1

I'm writing a small python program locally as i don't have root access on the server. It basically does a lot of mysql queries using python MySQLdb module.

The thing is I cant use MySQLdb with the server, as the mysql server is hosted locally and I need to ssh into the server and then use mysql from there.

Is there any module available where I can connect to a mysql database via SSH.

At the moment I can connect to the mysql instance using SSH credentials (IP, User, Pass)

I also have the user/pass for the mysql instance and I'm pretty sure it runs on 127.0.0.1/localhost.

user3413046
  • 109
  • 1
  • 13
  • 2
    Use an SSH tunnel (-L parameter)! It's out of scope for SO, so try man or google. Hint: Use an other port than 3306 for the client end or most MySQL clients will try to use the UNIX socket automatically. – Klaus D. Jul 14 '15 at 02:41

1 Answers1

1

If you're set on Python, I would use paramiko:

https://github.com/paramiko/paramiko

This seems to be one of the most widely used Python SSH libraries. There are some other StackOverflow questions that address how to do this.

The main idea is to create a tunnel with paramiko and then connect to the localhost port through which you are tunneling traffic to the remote server using the Python library MySQLdb.

Community
  • 1
  • 1