远程登陆阿里云Myslq数据库:ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.xxx.xxx'

在ubuntu server中安装完mysql,在本地环境使用客户端无法正常登陆解决方法:

1.在阿里云控制台添加实例安全组策略:
在这里插入图片描述
2.修改默认绑定ip:将 bind-address = 127.0.0.1这一行注释掉

 vi /etc/mysql/mysql.conf.d/mysqld.cnf
 #bind-address = 127.0.0.1

3.进入mysql并授权给用户root:这里可以自由指定可以被访问的IP地址以及用户

root用户在任意主机远程登陆mysql:  
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY
 'xxxxxx' WITH GRANT OPTION;  
指定用户及ip进行远程登陆mysql:
 mysql>GRANT ALL PRIVILEGES ON *.* TO 'your user'@’your ip address’ 
 IDENTIFIED BY 'your password' WITH GRANT OPTION;
 刷新生效:
 mysql>FLUSH RIVILEGES

4.或者修改mysql数据库中的user表使相应的用户能从某一主机登陆

mysql -u root –p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;

重启Mysql在本地进行远程登陆:

  /etc/init.d/mysql restart

你可能感兴趣的:(数据库)