python mysql 1045 OperationalError: 1045, "Access denied for user root@'localhost'

Python代码:

# ^_^ coding: utf-8 ^_^

import MySQLdb

#打开数据库连接
db = MySQLdb.connect("localhost","root","zhang123","stucou")
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()

print "Database version: %s" %data

db.close()


报错 1045 OperationalError: 1045, "Access denied for user root@'localhost'


cmd进入mysql,执行

GRANT all privileges on stucou.* to 'root'@'localhost' IDENTIFIED BY 'zhang123' WITH GRANT OPTION;

然后执行,

SHOW GRANTS FOR 'root'@'localhost';
 
  
成功输出结果。

你可能感兴趣的:(数据库,python)