MySQL 8开启root远程登录步骤详解

本文阅读时间10分钟。你会详细了解MySQL 8开启root远程登录的步骤。如果你没空,建议你看其他资料,乱枪打鸟地去试

MySQL 8与MySQL 5的登录方式有所不同。版本8允许auth socket,在linux本地登录不需要密码。

首先登录mysql

mysql -u root
use mysql

检查当前的用户登录限制

SELECT user,authentication_string,plugin,host FROM user;
+------------------+-------------------------+-----------------------+-----------+
| user             | authentication_string   | plugin                | host      |
+------------------+-------------------------+-----------------------+-----------+
| mysql.infoschema | $A$005$???????????????? | caching_sha2_password | localhost |
| mysql.session    | $A$005$???????????????? | caching_sha2_password | localhost |
| mysql.sys        | $A$005$???????????????? | caching_sha2_password | localhost |
| root             |                         | auth_socket           | localhost |
+------------------+-------------------------+-----------------------+-----------+
4 rows in set (0.00 sec)

发现root没有密码,验证方式是auth_socket,只能从localhost登录。

这里要背一下,必须先设置host,并且必须flush。

update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;

接着修改验证方式为密码。

alter user 'root'@'%' identified with mysql_native_password by '密码';

最后可以重新检查一下用户登录限制。

本文的步骤与《mysql8.0开启远程访问》完全相同,但加了注释。

发表评论

电子邮件地址不会被公开。

:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O 8)