远程连接数据库时出现Can't connect to Mysql on '主机名'(10061)解决方法

情况一:

授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。 
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; 
如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码 
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 
'mypassword' WITH GRANT OPTION; 

1.mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.199' IDENTIFIED BY 'root' WITH GRANT OPTION;  

2.mysql>flush privileges;

 


 

情况二:

需要修改mysql配置文件

步骤:

(1)cd /etc/mysql

(2)vim my.cnf

(3)将bind-address  = 127.0.0.1修改为bind-address = 0.0.0.0

(4)保存退出

(5)/etc/init.d/mysql restart  (一定要重启数据库,不然没用)

 

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