【问题标题】:Python scripts and MySQLPython 脚本和 MySQL
【发布时间】:2014-04-22 20:01:18
【问题描述】:

美好的一天!

我有一个令我烦恼的问题。我在我的 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)

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

【问题讨论】:

  • 请检查mysql配置。您是否启用了通过 give ip 访问数据库的权限?

标签: python mysql pymysql


【解决方案1】:

你必须给remote access to your mysql database

然后授予您的用户。

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多