Skip to content

ERROR 1130: Host Is Not Allowed to Connect to This MySQL Server

ERROR 1130 means MySQL looked at your client's address, found no account for that host at all, and hung up before asking who you were. How to read the host it printed, why two Docker images behave differently, and the scoped account that fixes it.

mysql-error-1130 host-not-allowed user-host-accounts docker mysql-auth mysql mysql-errors
Gopi Gorantala
Reading Progress

On This Page

ERROR 1130 (HY000): Host '172.18.0.1' is not allowed to connect to this MySQL server

Your user name isn't in that message, and that's the whole story.

No 'fx_loader'@..., no (using password: YES), unlike ERROR 1045. "Host is not allowed to connect to this MySQL server" comes out before MySQL has even asked who you are. The server looked at the address your connection came from, found no account whose host matches it, and closed the door. The password you've been retyping never left your machine.

Here's what it looks like

The text is identical in the MySQL 9.7 server error reference and 8.4: error 1130, symbol ER_HOST_NOT_PRIVILEGED, SQLSTATE HY000, message Host '%s' is not allowed to connect to this MySQL server. The %s is the client host as the server sees it, which is either an IP address or a resolved host name.

What each client wraps around it:

# mysql CLI, MySQL Workbench, DBeaver (same server text, different window)
ERROR 1130 (HY000): Host '172.18.0.1' is not allowed to connect to this MySQL server

# PHP / Laravel (PDO)
SQLSTATE[HY000] [1130] Host '10.20.4.17' is not allowed to connect to this MySQL server

# PyMySQL
pymysql.err.OperationalError: (1130, "Host '10.20.4.17' is not allowed to connect to this MySQL server")

# Connector/J (the form most often seen in Java logs)
java.sql.SQLException: null,  message from server: "Host '172.18.0.1' is not allowed to connect to this MySQL server"

# MariaDB: same number, same SQLSTATE, its own product name
ERROR 1130 (HY000): Host '172.18.0.1' is not allowed to connect to this MariaDB server

The Java wrapper class and prefix vary across Connector/J versions; the quoted server text inside it doesn't. That quoted part is the bit to search for.

It shows up on the first connection attempt, never after an hour or under load. If it appeared after a deploy that "changed nothing", something changed the client's address: a new Docker network, a new pod subnet, a NAT gateway, a move into a container.

Did the server even ask who you are?

No. That's the two-minute triage, and it rules out a lot.

The host_cache table docs say it plainly: when no account is permitted to connect from the client host, the server returns ER_HOST_NOT_PRIVILEGED "and does not even ask for a user name or password." So, compared with its neighbours:

You see How far you got What's wrong
ERROR 2003 nothing answered on that host and port network, port, bind-address (2003)
ERROR 1130 TCP worked, server read your address no account row matches your host
ERROR 1045 server matched an account and checked credentials wrong account matched, or wrong password (1045)
ERROR 1129 server read your address your host is blocked after too many failed handshakes

So with 1130 the network and server are fine. Stop poking at firewalls. The only question is which address the server thinks you came from and which host parts exist in mysql.user (full side-by-side in which MySQL connection error is this).

From any session that does work on the server, usually a local one:

SELECT user, host, plugin FROM mysql.user ORDER BY host, user;  -- needs SELECT on mysql.user
SELECT @@skip_name_resolve, @@version;

Then put the host from the error message next to that list. If nothing in the host column matches it, by exact string, by wildcard, by netmask or by CIDR block, you've found it.

Reproduce it in a throwaway container

Straight about this one: the workspace I wrote this in had no Docker daemon and no network to pull images, so I couldn't run the lab this time. The commands below follow the official image docs; the expected messages come from the error reference, not from my terminal. Run it on your own laptop, never against a shared server.

The interesting setup is two images that look the same and aren't. Docker Hub's mysql image (maintained by docker-library) creates root for host % by default, as a maintainer confirms in docker-library/mysql#527. Oracle's own image, container-registry.oracle.com/mysql/community-server, creates only 'root'@'localhost', per the MySQL manual's Docker page. Same server, same password, opposite answer for anyone outside the container.

  1. A network and the Oracle-image server:
docker network create fx-lab
docker run -d --name fx-db --network fx-lab \
  -e MYSQL_ROOT_PASSWORD=lab \
  container-registry.oracle.com/mysql/community-server:8.4
  1. Wait until docker logs fx-db says it's ready for connections, then dial it from a second container on the same network, using a pinned Docker Hub image only for its client:
