Scenario: Usually directly log on to the MySQL server with root for SQL statement query, when you want to connect MySQL with Python, prompt 1045, "Access denied for user ' root ' @ ' IP address ' (using Password:yes ) ", and then use the Create user name identified by ' password ' creates a user name name of the user, then to execute Python, prompting 1004 Access denied for user ' username ' @ '% ' to database, this time To go to MySQL with select * from Mysql.user \g to view all current users, you will find that many of the other people's permissions are Y, and their own are N, so realize that it is a permissions issue.
FIX: Add permissions to your username grant all privileges on the *. * to User name @ip address, and then select * from Mysql.user \g will find that its permissions have also become Y, when Python can connect to the database.
#!/usr/bin/env python
#-*-Coding:utf-8-*-
Import MySQLdb
conn = MySQLdb.connect (host = "IP Address", user = "username", passwd = "Password",
db = "database name", port = 3306, charset= "UTF8")
cur = conn.cursor ()
Cur.execute ("Set NAMES UTF8")
if __name__ = = ' __main__ ':
Conn.commit ()
Cur.close ()
Conn.close ()
MySQL Licensing issue: 1004 Access denied for user ' username ' @ '% ' to database