Python Forum
connect to remote database via python script - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: connect to remote database via python script (/thread-9679.html)



connect to remote database via python script - sunstar20 - Apr-23-2018

Hi,

I am able to connect to local database via python script.
For ex: MySQLdb.connect("localhost","testuser","test123","test" )

I want to connect to remote database via python script.

Could you please help.


RE: connect to remote database via python script - Gribouillis - Apr-23-2018

You can probably replace the "localhost" by the host's IP address such as "127.0.0.1"


RE: connect to remote database via python script - sunstar20 - Apr-23-2018

Getting the below error:

# python test.py
Error:
Traceback (most recent call last): File "test.py", line 6, in <module> db = MySQLdb.connect("1.2.3.4","testuser","test123","test" ) File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect return Connection(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 204, in __init__ super(Connection, self).__init__(*args, **kwargs2) _mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on '1.2.3.4' (110)")
Are there any other settings required for binding the remote ip of the remote database


RE: connect to remote database via python script - Gribouillis - Apr-23-2018

Is your server's IP address '1.2.3.4' ? Try to connect to the mysql server out of python (such as with the mysql command in a terminal).


RE: connect to remote database via python script - sunstar20 - Apr-23-2018

current system ip for example: x.y.z.k

I am trying to connect to the remote database of the remote server i.e 1.2.3.4

connecting to 1.2.3.4 from x.y.z.k



Error:
# mysql --host=1.2.3.4 --user=testuser --password=test123 TEST mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 2003 (HY000): Can't connect to MySQL server on '1.2.3.4' (111)



RE: connect to remote database via python script - Gribouillis - Apr-23-2018

Did you check the troubleshooting page?