Home >Database >Mysql Tutorial >Can't Connect to MySQL on Another PC in LAN: What am I Doing Wrong?

Can't Connect to MySQL on Another PC in LAN: What am I Doing Wrong?

DDD
DDDOriginal
2024-11-10 19:56:021026browse

Can't Connect to MySQL on Another PC in LAN: What am I Doing Wrong?

Connecting to MySQL Server on Another PC in LAN: Resolving Connection Issues

Initial Problem:

A user is unable to connect to a MySQL database hosted on another PC within the local network, despite having MySQL installed on the client machine. The error message encountered indicates that the MySQL server host is not recognized.

Solution for Initial Problem:

To successfully connect to the MySQL server on another PC, the following steps are crucial:

  • Ensure that both the server and client computers are on the same LAN network.
  • Verify that the MySQL server is listening on the correct port, usually 3306.
  • Use the following command on the client computer:
mysql -u username -h server_ip -p password

where username is the database user, server_ip is the IP address of the server PC, and password is the user's password.

Subsequent Problem:

After using the correct command, the user encounters an access denied error, citing that the user '@'MACBOOK' is denied access.

Solution for Subsequent Problem:

To grant access to the database from the client PC:

  1. On the MySQL server, grant privileges to the specified user or IP address. For example:
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'user_password';
  1. Refresh the privileges with the command:
FLUSH PRIVILEGES;
  1. Replace username and user_password with the appropriate values and % with the IP address of the client computer.

The above is the detailed content of Can't Connect to MySQL on Another PC in LAN: What am I Doing Wrong?. 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