By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

Connecting to MySQL from a Terminal

How to connect to a MySQL server from terminal

Edited: 2013-05-11 08:24

This Tutorial shows you how to connect to your external MySQL server, from your terminal in Ubuntu. The command will need both a hostname, username, and a password – and the user connecting to your server should have the necessary privileges.

It can sometimes be useful to connect to a MySQL server from the terminal – especially when testing and debugging – rather than cummunicating with it from server sided scripts.

The command that you need to use is as follows:


Note. There is no space between -p and PASSWORD – for simplicity, don't use spaces in the between -u and the USER either!

If the terminal throws an error saying that MySQL is not installed – and you know that MySQL is installed – a solution is to type the path for your MySQL executable. This might be a problem if you are using lampp for example. The command should look like:

/opt/lampp/bin/mysql -hHOST -uUSER -pPASSWORD

More MySQL Tutorials

  1. Backup MySQL databases from a terminal