f_db我正在尝试使用python脚本连接到mysql数据库。我这样做的代码如下:
`db = MySQLdb.connect(host="xxx.xx.xx.xx", # your host, usually localhost
port = xxxx,
user="chrathan", # your username
passwd="...", # your password
db="f_db") # name of the data base`
我已经从mysql workbench打开了数据库。但是,我无法从python中打开它我收到以下错误:
_mysql_exceptions.OperationalError: (1044, "Access denied for user 'chrathan'@'%' to database 'f_db'"). Basically I am receiving `Traceback (most recent call last):
File "D:\_WORKSPACE\mysql\fashion_db.py", line 7, in <module>
db = 'f_db') mysql_exceptions.OperationalError: (1044, "Access denied for user 'chrathan'@'%' to database 'f_db'")`
答案 0 :(得分:4)
在mysql终端上输入此命令
$> mysql
GRANT ALL PRIVILEGES ON f_db.* TO 'chrathan'@'%' identified by 'secret'
在mysqlworkbench中将用户添加到数据库,请查看此页面How to Create a MySQL Database with MySQL Workbench
答案 1 :(得分:1)
也许您应该检查数据库名称是否相同,同样的问题出现在我身上,最后我发现mysqlclient数据库名称与我在python中使用的名称不同