mysql默认安装的root用户是没有远程登录权限的:
mysql -u root -p
mysql> use mysql;
mysql> SELECT host, user FROM user WHERE user = 'root';
+-----------+------+
| host | user |
+-----------+------+
| localhost | root |
+-----------+------+
只能够从机器上登录
使用:
<password>
部分替换为需要使用的密码
CREATE USER 'root'@'%' IDENTIFIED BY '<password>'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
即可
mysql> use mysql;
mysql> SELECT host, user FROM user WHERE user = 'root';
+-----------+------+
| host | user |
+-----------+------+
| % | root |
| localhost | root |
+-----------+------+
测试:
冶心·练体·得技