MySQL远程訪问的命令 格式: mysql -h主机地址 -uusername -p用户password
首先在目标服务器上(115.159.66.51)改动mysql的my.cnf文件:
改动退出后,重新启动mysql服务 命令:sudo service mysql restart
此时尝试用115.159.66.51主机来连接mysql
ubuntu@VM-194-212-ubuntu:/etc/mysql$ mysql -h115.159.66.51 -uroot -pxiongchao
此时会出现无法连接的错误
原因:没有对远程主机115.159.66.51赋予訪问mysql server的权限
赋予主机主机115.159.66.51以root的身份訪问数据权限(注:訪问haibao数据库):
grant all privileges on haibao.* to ‘root’@’115.159.66.51’ identified by ‘xiongchao’ with grant option;
赋予不论什么主机以root的身份訪问数据权限(注:訪问haibao数据库):
grant all privileges on haibao.* to ‘root’@’%’ identified by ‘xiongchao’ with grant option;
改动生效:
flush privileges;