docker run --rm -it --network fx-lab mysql:8.4.13 \
  mysql -h fx-db -uroot -plab -e "SELECT CURRENT_USER()"

Expected: ERROR 1130, with the client container's address in the quotes (or a name, if the server's reverse lookup of that address returns one). Note that the user name isn't printed.

  1. Now the experiment that convinced me. From inside the server container, where root works over the socket, create an account that has nothing to do with root:
docker exec -it fx-db mysql -uroot -plab \
  -e "CREATE USER 'probe'@'%' IDENTIFIED BY 'probe-lab-only'"
  1. Repeat step 2. Per the access-control docs, you should now get ERROR 1045 for 'root'@'<your address>' instead of 1130. Nothing about root changed. Some account now exists for your host, so the server moved on to the user-name check and failed there.
  2. Teardown: docker rm -f fx-db && docker network rm fx-lab. The Oracle image keeps data in an anonymous volume, so add docker volume prune if you're done with lab volumes; a reused data directory ignores new MYSQL_ROOT_* values, which is its own trap (init-only variables).

If you get ERROR 2003 instead, the client never reached fx-db. Check that both containers are on fx-lab.

Why it broke, the simple version

MySQL doesn't log in a user. It logs in a user at a host, and an account is the pair (more on that in MySQL accounts are user@host). You created 'fx_loader'@'localhost', or the image created 'root'@'localhost', and then you connected over TCP from somewhere that isn't the server's own machine. No row in the account table names a host that matches where you came from, so MySQL refuses before the handshake.

The check that runs before your user name is read

I lost an afternoon to this on the FX rates loader. The service ran fine on a VM next to the database. We moved it into a container on a Compose network, and every rate fetch logged 1130 with 172.18.0.1. My first instinct was a grants problem with fx_loader, so I spent a good while comparing SHOW GRANTS output between environments. It looked reasonable at the time: grants are what usually differ. They were identical, and they were never consulted.

What cracked it was reading the message for what it leaves out. The server sorts its in-memory copy of mysql.user by host specificity first, then by user. The connection-verification docs give the order: literal IPs and host names first, then CIDR blocks, then netmasks, then %, then the empty host. A connection from an address is checked against the host column of every row before any user name matters. If no host matches, that's 1130. If some host matches, even one that belongs to a monitoring account you forgot about, the server continues and you'll get 1045 instead when your user isn't there. The troubleshooting page states it the same way: 1130 means "there is no row in the user table with a Host value that matches the client host."

The surprise for me was how much that sentence explains. It's why 1130 sometimes "fixes itself" into 1045 after a DBA adds an unrelated '%' account, and why the same app gets 1130 from a laptop and 1045 from a CI runner whose subnet happens to be covered by someone else's account.

Two more rules decide whether a host part matches:

  • It's a string match against what the resolver returns, except for netmask and CIDR hosts. If the server resolves your IP to pluto.example.com and the account says 'pluto', it doesn't match. If you wrote '198.051.100.%' and the resolver returns 198.51.100.2, it doesn't match either.
  • skip_name_resolve turns host names off. With it on, the host cache docs say the server uses only IP addresses to match grant rows, and accounts defined with host names can't be used at all. Plenty of container setups turn it on. An account for 'app-1.internal' is dead on such a server.

Fixing "host is not allowed to connect" without opening root to the world

First, find the address precisely. Believe the host in the error message; that's what the server saw. NAT, a proxy or a Docker bridge means it's rarely the address your app thinks it has. On the server you can also look at the counter that only this error increments:

SELECT IP, HOST, COUNT_HOST_ACL_ERRORS, LAST_ERROR_SEEN
FROM performance_schema.host_cache
WHERE COUNT_HOST_ACL_ERRORS > 0;

That needs SELECT on performance_schema; loopback and socket connections never appear there. It's the fastest way to see which addresses are bouncing when you can't reach the app's logs.

Then create an account for the network the app really lives on, scoped to its schema:

-- the FX loader's pods live in 10.20.0.0/16
CREATE USER 'fx_loader'@'10.20.0.0/255.255.0.0' IDENTIFIED BY 'use-a-secret-manager';
GRANT SELECT, INSERT, UPDATE ON fx.* TO 'fx_loader'@'10.20.0.0/255.255.0.0';

