Linux / 数据库 · 2012-05-04

为mysql添加root远程登录权限

默认情况下,MySQL允许本地登录,需要修改/etc/mysql/my.cnf文件:
注释这一行:
bind-address=127.0.0.1 ==> #bind-address=127.0.0.1
8.0还需加配置:default-authentication-plugin=mysql_native_password

对于需要远程登录的用户执行如下命令:
mysql> GRANT ALL PRIVILEGES ON *.* TO root@”%” IDENTIFIED BY “yourpasswd” WITH GRANT OPTION;
mysql> flush privileges;

mysql> use mysql;
mysql> update user set host = ‘%’ where user = ‘root’;
mysql> select host, user from user;
mysql> flush privileges;

8.0版本更新:

alter user ‘root’@’%’ identified with mysql_native_password by ‘123456’;