码迷,mamicode.com
首页 > 数据库 > 详细

centos7安装mysql8.0

时间:2019-03-08 11:23:05      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:更改root密码   安装库   plugin   报错   大写   sha   默认   日志   不能   

MySQL 8 正式版 8.0.11 已发布,官方表示 MySQL 8 要比 MySQL 5.7 快 2 倍,还带来了大量的改进和更快的性能!

mysql8.0安装步骤:

1、添加yum安装库

安装库的下载地址:https://repo.mysql.com//mysql80-community-release-el7-2.noarch.rpm

wget https://repo.mysql.com//mysql80-community-release-el7-2.noarch.rpm

rpm -Uvh mysql80-community-release-el7-2.noarch.rpm

2、安装mysql

yum install mysql-community-server

3、MySQL服务器初始化(从MySQL 5.7开始):在服务器初始启动时,如果服务器的数据目录为空,则会发生以下情况:

  • 服务器已初始化。

  • 在数据目录中生成SSL证书和密钥文件。

  • validate_password插件安装并启用。

  • ‘root‘@‘localhost‘ 创建一个超级用户帐户设置超级用户的密码并将其存储在错误日志文件中。要显示它,请使用以下命令:

    shell> sudo grep ‘temporary password‘ /var/log/mysqld.log

    通过使用生成的临时密码登录并为超级用户帐户设置自定义密码,尽快更改root密码:

    shell> mysql -uroot -p
    mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘MyNewPass4!‘;
4、注意密码的强度

MySQL的 validate_password 插件默认安装。这将要求密码包含至少一个大写字母,一个小写字母,一个数字和一个特殊字符,并且密码总长度至少为8个字符。

这个其实与validate_password_policy的值有关, mysql8.0更改了validate_password_policy相关的配置名称, 这跟Mysql5.7有点不一样了.
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
   
mysql> set global validate_password.length=1;
Query OK, 0 rows affected (0.00 sec)
   
接着再修改密码
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘123456‘;
Query OK, 0 rows affected (0.05 sec)
   
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
 
 
5.  Mysql8.0要注意的点
 
1)  创建用户和授权
在mysql8.0创建用户和授权和之前不太一样了,mysql8.0需要先创建用户和设置密码,然后才能授权。
 
mysql> create user ‘kevin‘@‘%‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.04 sec)
 
mysql> grant all privileges on *.* to ‘kevin‘@‘%‘ with grant option;   
Query OK, 0 rows affected (0.04 sec)
 
mysql> create user ‘bobo‘@‘%‘ identified by ‘123456‘;    
Query OK, 0 rows affected (0.06 sec)
 
mysql> grant all privileges on *.* to ‘kevin‘@‘%‘;
Query OK, 0 rows affected (0.03 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)
 
mysql> select host,user,authentication_string from mysql.user;
+-----------+------------------+------------------------------------------------------------------------+
| host      | user             | authentication_string                                                  |
+-----------+------------------+------------------------------------------------------------------------+
| %         | bobo             | $A$005$1VY")q?G6<^X@-6LsXrPt5C0TwlTuvHbaOa3sYF0DKViIGoRPuCF8AzwiFcim1  |
| %         | kevin            | $A$005$hy`U}ZB#R::rA8W0y2rmwgySqzv0rmR1eTeNDSaXfQPWIsrh7ytbVdi85       |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | $A$005$/VO_y^7,]6;2qxggBLmJzhA0Qylu5/AHuRScZ/ykKedgZKh/6krOIzPs2       |
+-----------+------------------+------------------------------------------------------------------------+
如果还是用Mysql5.7及之前版本的直接授权的方法, 会有报错:
 
mysql> grant all privileges on *.* to ‘shibo‘@‘%‘ identified by ‘123456‘;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘identified by ‘123456‘‘ at line 1
2)  Mysql8.0默认是不能使用root账号进行远程登录的! root账号只能本地登录!
 
mysql> select host,user,authentication_string from mysql.user;
+-----------+------------------+------------------------------------------------------------------------+
| host      | user             | authentication_string                                                  |
+-----------+------------------+------------------------------------------------------------------------+
| %         | bobo             | $A$005$1VY")q?G6<^X@-6LsXrPt5C0TwlTuvHbaOa3sYF0DKViIGoRPuCF8AzwiFcim1 |
| %         | kevin            | $A$005$hy`U}ZB#R::rA8W0y2rmwgySqzv0rmR1eTeNDSaXfQPWIsrh7ytbVdi85 |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | $A$005$/VO_y^7,]6;2qxggBLmJzhA0Qylu5/AHuRScZ/ykKedgZKh/6krOIzPs2 |
+-----------+------------------+------------------------------------------------------------------------+
6 rows in set (0.00 sec)
 
如果想要远程登录, 则需要进行update更新下root账号的权限
mysql> update mysql.user set host=‘%‘ where user="root";
Query OK, 1 row affected (0.10 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
mysql> flush privileges;
Query OK, 0 rows affected (0.14 sec)
 
mysql> select host,user,authentication_string from mysql.user;
+-----------+------------------+------------------------------------------------------------------------+
| host      | user             | authentication_string                                                  |
+-----------+------------------+------------------------------------------------------------------------+
| %         | bobo             | $A$005$1VY")q?G6<^X@-6LsXrPt5C0TwlTuvHbaOa3sYF0DKViIGoRPuCF8AzwiFcim1  |
| %         | kevin            | $A$005$hy`U}ZB#R::rA8W0y2rmwgySqzv0rmR1eTeNDSaXfQPWIsrh7ytbVdi85       |
| %         | root             | $A$005$/VO_y^7,]6;2qxggBLmJzhA0Qylu5/AHuRScZ/ykKedgZKh/6krOIzPs2       |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
+-----------+------------------+------------------------------------------------------------------------+
6 rows in set (0.00 sec)
这样就能在远程使用root账号登录该mysql8.0的数据库了
3) 修改root账号权限, 允许root账号远程登录后, 在其他主机进行mysql的远程连接时,出现了弹窗报错: 
ERROR 2059 (HY000): Authentication plugin ‘caching_sha2_password‘ cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
出现这个原因是mysql8 之前的版本中加密规则是mysql_native_password, 而在mysql8之后,加密规则是caching_sha2_password, 解决问题方法有两种:
1) 一种是升级navicat驱动;
2) 一种是把mysql用户登录密码加密规则还原成mysql_native_password;
 
这里选择第二种方法来解决:
 
#修改加密规则
mysql> ALTER USER ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ PASSWORD EXPIRE NEVER;       
Query OK, 0 rows affected (0.16 sec)
 
#更新一下用户的密码
mysql> ALTER USER ‘root‘@‘%‘ IDENTIFIED WITH mysql_native_password BY ‘123456‘;
Query OK, 0 rows affected (0.08 sec)
 
#刷新权限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)
完毕!

centos7安装mysql8.0

标签:更改root密码   安装库   plugin   报错   大写   sha   默认   日志   不能   

原文地址:https://www.cnblogs.com/yshc/p/10494480.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!