I have written a python script that uses the MySQL Connector for Python to read, write and update the database. Do I need to install MySQL server on the client machine (Windows) too to run the program or do I just need to make sure that the database is present in the path used by the script? I tried finding guidance on Google and here but couldn't find what I needed.
No you don't need to install MySQL Server on a client machine. By definition client machine means you don't have the DB/Server there. Where is this DB allocated? You show have an IP or a domain/subdomain address where the DB is actually hosted.
I created a connection to a remote, tunneled MySQL server over the PyCharm GUI in the "Database" menu.
I'm trying to use this connection in the code itself, without connecting manually again to the SQL server and tunelling over SSH in the code.
Is this possible? I couldn't find anything relevant on the internet yet.
Thanks!
I'm trying to write a python script using cx_oracle module for perform oracle database connection. But during the execution, I found it needs oracle instant client to establish a connection. Currently, I'm developing the script in ubuntu but there is a chance to run the same in windows. So I'm confused about the implementation. Could someone please suggest the best way to connect oracle database irrespective the platform
You will always need an OS-specific library or client of some kind. Either the Oracle Instant Client or a Java JDK/JDBC library or both. If you want OS-independence then you would need to interact with the DB through REST calls or something like that instead of making a persistent connection. Otherwise you have to interact with the OS networking stack at some point, which requires OS-specific libraries.
I have question how can I connect to VPS server and interact with MySQL database using python on my local machine.
I would like to make program using PyQT that connect to my server and update, take sth from db.
I know that there is MySQLdb module but from what I know i cannot connect to VPS server, because in connect method it doesn't take server password argument.
I am trying to connect to a MySQL database on someone else's "machine". When I use Navicat for MySQL, I have no problem connecting to it. I am trying to do the same with Python so that I do not have to use the GUI interface. I know all my info below is correct (even though I swap fake info) -- can anyone spot where I went wrong? The error I get is OperationalError: (2005, "Unknown MySQL server host 'FTP_hostname' (0)")
My code (using paramiko for the SSH):
import MySQLdb
import paramiko
import time
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('SSH_hostname', 22, username='me', password='pswrd')
time.sleep(1)
db = MySQLdb.connect(host="FTP_hostname",
user="root",
passwd="pswrd2",
db="MyDB")
cur = db.cursor()
Again, I put all this into Navicat and connect no problem. Hoping you can help! Thanks!
MySQL, like most databases, by default runs locally and disallows access from outside networks. As such, you cannot connect to it from an external computer.
Navicat, being a software explicitely for remote administration of databases, likely connects via SSH and tunnels the MySQL connection over it. That way it can act as if the database was installed locally, and for the database it looks as if it was accessed locally.
You could try to do the same by creating a tunnel using Paramiko; see also this question.
If you still in need of connecting to a remote MySQL db via SSH I have used a library named sshtunnel, that wraps ands simplifies the use of paramiko (a dependency of the sshtunnel).
You can check my answer in another similar question with some sample code to use it.
db = MySQLdb.connect(host="FTP_hostname",
Would the host not need to be 127.0.0.1 (localhost) as the tunnel is making the MySQL DB local to the machine that the python script is running on?