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 |
+-----------+------------------+------------------------------------------------------------------------+
| % | 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 |
+-----------+------------------+------------------------------------------------------------------------+
| % | 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 |
+-----------+------------------+------------------------------------------------------------------------+
| % | 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)
完毕!