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:
mysql -hHOST -uUSER -pPASSWORD
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