Home > Database > Mysql Tutorial > Why Do I Get 'Host 'xxx.xx.xxx.xxx' is Not Allowed to Connect to This MySQL Server' Even with a '%' Host Entry?

Why Do I Get 'Host 'xxx.xx.xxx.xxx' is Not Allowed to Connect to This MySQL Server' Even with a '%' Host Entry?

DDD
Release: 2024-12-20 18:06:11
Original
688 people have browsed it

Why Do I Get

Remote MySQL Connection Error: "Host Not Allowed"

Connecting remotely to MySQL can sometimes result in the error message "Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server." Despite having a root user entry with a host value of both 'localhost' and '%', the connection fails.

This issue is typically encountered due to security measures implemented by MySQL. One possible solution is to create a new administrative user with specific privileges and access restrictions:

Creating a New Administrative User:

mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost' ->     WITH GRANT OPTION;
mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%' ->     WITH GRANT OPTION;
Copy after login

While granting extensive privileges is convenient, it is not recommended due to security risks. Instead, it's prudent to:

  • Limit user access to the specific hosts and IPs required.
  • Grant only the necessary privileges for the task at hand.

MySQL FAQ Insight:

The MySQL FAQ provides further clarification on this issue:

"If you cannot figure out why you get 'Access denied', remove all user table entries that have host values containing wildcards (e.g., '% or _'). It's common to accidentally insert an entry with host='%' and user='some_user' to enable localhost connections. However, it won't work because the default privileges include an entry with host='localhost' and user=''. The localhost entry is more specific and will be used instead. To allow localhost connections, insert a second entry with host='localhost' and user='some_user', or delete the default localhost entry and issue a FLUSH PRIVILEGES statement."

The above is the detailed content of Why Do I Get 'Host 'xxx.xx.xxx.xxx' is Not Allowed to Connect to This MySQL Server' Even with a '%' Host Entry?. 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