MySQL Licensing issue: 1004 Access denied for user ' username ' @ '% ' to database

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.