1. 卸载mariadb
因centos7默认安装了mariadb, 会造成依赖冲突,按下列方式进行卸载:
rpm -qa | grep mariadb
#如果出现
mariadb-libs-5.5.68-1.el7.x86_64
#执行
rpm -e mariadb-libs --nodeps
2. 下载 注意权限:(chmod -R 777 /var/lib/mysql)(chmod -R 777 /var/lib/mysql)
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar
#下载完后创建目标文件夹,将其解压
cd /opt
tar -xvf mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar -C /opt/mysql
#然后会出现以下几个安装包
mysql-community-client-8.0.31-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm
mysql-community-common-8.0.31-1.el7.x86_64.rpm
mysql-community-debuginfo-8.0.31-1.el7.x86_64.rpm
mysql-community-devel-8.0.31-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.31-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm
mysql-community-libs-8.0.31-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.31-1.el7.x86_64.rpm
mysql-community-server-8.0.31-1.el7.x86_64.rpm
mysql-community-server-debug-8.0.31-1.el7.x86_64.rpm
mysql-community-test-8.0.31-1.el7.x86_64.rpm
3. 安装
yum install -y perl.x86_64
rpm -ivh mysql-community-common-8.0.26-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-libs-8.0.26-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-client-8.0.26-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-server-8.0.26-1.el7.x86_64.rpm --force --nodeps
4. 启动
#启动
systemctl start mysqld
#查看启动状态
systemctl status mysqld
6. 修改密码
#查看初始密码
grep 'temporary password' /var/log/mysqld.log
#登录、使用刚才的获得的密码
mysql -uroot -p
#MySQL 8.0 调整密码验证规则(否则设置简单密码不成功):
set global validate_password.policy=0;
set global validate_password.length=1;
#修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
7. 设置mysql远程链接
#登录MySQL 运行以下指令
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
FLUSH PRIVILEGES;
然后最好重启一次mysql
8. 最后
用软件登陆的Mysql8数据库时,会报错:Authentication plugin 'caching_sha2_password' cannot be loaded。 出现这个原因是mysql8 之前的版本中加密规则是mysql_native_password,而在mysql8之 后,加密规则是caching_sha2_password。
解决问题方法有两种,一种是升级navicat驱动, 另一种是把mysql用户登录密码加密规则还原成mysql_native_password。此处采用第二种,修改加密规则:
1、登录Mysql:
mysql -u root -p
2、修改账户密码加密规则并更新用户密码:
//修改加密规则(可以直接复制)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
//更新一下用户的密码(可以直接复制)
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
3、刷新权限并重置密码
//刷新权限(可以直接复制)
FLUSH PRIVILEGES;
4、重置密码
//此处请自定义密码,红色的root就是博主自定义的密码
alter user 'root'@'localhost' identified by 'root';
此处将密码改为root
重新打开软件,再次连接数据库即可