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
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?
To install the command line MySQL client you should do:
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-addressand is set in
/etc/mysql/my.cnf. By default it is
127.0.0.1- 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:
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.