修改 bind-address
# for ubuntu
vim /etc/mysql/my.cnf
[mysqld]
bind-address=0.0.0.0 # 或者指定的IP
更新 mysql root 权限
mysql -uroot -pPASSWD
use mysql;
update user set host = "%" where user="root" limit 1;
GRANT ALL PRIVILEGES ON *.* TO "root"@"%" WITH GRANT OPTION;
FLUSH PRIVILEGES;
> 此处 GRANT ALL PRIVILEGES ON . TO "root"@"%" IDENTIFIED BY "PASSWD" WITH GRANT OPTION;
> 在以往的版本中,往往是 GRANT ALL PRIVILEGES ON . TO "root"@"%" IDENTIFIED BY "PASSWD" WITH GRANT OPTION;
> 多加了 IDENTIFIED BY "PASSWD",在 5.7 以后便会报错,提示 Using GRANT statement to modify existing user properties other than privileges is deprecated and will be removed in future release. Use ALTER USER statement for this operation.
到这里,基本上就可以远程访问了
mysql -uroot -pPASSWD -h IP