I am trying to connect to a remote MySQL database in Bash. On the server hosting the database I can type:

mysql -u _username_ -p

to connect.

I would like to be able to type:

mysql -h _host_ -u _username_ -p

to connect from another server. I don't have MySQL installed on the client so the command is not found. Is there something I can install (apt-get preferred) besides the entire MySQL-server so I can use the mysql commands in bash?

  • 1
    apt-get install mysql-client I thought it was only for the GUI client. – user722307 Jan 15 '12 at 7:30
  • You can answer your own question, and after some time you can also accept it. – enzotib Jan 15 '12 at 10:01

To install the command line MySQL client you should do:

sudo apt-get install mysql-client

and then you can do


However you may need to alter the set up of the MySQL server. By default on ubuntu the MySQL server will only accept connections from the local server. The setting is called bind-address and is set in /etc/mysql/my.cnf. By default it is - you should change it to the IP address of the server. If the server has multiple IP addresses you can choose just one IP address (say for the internal network) or have MySQL listen to all IP addresses by making the value

You will also need to ensure that the MySQL user can access the database. Following instructions on the internet, you may have created user 'myname'@'localhost' - that user will not be able to connect remotely. To create a new user who can connect from your client IP address you need to do something like:

GRANT ALL PRIVILEGES ON database_name TO 'username'@'' IDENTIFIED BY 'password';

Read a little more about the address specification MySQL uses.

Finally don't forget to ensure that the server firewall will allow access to the MySQL port - the default is 3306.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.