phpmyadmin and remote databases

So you are using mysql as a database and want to control and work with it. Same here. We have all our own system mostly running on Linux and a lot of applications are using the mysql database. I also have a lot of customer using mysql so I need to be able to use it and work a lot with mysql.

You can ofcouse use the command line for a lot of things and many times I do use that. But some times a graphical tool is god to use, especially when you are converting old applications and need to jump between tables and getting an overview of a system.

When I was using my old machine under windows there was a program called EMS SQL Manager (comercial) so you had to by it but it was very good. So i was looking for a simmelar program under linux and came across phpmyadmin ofcouse.

This is a webapplications written in PHP and you can install it on a server or on your own system. I would prefer to have it running on my local server / laptop and access databases remote as I don’t want to install web and software in all serves im working on. So I started with installing phpmyadmin on my laptop. There is an package that is called phpmyadmin os its just to install that with:

I can then go to locahost/phpmyadmin and login and work on the local databases.

Access other servers

Thats all god and fine but now i want to access other servers. There is 2 different ways of doing this. First you can enable the “Any Server” field so that anyone can enter in an address and that phpmyadmin will connect to that database. Its something I kind off need as sometimes you dont want to add the server to the phpmyadmin config file, but just access it a few time.

It is ofcouse a security problem as anyone with web access to your machine can use it to connect to any other mysql sever, but as most of the time my laptop is behind a firewall with very restricted access to it, I can cope.

What you do to enable this is to add one line to the config file (/etc/phpmyadmin/

This will pop up one more input field on the login page called Server and that will allow you to enter the server you whnat to connect to. You can actually enter both the IP or hostname of the server and the port name (after a : ) if you are running mysql on a special port.

And this leads into ssh tunnelling.

Mysql ssh tunneling

One other way to get to a mysql database even through firewalls and other hindrance is to use ssh tunnelling.

You do this with the -L flag to ssh.

So as en example:

will take port 7778 on my local machine and forward that to port 3306 on the other end (localhost on that end). And that is ofcuase the mysql port. So if you can log in to a server ytou can forward a port that way.

This is ofcuase a great way of working with severs and mysql servers, and you can then type in in the server field on the login page of phpmyadmin and work with the remote database.

If you have one or more servers that you regularly are working on the is a way of makeing this even easier.

I have created on small shellscript in the bin directory in my home directory. Its has the same name as the server – lets say foo and consists of:

This way i only have to type foo to access the server and the right ports get forwarded. You could do the same with the config file in ~ssh also.

The you can add the folloing lines to the config file (/etc/phpmyadmin/

This will give you one more server named that can be accessed in the drop down Server Choice box.

This is how I solved my need. Hope it will help someone else.

4 thoughts on “phpmyadmin and remote databases

  1. Pingback: A Linux User in a Windows World » Blog Archive » Having fun with dcop

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.