HLH
HLH

Reputation: 1167

On Django, how to connect to MySQL database on remote server through SSH?

I've looked around, and can't find any answers that specifically address what I'm wondering:

In the Mac terminal, I can access a remote server through ssh:

ssh [my_username]@[server.host.com]

which prompts me for a password, and after I enter my password, it brings me to the remote server.

Once I've logged into the remote server, I can access MySQL:

mysql -u [other_username] -h [mysql.host.com] -p

which prompts me for another password, and after entering the password, I'm in the MySQL console and can show databases located there, etc. We can call the database I'm interested in [database].

My question is, how do I hook up Django, run on my localhost, to [database], so that my app uses that [database]?

Upvotes: 3

Views: 6209

Answers (1)

turbotux
turbotux

Reputation: 412

You can create an ssh tunnel to map the remote server mysql port to a local port on your machine.

ssh -L 3333:127.0.0.1:<remote mysql port> <username>@<remote host> -N

Whiles this process is active the local port 3333 will connect to the remote port on the remote host.

Upvotes: 8

Related Questions