Home > Database > Mysql Tutorial > body text

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

Susan Sarandon
Release: 2024-11-14 11:26:01
Original
467 people have browsed it

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

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

mysql -u user -h 192.168.1.28 -p password
Copy after login

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';
    Copy after login
    • Execute the following command to apply the changes:
    FLUSH PRIVILEGES;
    Copy after login
  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!

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