Incident Response

MySQL ERROR 1130: Host is not allowed to connect to this MySQL server

The server is up, the port is open, the password is right, and MySQL still refuses before it even asks for it. Error 1130 is about the host part of the account, not the password. Here is how MySQL matches hosts, the fix that does not end in a root@% account, and what changes with autoscaling, proxies and hundreds of clients.

· 12 min read · AG Data Team

MySQL ERROR 1130: Host is not allowed to connect to this MySQL server means the server received your connection, looked at the address you came from, and found no account whose host part matches it. MySQL accounts are always user@host pairs, and here it is the host half that fails, before the password is even checked.

$ mysql -h db1.internal -u app -p
ERROR 1130 (HY000): Host '10.20.3.17' is not allowed to connect to this MySQL server

The server error reference lists it as ER_HOST_NOT_PRIVILEGED, SQLSTATE HY000. The troubleshooting chapter is direct about the meaning: there is no row in the user table with a Host value that matches the client host. The address in quotes is how the server sees you, which is often not what you expect: a NAT gateway, a proxy, a container network address, or a reverse DNS name.

1130, 1045 or 2003?

Three errors look alike in an outage, and they point to different layers:

So 1130 is good news in one way: the network path works. You only need the right account.

How MySQL matches the host

The connection verification chapter explains the rules that cause most surprises:

-- on the server, as an admin: which hosts does each account allow?
SELECT user, host FROM mysql.user ORDER BY user, host;

-- after you get in from the client: how did the server see you?
SELECT USER(), CURRENT_USER();

USER() shows the user and host you tried to log in as; CURRENT_USER() shows which account row actually matched. When they differ, a broader account than you intended let you in.

The fix: an account for that host or subnet

  1. Find the real client address in the error message, not in the client's own network settings.
  2. Create an account for that address, or better for the application subnet. IPv4 host values can use netmask notation (10.20.0.0/255.255.0.0) or CIDR notation (10.20.0.0/16).
  3. Grant only what the application needs, on the schemas it uses.
  4. Or move an existing account with RENAME USER; the RENAME USER page confirms that the privileges move with it.
-- one host
CREATE USER 'app'@'10.20.3.17' IDENTIFIED BY '...';

-- a whole application subnet (netmask or CIDR notation)
CREATE USER 'app'@'10.20.0.0/255.255.0.0' IDENTIFIED BY '...';
CREATE USER 'app'@'10.20.0.0/16' IDENTIFIED BY '...';

GRANT SELECT, INSERT, UPDATE, DELETE ON shop.* TO 'app'@'10.20.0.0/16';

-- move an existing account to another host, keeping its privileges
RENAME USER 'app'@'10.20.3.17' TO 'app'@'10.20.0.0/16';

Do not "fix" it with root@'%'. The MySQL documentation itself suggests a '%' account only as a temporary step to discover the real host, and warns that leaving it opens the account to connections from any host. A database port reachable from the internet plus a wildcard admin account is how many breaches start. Use specific subnets and a separate least-privilege account for the application.

Blocked hosts: ERROR 1129

A related error appears after many failed attempts: Host '...' is blocked because of many connection errors. The host cache documentation explains that the server counts successive blocking errors per client IP and blocks the host after max_connect_errors of them (default 100, see system variables). The host_cache table shows the counters. Unblock by truncating it; FLUSH HOSTS is deprecated as of MySQL 8.0.23 (FLUSH documentation). Then find what is producing the errors, or the block will come back.

-- ERROR 1129: Host '...' is blocked because of many connection errors
SELECT IP, HOST, SUM_CONNECT_ERRORS, COUNT_HOST_BLOCKED_ERRORS
FROM performance_schema.host_cache
ORDER BY SUM_CONNECT_ERRORS DESC
LIMIT 20;

-- unblock (FLUSH HOSTS is deprecated since 8.0.23)
TRUNCATE TABLE performance_schema.host_cache;

What changes with many clients

With two application servers you add an account by hand. With autoscaling groups, Kubernetes, connection proxies and replicas in several networks, host rules become part of the architecture, and the same error can take down a whole service at once.

-- accounts that would stop matching if you enable skip_name_resolve
SELECT user, host FROM mysql.user
WHERE host NOT REGEXP '^[0-9.:/%]+$'
  AND host NOT IN ('localhost');

-- accounts open to the whole world
SELECT user, host FROM mysql.user WHERE host = '%';

# my.cnf: no DNS on the login path (needs a restart)
[mysqld]
skip_name_resolve = ON

Key takeaways

MySQL Errors Security Connectivity
Work with us

Locked out of MySQL after a network change?

We restore access safely, clean up MySQL accounts and host rules across your servers, and set up access that survives autoscaling and failovers.

Get in touch More from the blog