Netmask notation works for IPv4 on every supported version. The 8.4 manual also documents CIDR for IPv4 ('10.20.0.0/16'), which sorts ahead of netmask entries. Both are better than '10.20.%', because the account-name docs mark % and _ wildcards in host parts as deprecated. And remember each account has its own password and authentication plugin: 'fx_loader'@'localhost' and 'fx_loader'@'10.20.0.0/255.255.0.0' are two accounts, and changing one doesn't touch the other.

For the Oracle Docker image, if you genuinely need root from the host during local development, MYSQL_ROOT_HOST=172.17.0.1 (or the gateway of your Compose network) on a fresh volume is the documented knob. It takes one value and is read only at initialisation. For an app, make an app account instead.

What the top answers say, and what it costs:

  • GRANT ALL PRIVILEGES ON *.* TO 'root'@'%': this gives anyone who can reach port 3306 a superuser login guarded by one password. In 8.x that statement also fails if 'root'@'%' doesn't exist, because GRANT no longer creates users.
  • UPDATE mysql.user SET host='%' WHERE user='root' plus FLUSH PRIVILEGES: same exposure, and editing grant tables by hand skips the checks RENAME USER would do.
  • "Open the firewall" or "set bind-address = 0.0.0.0": irrelevant here. You already reached the server; that's how it could refuse you.

The better setup

Give every application its own account, scoped to the network it runs in, created by the same migration or provisioning code that creates its schema. Something like:

CREATE USER IF NOT EXISTS 'fx_loader'@'10.20.0.0/255.255.0.0'
  IDENTIFIED BY 'from-the-secret-store'
  WITH MAX_USER_CONNECTIONS 40;
GRANT SELECT, INSERT, UPDATE ON fx.* TO 'fx_loader'@'10.20.0.0/255.255.0.0';

Keep the app's subnet next to the deployment config, so a network move and an account change ship together. In Compose, pin the network's subnet (ipam.config.subnet) so the bridge address stops drifting between machines. And keep root on localhost; the Oracle image's default is the safer one.

What to alert on

  • COUNT_HOST_ACL_ERRORS in performance_schema.host_cache going above zero for any IP. That's either a misconfigured client after a network change or somebody scanning you; both are worth a page during business hours.
  • Aborted_connects rising faster than usual after a deploy.
  • A CI job that runs CREATE USER scripts against a Testcontainers MySQL at your production version, then connects from a separate container on its own network. That's the test that would have caught our Compose move.

Version notes: the number and text are the same in 8.4 and 9.7, and MariaDB says "MariaDB server". Since 8.0.23 IP-based host parts are checked in a fixed order instead of creation order (release notes), so an old 5.7 server may pick differently. The % deprecation means a future release could stop honouring '10.20.%'; move those accounts to netmask or CIDR before an upgrade forces you. This was a narrower hunt than most, but I checked the message in the 8.4, 9.7 and MariaDB references and walked each documented matching rule before writing it down.

Takeaways

  • No user name in the error means the server never asked for one. Grants and passwords aren't involved yet.
  • The quoted host is the truth. Build the account for that network, not for the address you assumed.
  • Docker Hub's mysql image creates root at %; Oracle's image creates root at localhost. Switching images can introduce 1130 with nothing else changed.
  • Adding any account for your host turns 1130 into 1045. If that happens, you're one step closer, not further away.
  • 'root'@'%' is never the fix.

What people ask about ERROR 1130

How do I fix ERROR 1130 when MySQL runs in Docker?

Read the host in the message; from the Docker host it's usually the bridge gateway, such as 172.17.0.1 or a Compose network's .1 address. With Oracle's image, root exists only at localhost, so create an app account for that subnet, or set MYSQL_ROOT_HOST on a fresh volume for local development only. Init variables are ignored on an existing data directory.

Is ERROR 1130 a firewall problem?

No. A firewall gives you ERROR 2003 because the TCP connection never completes. With 1130 the server accepted the connection, read your address and refused it because no account's host part matches.

What's the difference between ERROR 1130 and ERROR 1045?

1130 is decided on the host alone, before the server asks for a user name. 1045 means some account matched your host, so the server checked the user and credentials and they failed. See the 1045 article for that half.

Should I use '%' as the host to fix it?

Only if that user may log in from anywhere that reaches the port. Scope it to the app's subnet with netmask or CIDR notation; % in host parts is deprecated in the 8.4 manual anyway.

mysql-error-1130host-not-alloweduser-host-accountsdockermysql-authmysqlmysql-errors

Staff engineer architecting Kafka and Flink platforms for banking, where a dropped event is a reconciliation break, not a retry. Through javahandbook.com, I share production-tested guidance on building reliable event-driven systems.

Comments