ERROR 2003 HY000 Can't connect to MySQL server on '127.0.0.1' 111
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Connecting to a MySQL server is a routine task for many developers and system administrators. However, encountering connection errors like ERROR 2003 (HY000) can be particularly frustrating. This specific error code indicates that a connection attempt to the MySQL server at 127.0.0.1 has failed, with the error code (111), meaning "Connection refused."
Understanding the Error
The error can be broken down into its components:
- ERROR 2003 (HY000): The MySQL client error code that suggests a problem connecting to the MySQL server.
- Can't connect to MySQL server on '127.0.0.1': Indicates the attempt was made to connect to the MySQL server running on the local machine (localhost).
- (111): A typical UNIX/Linux error code meaning "Connection refused," which often suggests that the server is not listening on the specified port or is not running.
Common Causes
- MySQL Server Not Running:
- The MySQL service might be stopped. Confirm by running
service mysql statusorsystemctl status mysqlto check the service status.
- Incorrect Configuration:
- MySQL configuration (
my.cnformy.ini) might not be set up to listen on127.0.0.1. Check the[mysqld]section forbind-address=127.0.0.1.
- Firewall Restrictions:
- Firewall settings may block inbound connections to MySQL's default port (3306). Use
iptables,firewalld, or equivalent tools to verify and adjust firewall settings.
- Port Issues:
- MySQL might not be set to use the default port 3306. Verify the port setting in your configuration file and connect using
--port=if different.
- Network Configuration:
- Network issues could also prevent connection. Confirm network interfaces are up and properly configured.
Diagnostic Steps
- Check MySQL Service Status:
- Open the configuration file typically found at
/etc/mysql/my.cnfor/etc/my.cnf. - Make sure the relevant section has:
- View MySQL logs often located in
/var/log/mysql/or/var/log/. - On systems with SELinux, ensure it's not preventing access.
Related reading
- ERROR 2006 HY000 MySQL server has gone away
- error 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' 2' -- Missing /var/run/mysqld/mysqld.sock
- Error Code 1292 - Truncated incorrect DOUBLE value - Mysql
- Error Code 2013. Lost connection to MySQL server during query
- Error 5 Access Denied when starting windows service
- Error _handleNonLaunchSpecificActions in iOS9
- Error creating bean with name 'entityManagerFactory' defined in class path resource Invocation of init method failed
- Error Dropping Database Can''t rmdir ''.test'', errno 17

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.