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:
1 |
sudo apt-get install phpmyadmin |
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/config.inc.php):
1 |
$cfg['AllowArbitraryServer'] = TRUE; |
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:
1 |
ssh -L 7778:localhost:3306 jan@www.foo.net |
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 127.0.0.1:7778 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:
1 2 3 4 |
#!/bin/sh #Start ssh to foo with forwarding of mysql port echo "ssh -L 7778:localhost:3306 jan@www.foo.net" ssh -L 7778:localhost:3306 jan@www.foo.net |
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/config.inc.php):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
//------------------------------------------------- $i++; $cfg['Servers'][$i]['host'] = '127.0.0.1'; $cfg['Servers'][$i]['port'] = '7779'; $cfg['Servers'][$i]['socket'] = ''; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['extension'] = 'mysql'; $cfg['Servers'][$i]['compress'] = FALSE; $cfg['Servers'][$i]['controluser'] = ''; $cfg['Servers'][$i]['controlpass'] = ''; $cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['Servers'][$i]['user'] = ''; $cfg['Servers'][$i]['password'] = ''; $cfg['Servers'][$i]['only_db'] = ''; $cfg['Servers'][$i]['verbose'] = 'foo.net'; |
This will give you one more server named foo.net that can be accessed in the drop down Server Choice box.
This is how I solved my need. Hope it will help someone else.
great!!
i was looking for this….
concise, simple, easy….. and very useful
Thanks
Well thats kind of why i did the blog. Both to document for myself and help others.
Thanks
Pingback: A Linux User in a Windows World » Blog Archive » Having fun with dcop
Thanks!!
Straight away worked for me…
Keep up the good work….
Good one…