sudo vi /etc/mysql/my.cnf
找到bind-address = 127.0.0.1
注释掉这行:#bind-address = 127.0.0.1
或者改为: bind-address = 0.0.0.0 (允许任意IP访问)
或者自己指定一个IP地址。
mysql -h localhost -uroot -p
Grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
flush privileges;
sudo /etc/init.d/mysql restart