perationalError: (2003, "Can't connect to MySQL server on u'192.168.1.6' (timed out)")

时间:2023-03-09 20:42:47
perationalError: (2003, "Can't connect to MySQL server on u'192.168.1.6' (timed out)")

在Ubuntu(192.168.1.20)中部署项目后,mysql还在另外一台windows(192.168.1.6)机子上,ping windows时可以ping通,但是访问项目提示:

perationalError: (2003, "Can't connect to MySQL server on u'192.168.1.6' (timed out)")

原来是mysql的默认端口3306没有开放,

chen@ubuntu:~$ telnet 192.168.1.6
Trying 192.168.1.6...
telnet: Unable to connect to remote host: Connection timed out

打开windows防火墙,入站规则添加3306端口。

perationalError: (2003, "Can't connect to MySQL server on u'192.168.1.6' (timed out)")

再次访问,又提示:

InternalError: (1130, u"Host '192.168.1.20' is not allowed to connect to this MySQL server")

怎么还是不能连接,原来是你的root帐号不允许从远程登陆,只能在
localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改”mysql” 数据库里的 “user” 表里的 “host”项,从”localhost”改为”%

进入windows的mysql安装的bin目录

mysql -u root -p
mysql->use mysql
mysql->update user set host = '%' where user ='root';
mysql->grant all privileges on *.* to 'root'@'%' with grant option;
mysql->flush privileges;
mysql->exit;

最后重启下mysql服务

perationalError: (2003, "Can't connect to MySQL server on u'192.168.1.6' (timed out)")

再次访问终于不报错了