Home > Database > Mysql Tutorial > Why Can't I Remotely Connect to MySQL Using the '%' Wildcard?

Why Can't I Remotely Connect to MySQL Using the '%' Wildcard?

DDD
Release: 2024-12-07 12:54:11
Original
783 people have browsed it

Why Can't I Remotely Connect to MySQL Using the '%' Wildcard?

Connecting Remotely to MySQL Using '%' Wildcard

Question:

When attempting to connect to a MySQL database remotely using the 'user@'%' account, connection issues arise despite successfully connecting using 'user@'localhost'. Why does '%' not allow connections from any host?

Answer:

To establish remote connections, follow these steps:

1. Configure MySQL Bind Address:

Edit the my.cnf (my.ini on Windows) file and set the bind-address parameter to your machine's IP address:

bind-address = xxx.xxx.xxx.xxx
Copy after login

2. Create Wildcard User and Grant Permissions:

Execute the following commands:

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';
Copy after login
GRANT ALL ON *.* TO 'myuser'@'localhost';
GRANT ALL ON *.* TO 'myuser'@'%';
Copy after login
FLUSH PRIVILEGES;
Copy after login

3. Open Remote Connection Port:

Depending on your operating system, it may be necessary to open port 3306 to allow remote connections.

Explanation:

'%' does allow connections from any host. However, for remote connections, MySQL must be configured to bind to the appropriate IP address. Additionally, the user must be created with both the 'localhost' and '%' wildcard privileges granted for all databases.

The above is the detailed content of Why Can't I Remotely Connect to MySQL Using the '%' Wildcard?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template