Python Forum
connect to remote database via python script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
connect to remote database via python script
#1
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.
Reply
#2
You can probably replace the "localhost" by the host's IP address such as "127.0.0.1"
Reply
#3
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
Reply
#4
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).
Reply
#5
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)
Reply
#6
Did you check the troubleshooting page?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Running script from remote to server invisiblemind 4 614 Mar-28-2025, 07:57 AM
Last Post: buran
  [SOLVED] Using Python to connect to an XML ? jehoshua 21 7,540 Dec-02-2024, 02:35 PM
Last Post: snippsat
  Python script to extract data from API to database melpys 0 823 Aug-12-2024, 05:53 PM
Last Post: melpys
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 1,025 Jan-26-2024, 07:02 PM
Last Post: deanhystad
  python script is hanging while calling a procedure in database prasanthi417 4 2,005 Jan-17-2024, 02:33 PM
Last Post: deanhystad
  connect sql by python using txt. file dawid294 2 2,062 Jan-12-2024, 08:54 PM
Last Post: deanhystad
  How to Connect to PostgreSQL Through Jump Server and SSH Tunnel using Python? nishans 1 3,841 Jan-02-2024, 10:37 AM
Last Post: khanzain
  python connect to mssql wailoonho 7 5,484 Dec-07-2023, 02:06 AM
Last Post: wailoonho
  i tried to install python for the first time today and pretty certain im being remote brianlj 2 1,583 Oct-03-2023, 11:15 AM
Last Post: snippsat
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 7,904 Jun-29-2023, 11:57 AM
Last Post: gologica

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020