Home  >  Article  >  Database  >  How to Allow Remote Connections in MySQL?

How to Allow Remote Connections in MySQL?

DDD
DDDOriginal
2024-11-19 03:19:02294browse

How to Allow Remote Connections in MySQL?

Allowing Remote Connections in MySQL

Unlike SQL Server, MySQL requires manual configuration to allow remote database connections. To achieve this, you can utilize the GRANT command. Rather than granting permissions to individual IP addresses, you can grant access to all remote connections by using the '%' wildcard.

Command:

GRANT ALL ON *.* to user@'%' IDENTIFIED BY 'password';

This command grants all privileges to the user with the specified password, allowing them to connect from any host.

Additional Considerations:

However, it's important to note that additional steps may be required for the remote connection to work. Specifically, a user account from localhost must be created for the same user. This is because the anonymous account created by mysql_install_db may take precedence otherwise, preventing the remote connection from authenticating properly.

Therefore, for a user named 'user' to connect from any server, the following two accounts must be created:

GRANT ALL ON *.* to user@localhost IDENTIFIED BY 'password';
GRANT ALL ON *.* to user@'%' IDENTIFIED BY 'password';

By following these steps, you can effectively allow all remote connections in your MySQL database while maintaining proper security measures. Remember that this approach is only recommended for development databases within a controlled network environment.

The above is the detailed content of How to Allow Remote Connections in MySQL?. 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