当我运行我的脚本时,它将无法连接到mysql数据库,我无法从godaddy找到我的主机名,我只是尝试了mysq.mydomain.com和mydomain.com。数据库的登录详细信息是正确的。
Traceback (most recent call last):
File "mysql.py", line 6, in <module>
conn = MySQLdb.connect(host="?",user="?",passwd="?",db="?")
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'official_autotes'@'104.156.228.189' (using password: YES)")
------------------
我的代码
from threading import Thread
import urllib
import re
import MySQLdb
conn = MySQLdb.connect(host="?",user="?",passwd="?",db="?")
query = "INSERT INTO tutorial (symbol) values ('AAPL')"
x = conn.cursor()
x.execute(query)
row = x.fetchal()
答案 0 :(得分:1)
对用户和ip尝试使用Python代码访问MySQL表的高级权限。要做到这一点,请在mysql shell中执行以下命令。
GRANT <privileges> ON database.* TO 'user'@'ip' IDENTIFIED BY 'password';
flush privileges;