1

再会!

我有一个令我烦恼的问题。我在我的 PC 上设置了 Apache 服务器/MySQL/PhpMyAdmin。我想在 python3 上写一些脚本来处理数据库。我在本地主机上设置了我的数据库。但是现在本地网络有另一台计算机。

我希望我的朋友可以通过我的 ip 访问数据库。喜欢(http://192.168.xx.xx/pma)。现在它可以工作了!

我的朋友也喜欢蟒蛇。还有一个问题:当他运行脚本时,python 等待 30 秒并且:

"Can't connect to MySQL server on %r (%s)" % (self.host, e))
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '192.168.
xx.xx' ([WinError 10060] A connection attempt failed because the connected part
y did not properly respond after a period of time, or established connection fai
led because connected host has failed to respond)") 

有和平的代码连接:

import pymysql   
con = pymysql.connect(host='192.168.xx.xx', user='root', passwd='xxx', db='test')
cur = con.cursor()
print(con)

帮助我的朋友使用我的数据库!谢谢!

4

1 回答 1

0

您必须授予对数据库的远程访问权限mysql

然后授予您的用户。

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
于 2014-03-17T14:50:41.623 回答