1、修改认证加密方式
在mysql8.0下,默认变成了default_authentication_plugin=caching_sha2_password,包括你刚初始化的root用户也是这个认证加密方式,这样的结果是让你除非用新的协议驱动,例如必须用8.0自带的mysql客户端才行,不然就连接不上数据库.这样就必然造成不兼容的情况,幸好,是可以改回旧的方式的。
vim /etc/my.cnf
不过只对新创建的用户生效,就旧用户还是需要原来的认证加密方式。root:旧用户。test:新用户。
mysql> mysql> select Host,User,plugin,authentication_string from mysql.user;+-----------+------------------+-----------------------+------------------------------------------------------------------------+| Host | User | plugin | authentication_string |+-----------+------------------+-----------------------+------------------------------------------------------------------------+| % | root | caching_sha2_password | $A$005$=1=]jKmONVatruKBgSjEWdAQ8xKcxXkO8fLNwK52Vso1nXXUhSAd0 || % | test | mysql_native_password | *A413481286CFCE731AFEEB15D191A01D5C10478B || localhost | mysql.infoschema | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE || localhost | mysql.session | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE || localhost | mysql.sys | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |+-----------+------------------+-----------------------+------------------------------------------------------------------------+5 rows in set (0.00 sec)
2、授权
以前的授权方式就会报错
mysql> grant all privileges on *.* to 'root'@'%' identified by "iOuytErss8!";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 "iOuytErss8!"' at line 1mysql> flush privileges;
新授权方式,需要先创建用户和设置密码,然后才能授权。
#先创建一个用户create user 'test'@'%' identified by '123123';#再进行授权grant all privileges on *.* to 'test'@'%' with grant option;