MySQL accepts local logins but refuses connections from other machines
Can'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.
Fix it fast
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';2Match what you see, then jump to its fix
- 1
bind_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
skip_networking shows ON, and no TCP login works at all, even with 127.0.0.1skip_networking is enabledFix - 3
telnet 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
Everything above is correct, the server listens, and a client on another machine still cannot reach port 3306A firewall blocks the MySQL portFix
- 1
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.103Verify
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 versionConfirmed by dev.mysql.com
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-networking3Verify
skip_networking shows OFF and telnet reaches the port.
SHOW VARIABLES LIKE 'skip_networking';Confirmed by dev.mysql.com
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 33062Fix
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 -p3Verify
telnet answers with text that includes the server version.
telnet 203.0.113.10 3306Confirmed by dev.mysql.com
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 33062Fix
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 only3Verify
telnet from the client connects.
telnet 203.0.113.10 3306Confirmed by dev.mysql.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
PHP cannot log in because the database says your host is not allowed
Host is not allowed to connect to this MySQL server
Error 1130 means the server has no account whose host part matches the machine PHP connects from.
3 causes, each with a fixDatabases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
A query on Aurora MySQL dies with 'table /rdsdbdata/tmp/#sql... is full'
ERROR 1114 (HY000): The table '/rdsdbdata/tmp/#sqlfd_1586_2' is full
In Aurora MySQL 3, internal temporary tables share one pool, and when that pool and the memory-mapped overflow file are used up, a reader instance ends the query with error 1114.
3 causes, each with a fixDatabases
Azure Database for MySQL refuses a connection that does not use SSL
ERROR 3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.
Azure Database for MySQL Flexible Server requires encrypted connections by default (require_secure_transport = ON, TLS 1.2).
4 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
DBeaver fails to resolve Maven dependencies when downloading a database driver
A driver library does not download automatically
DBeaver downloads driver jars from a Maven repository.
3 causes, each with a fix