1.添加MySQL Yum存储库
-
a.下载Yum存储库,下载地址(https://dev.mysql.com/downloads/repo/yum/)
-
b.选择并下载适合您平台的发布包
或者在服务器上执行命令下载:
wget https://repo.mysql.com//mysql84-community-release-el7-1.noarch.rpm
-
c .安装下载的发布包
sudo yum install mysql84-community-release-el7-1.noarch.rpm
2.选择版本
查询可以安装的版本:
yum repolist all | grep mysql
使用yum-config-manager工具禁用8.4,启用8.0
#禁用8.4
sudo yum-config-manager --enable mysql-tools-community
sudo yum-config-manager --disable mysql-tools-8.4-lts-community
#启用8.0
sudo yum-config-manager --enable mysql80-community
sudo yum-config-manager --enable mysql-tools-community
3.禁用默认的MySQL模块(centos8)
sudo yum module disable mysql
4.安装
sudo yum install mysql-community-server
5.启动mysql
systemctl start mysqld
查看mysql状态
systemctl status mysqld
设置开机启动:
sudo systemctl enable --now mysqld.service
5.修改root默认密码
查询root默认密码
sudo grep 'temporary password' /var/log/mysqld.log
登录mysql
mysql -uroot -p
修改默认密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
设置任意ip链接mysql:
use mysql;
select user,host from user;
update user set host='%' where user='root';
FLUSH PRIVILEGES;