Home >Database >Mysql Tutorial >How to Connect to a Remote MySQL Database via Command Line?
Connecting to Remote MySQL Databases via Command Line
Accessing remote database servers from the command line can be challenging. In this example, an attempt to connect to a Rackspace-hosted database using the command:
mysql -u username -h my.application.com -ppassword
resulted in the error:
ERROR 2003 (HY000): Can't connect to MySQL server on 'my.application.com' (10061)
Causes of the Error
This error occurs due to an incorrect command syntax or network connectivity issues.
Resolving the Issue
To establish a direct connection to a remote MySQL console, use the following command:
mysql -u {username} -p'{password}' \ -h {remote server ip or name} -P {port} \ -D {DB name}
Replace the placeholders with the relevant values:
Example
To connect to a local database named "local" with the username "root" and password "'root," use the command:
mysql -u root -p'root' \ -h 127.0.0.1 -P 3306 \ -D local
Upon successful connection, you will be switched to the specified database's console.
The above is the detailed content of How to Connect to a Remote MySQL Database via Command Line?. For more information, please follow other related articles on the PHP Chinese website!