- https://dev.mysql.com/downloads/repo/yum/ 进入这个mysql官网根据centos版本下载rpm文件
2.安装数据源
yum install yum install mysql80-community-release-el8-1.noarch.rpm
3.检查数据源
yum repolist enabled | grep "mysql.*-community.*"
4.禁用CentOS8自带的mysql模块
yum module disable mysql
5.安装mysql 一路y
yum install mysql-community-server
6.启动mysql
service mysqld start
service mysqld status
7.获取mysql安装后生成的随机密码
grep 'temporary password' /var/log/mysqld.log
8.登录
mysql -u root -p
随机密码
9.修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql_21root';
查看密码策略
SHOW VARIABLES LIKE 'validate_password%';
更改密码策略
set global validate_password.length=1;
set global validate_password.policy=0;
再次修改密码为自己想要的
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
10.开启远程访问权限
create user 'root'@'%' identified by 'root123';
grant all privileges on *.* to 'root'@'%' with grant option;
FLUSH PRIVILEGES;
11.更改mysql加密方式
由于mysql8.0加密方式变了,用navicat等工具连接数据库可能发生1045 密码错误的情况。所以要改变加密方式
ALTER USER'root'@'localhost' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER;
ALTER USER'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;
12.开启防火墙
退回到linux 终端
//开启3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
//重启防火墙
firewall-cmd --reload
//查看指定端口状态 显示 success 即端口成功开启
firewall-cmd --query-port=3306/tcp