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'")
Python needs a MySQL driver to access the MySQL database. In this tutorial we will use the driver "MySQL Connector". We recommend that you use PIP to install "MySQL Connector". PIP is most likely already installed in your Python environment.
To create a connection between the MySQL database and Python, the connect() method of mysql. connector module is used. We pass the database details like HostName, username, and the password in the method call, and then the method returns the connection object.
The MySQL server communicates only from the localhost by default. It can only be accessed by applications running on the same host. Remote access is necessary to remotely access the database from an application running on a different machine or host.
This is what I would do
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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With