Home  >  Article  >  Database  >  How to Connect to a MySQL Server on a Remote PC in a LAN?

How to Connect to a MySQL Server on a Remote PC in a LAN?

Susan Sarandon
Susan SarandonOriginal
2024-11-14 11:26:01469browse

How to Connect to a MySQL Server on a Remote PC in a LAN?

Connecting to a MySQL Server on a Remote PC in LAN

You have encountered an issue while attempting to connect to a MySQL database hosted on another computer within your local network. Despite having MySQL installed on your client computer, the connection is failing.

To establish the connection, consider the following steps:

Resolving Unknown Host Error:

You previously executed the command:

mysql -u user -h 192.168.1.28:3306 -p password

However, the port number (3306) should be included after the database address:

mysql -u user -h 192.168.1.28 -p password

Resolving Access Denied Error:

You have successfully connected without specifying the port, but now encounter an access denied error. To resolve this, grant access privileges to the remote computer.

  1. On the server machine where MySQL is running:

    • Open the MySQL command prompt.
    • Execute the following command to grant all privileges to the 'root' user from the remote computer's IP address:
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.28' IDENTIFIED BY 'root_password';
    • Execute the following command to apply the changes:
    FLUSH PRIVILEGES;
  2. Replace 'root_password' with the actual root password of the MySQL server.
  3. Replace '192.168.1.28' with the IP address of the client computer (the one from which you want to connect).

Additional Notes:

  • Ensure that the MySQL server is listening on the correct IP address and port.
  • Confirm that your client computer has a firewall that allows connections to the MySQL server.
  • If you continue to encounter issues, check the MySQL documentation or online forums for further troubleshooting solutions.

The above is the detailed content of How to Connect to a MySQL Server on a Remote PC in a LAN?. 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