1.授权

运行如下命令即可授权root可远程登录

grant all privileges on *.* to 'root'@'%' identified by 'test123456' with grant option;
flush privileges;

显示如下即表示授权成功。

mysql> select user,host,authentication_string from user;
+---------------+-----------+-------------------------------------------+
| user          | host      | authentication_string                     |
+---------------+-----------+-------------------------------------------+
| root          | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys     | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| root          | %         | *CB65AD34901F9DFD659526F9579AD79F557E66D5 |
+---------------+-----------+-------------------------------------------+
4 rows in set (0.00 sec)

成功后即可用 'root' 远程以密码 'test123456'连接mysql数据。

连接命令:[scode type="blue"] mysql --host 118.25.11.111 -uroot -p [/scode]

2.注意事项

2.1 比如你运行最上面的命令时碰到如下错误时,表示开启强密码校验,密码太简单了不行。

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

2.2 如果你使用的是腾讯云或者阿里云之类的,那你还要设置安全组,打开3306端口允许任意人或指定IP访问。
1x.jpg

2.3 关闭iptable防火墙,或者打开3306端口

service   iptables stop