23

I have tried the following script but unfortunately doesn't work. I am using a free MySQL database provider. Any ideas?

import MySQLdb

myDB = MySQLdb.connect(host="208.11.220.249",port=3306,user="XXXXX",passwd="XXXXX",db="XXXXX")
cHandler = myDB.cursor()
cHandler.execute("SHOW DATABASES")
results = cHandler.fetchall()
for items in results:
    print items[0]

Currently, I am getting the following error:

super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1044, "Access denied for user 'XXXXX'@'%' to database 'XXXXX'")
3
  • 2
    what does not work? you get an error or just nothing is output Commented Oct 19, 2012 at 11:04
  • 1
    Did you test to connect using the mysql command line client? Commented Oct 19, 2012 at 11:10
  • Can you connect to the same database at the same host with these credentials in some other way? like from the command line or a GUI tool? Commented Oct 19, 2012 at 11:17

4 Answers 4

13
 GRANT ALL
 ON  *.*
 TO [email protected]  -- client ip address
 IDENTIFIED BY 'pwd';

Edit

This is SQL that you'd run on the database in order to ensure that the user has access to everything. pwd is the user's password.

Basically, this answer assumes that the connection issue is a credentials issue.

Sign up to request clarification or add additional context in comments.

3 Comments

I don't get it. Could you please explain it further?
What is this excatly?
is there a way to run this command through python. I tried the cursor object, but it also giving the access denied error.
6

This is what I would do

  1. See if the port is actually open on that machine.
  2. On the machine you are connecting from, open console/cmd/terminal and see if you can connect using mysql -u XXXX -h 208.11.220.249 -p. If your mysql client can not connect, then there is no way you can connect using python

Comments

1

You don't have permission for connecting to database with this user. Follow these steps:

1.try connecting to mysql DB: mysql -h208.11.220.249 -uXXXXX -pXXXXX XXXXX

2.If you don't have permission for connecting to DB ,try creating user that has remote permission

GRANT ALL ON DB.* -- Database name TO user@ip -- client ip address IDENTIFIED BY 'pwd';

3.on the last check my.cnf . "bind-address" must be 0.0.0.0 If you want to connect all remote addresses.

2 Comments

The first step was successful, but I lost it from step 2 onwards... could you please explain it in more detail???
IF you have connection to special DB ,You could access to this DB.Run the other command for example cHandler.execute("SHOW TABLES").IF this command works,you don't have permission for seeing all databases.
0

open your database in mysql and type the following :

mysql> GRANT ALL ON *.* TO root@'x' IDENTIFIED BY 'Your-password'

where x is the ip address of the user that wants to access your db.

use this link for more information: How to Allow MySQL Client to Connect to Remote MySQL server

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.