CentOS7使用yum安装配置MySQL8

卸载MariaDB

列出所有被安装的rpm package

# rpm -qa | grep mariadb
mariadb-libs-5.5.50-1.el7_2.x86_64
mariadb-5.5.50-1.el7_2.x86_64
mariadb-server-5.5.50-1.el7_2.x86_64

强制卸载

rpm -e mariadb-libs-5.5.50-1.el7_2.x86_64

此时报错:

error: Failed dependencies:
    libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
    libmysqlclient.so.18()(64bit) is needed by (installed) perl-DBD-MySQL-4.023-5.el7.x86_64
    libmysqlclient.so.18()(64bit) is needed by (installed) php-mysql-5.4.16-36.3.el7_2.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) perl-DBD-MySQL-4.023-5.el7.x86_64
    libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) php-mysql-5.4.16-36.3.el7_2.x86_64
    mariadb-libs(x86-64) = 1:5.5.50-1.el7_2 is needed by (installed) mariadb-1:5.5.50-1.el7_2.x86_64
    mariadb-libs(x86-64) = 1:5.5.50-1.el7_2 is needed by (installed) mariadb-server-1:5.5.50-1.el7_2.x86_64

强制卸载,因为没有–nodeps

# rpm -e --nodeps mariadb-libs-5.5.50-1.el7_2.x86_64

# rpm -e --nodeps mariadb-5.5.50-1.el7_2.x86_64

# rpm -e --nodeps mariadb-server-5.5.50-1.el7_2.x86_64 

安装MySQL

下载MySQL源(后缀是noarch.rpm)

[root@centos ~]# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

安装mysql源

[root@centos ~]# yum localinstall mysql80-community-release-el7-1.noarch.rpm

检查mysql源是否安装成功

[root@centos ~]# yum repolist enabled | grep "mysql.*-community.*"

出现如下所示表示安装成功:

mysql-connectors-community/x86_64 MySQL Connectors Community                  65
mysql-tools-community/x86_64      MySQL Tools Community                       69
mysql80-community/x86_64          MySQL 8.0 Community Server                  33

安装MySQL

[root@centos ~]# yum install mysql-community-server

出现Error downloading packages:错误,重复执行上述命令。

启动MySQL服务

[root@centos ~]# systemctl start mysqld

查看MySQL的启动状态

[root@centos ~]# systemctl status mysqld

找出root默认密码

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改。

[root@centos ~]# grep 'temporary password' /var/log/mysqld.log
2018-05-13T02:02:14.879263Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: &/hQlEZXc1gT

使用数据库root用户登录

[root@centos ~]# mysql -u root -p
Enter password: &/hQlEZXc1gT

修改默认密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mysql&123456789';
mysql> flush privileges;

修改默认密码和加密方式

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '%KMzSp43m5XKC@eP';
flush privileges;

注意:mysql5.7以上默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000)错误,如下图所示:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456789';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

远程连接授权

mysql> use mysql;
mysql> select user,host from user;
mysql> update user set host = '%' where user = 'root';

重启MySQL

[root@centos ~]# systemctl restart mysqld;

Mysql 安装完客户端连接报错:“Authentication plugin ‘caching_sha2_password’ cannot be loaded: ”

意思是客户端不支持caching_sha2_password的加密方式。

这样是不是就可以了呢? 其实并不会,还有一个坑

执行命令

use mysql;
select user,plugin from user ;

可以看到root用户的加密方式为caching_sha2_password

这样的话有两种办法可以解决问题:

一、升级客户端支持caching_sha2_password方式,没有采用。

我使用第二种方法:

二、修改密码加密方式,改成mysql_native_password

# 注意这里’%’是因为我们刚刚把user表中的localhost换成了%

ALTERUSER'root'@'%'IDENTIFIED BY'password'PASSWORD EXPIRE NEVER;

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

FLUSH PRIVILEGES;

 

# 查看一下现在的user表

select host, user, authentication_string, plugin from user;

可以看到plugin那我们已经换过来了

现在就可以正常的使用小海豚或者navicat Premium登录了

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Captcha Code