Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

MySQL accepts local logins but refuses connections from other machines

ErrorCan't connect to MySQL server on 'host' (111)

Short answer

A refused connection means nothing accepted it at the network level. If it works on the server itself but not from another machine, the server is often bound to 127.0.0.1 only. Check bind_address and skip_networking, test the port with telnet, then look at the firewall.

  • Applies to MySQL 8.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    On the server, read the two settings that decide whether TCP connections from outside are accepted.

    SHOW VARIABLES LIKE 'bind_address';
    SHOW VARIABLES LIKE 'skip_networking';
    SHOW VARIABLES LIKE 'port';
  2. 2Match what you see, then jump to its fix

    1. 1bind_address shows 127.0.0.1 and the same login works with -h 127.0.0.1 on the serverbind_address is 127.0.0.1, so only local TCP connections are acceptedFix
    2. 2skip_networking shows ON, and no TCP login works at all, even with 127.0.0.1skip_networking is enabledFix
    3. 3telnet to the port says Connection refused even from the server hostThe client uses a different port than the server listens on, or the server is not runningFix
    4. 4Everything above is correct, the server listens, and a client on another machine still cannot reach port 3306A firewall blocks the MySQL portFix

What does the error look like?

  • Can't connect to MySQL server on 'host' (111)
  • ERROR 2003 (HY000): Can't connect to MySQL server on '203.0.113.10:3306'
  • telnet: Unable to connect to remote host: Connection refused

Cause 1 of 4

bind_address is 127.0.0.1, so only local TCP connections are accepted

1Check

With bind_address set to 127.0.0.1 the server listens on the loopback interface only and does not accept remote connections. The default value is * (all interfaces).

SHOW VARIABLES LIKE 'bind_address';

2Fix

Set bind_address in the [mysqld] section of the option file to the server's own address, or * for all interfaces, then restart. The variable is not dynamic, so a restart is required. Keep an administrative account that can connect to that address.

[mysqld]
bind-address = 203.0.113.10

3Verify

After the restart, the variable shows the new address and the client connects.

SHOW VARIABLES LIKE 'bind_address';
mysqladmin -h 203.0.113.10 --port=3306 version

Confirmed by dev.mysql.com

Did this fix it?

Cause 2 of 4

skip_networking is enabled

1Check

With skip_networking on, the server accepts no TCP/IP connections at all.

SHOW VARIABLES LIKE 'skip_networking';

2Fix

Remove skip-networking from the option files (or set it off), then restart the server.

[mysqld]
# skip-networking

3Verify

skip_networking shows OFF and telnet reaches the port.

SHOW VARIABLES LIKE 'skip_networking';

Confirmed by dev.mysql.com

Did this fix it?

Cause 3 of 4

The client uses a different port than the server listens on, or the server is not running

1Check

The manual's checks are: is a mysqld process running, and is the port the one configured on the server. Test the port you are using.

ps xa | grep mysqld
telnet some_host 3306

2Fix

Start the server if it is down. If the port differs from 3306, use the value from SHOW VARIABLES LIKE 'port' in the client.

mysql -h 203.0.113.10 -P 3306 -u app -p

3Verify

telnet answers with text that includes the server version.

telnet 203.0.113.10 3306

Confirmed by dev.mysql.com

Did this fix it?

Cause 4 of 4

A firewall blocks the MySQL port

1Check

The manual says to check that no firewall blocks the MySQL port, which is 3306 by default (IP tables on Linux, Windows Firewall on Windows).

telnet 203.0.113.10 3306

2Fix

Allow TCP port 3306 only from the client addresses that need it, in your firewall tool or cloud security group.

# add a rule: allow tcp/3306 from the client IP only

3Verify

telnet from the client connects.

telnet 203.0.113.10 3306

Confirmed by dev.mysql.com

Did this fix it?

How do I stop it coming back?

  • Open the database port to named client addresses only; do not publish 3306 to the internet.
  • Create accounts with a host part that matches the clients, and keep bind_address deliberate.
  • Record bind_address, port and firewall rules together in your server setup notes.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.