Very often, we all need to access a remote database for debugging or any other related stuff.
The simplest thing that comes to mind is to take the dump of remote database and bring it to the local and run the application using that data.
We can avoid that, if we can connect our local mysql client to a remote machine over a SSH connection so that we can run queries on remote machine from our client machine, without dumping the database of remote machine.
To do that, we need to just need to remote machine over SSH with -L option
ssh -L 32001:127.0.0.1:3306 email@example.com
This means that we redirected call on port number 32001 to port number 3306 on the remote machine and all responses from the remote machine on 3306 will be redirected to 32001 on the local machine.
All we need to do now is to open mysql client and attach it to port number 32001 on local machine, we need to do
mysql -h 127.0.0.1 -P 32001 -u’username’ -p’password’
Here we are connecting to local machine on port number 32001, with username and password for that of the remote machine.