
This assume you are already able to connect to mySQL or MariaDB as root on the system that mySQL or MariaDB has been installed on (localhost).
To be able to connect to mySQL or MariaDB from a remote system, the mysql command line tool will need to be installed on the remote system. The which command can be used to determine if the mysql command line tool is installed. In this example, the mysql command line tool is installed.
~]# which mysql
/bin/mysql
The -h or --host option can be used with the DNS name or IP address of the remote MariaDB or mySQL database.
~]# mysql --host=sql.example.com
Or, you can update the main mySQL or MariaDB configuration file (e.g. /etc/my.cnf) to have the IP address of the remote system. You will need to restart mySQL or MariaDB for this change to take effect.
bind-address=10.14.56.3
You will also need to configure a user with permission to connect to make a remote connection. The select mysql users command can be used to display a users permissions.
mysql --execute="select * from mysql.user \G"
In this example, user john.doe has access to host %. The % character is used for remote connections.
Host: %
User: john.doe
By default, mySQL or MariaDB listens on port 3306. Assuming the mysql client has been installed on the remote system, the mysql command can be used to make a remote connection to mySQL or MariaDB.
mysql --host=foo.example.com --port=3306 --user=john.doe --password
Or to connect to the database named "db001".
mysql --host=foo.example.com --port=3306 --user=john.doe --password=db001
Did you find this article helpful?
If so, consider buying me a coffee over at