Home  >  Article  >  Database  >  How Do I Connect to a Remote MySQL Database from the Command Line?

How Do I Connect to a Remote MySQL Database from the Command Line?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-06 08:10:03614browse

How Do I Connect to a Remote MySQL Database from the Command Line?

Accessing Remote MySQL Database from Command Line

When attempting to connect to a remote MySQL database from the command line, it's common to encounter errors like "ERROR 2003...Can't connect to MySQL server on '{server address}'".

To resolve this issue, authenticate to the database using the correct syntax:

mysql -u {username} -p'{password}' \
    -h {remote server ip or name} -P {port} \
    -D {DB name}

Here's an example:

mysql -u root -p'root' \
        -h 127.0.0.1 -P 3306 \
        -D local

Key Points:

  • Use the correct syntax with no spaces after -p.
  • Specify the remote server IP or name (-h) and port (-P).
  • Connect to the desired database (-D) to switch to its console.

By following these steps, you should be able to successfully connect to the remote MySQL database from the command line.

The above is the detailed content of How Do I Connect to a Remote MySQL Database from the Command Line?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn