Home > Database > Mysql Tutorial > 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
Release: 2024-11-06 08:10:03
Original
708 people have browsed it

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}
Copy after login

Here's an example:

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

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template