phpMyAdmin #2002: Connection refused or No such file or directory
Fix phpMyAdmin error #2002, "The server is not responding": start MySQL, use 127.0.0.1 and the right port, or fix the socket and Docker host.
Error #2002 means phpMyAdmin could not reach MySQL at all, before any login. Either MySQL is not running, or phpMyAdmin is looking in the wrong place for it. Check that first, then the host and port.
What to do, step by step
- Check MySQL is running. In XAMPP or MAMP open the control panel and start MySQL. On Linux run sudo systemctl status mysql (or mysqld, or mariadb).
- If it will not start, read its error log. A port clash on 3306 or a damaged data folder are common causes.
- Open phpMyAdmin's config.inc.php and set the host to 127.0.0.1 instead of localhost. That forces a network connection and skips the socket file.
- If MySQL uses another port, add it: $cfg['Servers'][$i]['port'] = '3307';.
- In Docker, the host is the name of the database service (for example db), not localhost.
Commands you can copy
sudo systemctl status mysqlmysql -h 127.0.0.1 -P 3306 -u root -p$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['port'] = '3306';Other causes to check
- No such file or directory
- phpMyAdmin looked for the MySQL socket file and it is not there. Use host 127.0.0.1, or set the right socket path in config.inc.php.
- #2054 The server requested authentication method unknown to the client
- An old phpMyAdmin with MySQL 8 and its caching_sha2_password login. Update phpMyAdmin, or create the user with mysql_native_password.
- #1045 Access denied
- MySQL answered but rejected the login. See the MySQL access denied page for the right default logins.
- Works on the command line but not in phpMyAdmin
- The command line may use another socket or port than phpMyAdmin. Run mysql -h 127.0.0.1 -P 3306 -u root -p with the same values.
- XAMPP: MySQL shuts down unexpectedly
- Another MySQL on port 3306, or a crash during the last shutdown. Stop the other service, or change the port in my.ini, and check the MySQL error log.
Questions about phpMyAdmin #2002 cannot connect
- What does #2002 mean?
- MySQL error 2002 is "cannot connect to the server". The server is down or unreachable, or phpMyAdmin has the wrong host, port or socket.
- What is the default host for phpMyAdmin?
- localhost, which uses a Unix socket on Linux and macOS. Using 127.0.0.1 forces a TCP connection and often solves this error.
- How do I change the MySQL port in XAMPP?
- Edit the port in my.ini (both [client] and [mysqld]), restart MySQL, and set the same port in phpMyAdmin's config.inc.php.
Config generators for this
- Docker Compose for MySQL and phpMyAdminRun MySQL and the phpMyAdmin web page on your computer with one docker compose command.
- MySQL my.cnf settingsA small MySQL or MariaDB override file for connections, memory, character set and the slow query log.