mac下python连接mysql数据库遇到的问题及解决

问题描述:

连接数据库语句:

try:
    conn=MySQLdb.connect(host='localhost',user='root',passwd='jiangxm',db='proxy',port=3306,charset="utf8")
    cur=conn.cursor()
    # conn.select_db('proxy')
    cur.execute("insert ignore into activity values(%s,%s,%s,%s)",value)
    conn.commit()
    cur.close()
    conn.close()
except MySQLdb.Error,e:
    print "Mysql Error %d: %s" % (e.args[0], e.args[1])
 遇到问题:[python] Mysql Error 1045: Access denied for user 'root'@'localhost' (using password: YES) 
  

解决方案: http://stackoverflow.com/questions/22267114/python-mysqldb-error-1045-access-denied-for-user

终端下进入mysql 

$ mysql -u root-p
Enter password: jiangxm

mysql> create database TESTDB;
mysql> grant usage on *.* to root@localhost identified by jiangxm’;
mysql> grant all privileges on TESTDB.* to root@localhost ;
mysql> exit
GRANT all privileges on TESTDB.* to 'root'@'localhost' IDENTIFIED BY 'jiangxm' WITH GRANT OPTION;
HOW GRANTS FOR 'root'@'localhost';


你可能感兴趣的:(mac上的安装配置)