安装步骤如下:
1.卸载
yum remove -y mysql
find / -name mysql //找到残留的文件,再通过rm -rf去删除对应的文件
2.下载
wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
yum install mysql80-community-release-el8-1.noarch.rpm
3.检查数据源
查看mysql源是否安装成功:
yum repolist enabled | grep "mysql.*-community.*"
4.禁用CentOS8自带mysql模块
yum module disable mysql // 禁用命令
5.安装mysql命令
yum install mysql-community-server --nogpgcheck
Is this ok [y/Y] 一直 y到底
6.启动mysql
在启动mysql时,遇到了一个问题:
[root@iZuf6hx48jsavuzwp5hv7jZ soft]# service mysqld start //启动命令
遇到问题
正确启动命令:
[root@iZuf6hx48jsavuzwp5hv7jZ soft]# /bin/systemctl start mysqld.service//启动命令
[root@iZuf6hx48jsavuzwp5hv7jZ soft]# service mysqld status //
7.显示mysql的随机密码
grep 'temporary password' /var/log/mysqld.log
密码是host:后面的一串字符。
8.登录并修改mysql密码
mysql -u root -p //输入上面生成的密码
修改密码需要注意,这里密码先修改成 “Root_21root”
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root_21root'; //因为我们随便修改密码时,一般都不满足它的策略
会报以下错误:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
解决办法:
一定要先修改默认密码为: Root_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';
修改前策略:
修改后策略:
9.Mysql8.0.22开放远程访问
create user 'root'@'%' identified by 'root123'; //1、先创建权限记录
grant all privileges on *.* to 'root'@'%' with grant option; //2、授权
开放防火墙端口
直接在安全组开放mysql端口号
解决2059 - Authentication plugin ‘caching_sha2_password’ cannot be loaded:
从错误信息可知caching_sha2_password不能加载。
以上报错是由于目前已有的客户端连接软件还不支持Mysql8新增加的加密方式caching_sha2_password,所以我们需要修改用户的加密方式,将其改为老的加密验证方式。可以看到当前用户的加密方式为caching_sha2_password。执行以下命令:
use mysql;
select user,plugin from user where user='root';
alter user 'root'@'%' identified with mysql_native_password by 'Admin@123';//将用户的加密方式改为mysql_native_password。
flush privileges;//这个一定要执行,执行命令使权限配置项立即生效。
再次尝试连接Mysql,连接成功。
示意图:
转载:https://blog.csdn.net/qq_39150374/article/details/112471108