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:
- ERROR 2003, Can't connect to MySQL server on 'host:port': a client error (client error reference). The network or the listener is the problem: firewall, wrong port, or a server that only listens on some addresses (
bind_addressdefaults to*, but a config file can narrow it to one address). - ERROR 1130: you reached the server, but no account allows your host.
- ERROR 1045, Access denied for user: a host matched, but the user or password did not. That is a different fix, covered in MySQL ERROR 1045.
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:
- Most specific host first. The server sorts accounts with literal IP addresses and host names first, then CIDR and subnet mask values, with
'%'(any host) last, and uses the first row that matches both the host and the user. - String matching. According to the account names page, except for netmask notation the comparison is a string match against what the DNS resolver returns, even for IP-like values. An account written as a host name does not match a client the server only knows by IP, and the other way round.
- localhost is special. On Unix, connecting to
localhostuses the socket file, not TCP (connecting to the server). Such connections match alocalhostaccount if one exists, and only otherwise a wildcard host such as'%', so'app'@'localhost'and'app'@'127.0.0.1'are different accounts. Socket problems have their own error, see Can't connect through socket.
-- 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
- Find the real client address in the error message, not in the client's own network settings.
- 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). - Grant only what the application needs, on the schemas it uses.
- 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.
- Client addresses change. Pods and autoscaled instances get new IPs all the time. Per-IP accounts break on the next scale-out; one account per application subnet, in netmask or CIDR form, keeps working without falling back to
'%'. - Proxies hide the real client. Behind ProxySQL, a cloud database proxy or a load balancer that terminates the connection, the server sees the proxy's address. In our experience 1130 after "nothing changed" is often a proxy that moved to new IPs. Write the accounts for the proxy tier, and keep proxy subnets in your inventory.
- DNS on the login path is a risk. With
skip_name_resolveOFF (the default), the server resolves client host names; the host cache, autosized by default throughhost_cache_size, saves repeat lookups per IP. When DNS is slow or broken, logins slow down or accounts written as host names stop matching. Turning onskip_name_resolveremoves DNS from the path, but the variable is not dynamic, so it needs a restart, and then all Host values must be IP addresses. Run the check below first; enabling it with host-name accounts in place produces 1130 for every one of them. - Health checks can block hosts. In our experience load balancer or monitoring checks that open a TCP connection and close it without finishing the handshake are a common source of ERROR 1129 from the balancer's own address, which then blocks every client behind it. Point checks at a proper login, or raise
max_connect_errorsfor that setup. - Replication and failover accounts too. A replica rebuilt in a new subnet, or a promoted replica that now receives application traffic, needs matching accounts. Keep host rules identical on every server, so the account set does not change when a failover changes which server is primary.
-- 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
- ERROR 1130 means no account's host part matches the address the server sees; the password is never checked.
- Tell it apart from 2003 (network or listener) and 1045 (host matched, user or password wrong).
- Create accounts for the real client address or subnet, using netmask or CIDR notation, and avoid
'%', especially for admin users. - ERROR 1129 is a blocked host: inspect
performance_schema.host_cache, truncate it, and fix the source of the errors. - With proxies, autoscaling and many servers, use subnet accounts, consider
skip_name_resolveafter checking for host-name accounts, and keep accounts identical across replicas.