Symptoms & Diagnosis
The “MySQL login failed” error in phpMyAdmin typically manifests as “Error #1045 – Access denied for user ‘root’@’localhost'”. This occurs when the database server rejects the connection attempt due to incorrect credentials or insufficient permissions.
To diagnose the issue, you must identify whether the problem lies in the phpMyAdmin configuration or the MySQL user table itself. Common indicators include constant password prompts or a specific “mysqli_real_connect()” warning.
| Error Code | Probable Cause | Environment |
|---|---|---|
| #1045 – Access Denied | Incorrect username/password or host mismatch | All MySQL/MariaDB |
| #2002 – No such file | MySQL server is stopped | Linux/macOS |
| Cannot connect: invalid settings | config.inc.php syntax error | phpMyAdmin Config |

Checking the Error Logs
Before making changes, inspect the MySQL error log. This file provides the exact reason why the login failed. On most Linux systems, you can find it using this command:
sudo tail -f /var/log/mysql/error.log
Troubleshooting Guide
Follow these steps in sequence to resolve the access denied error. Start with the most common configuration fixes before attempting to reset database passwords.
1. Update phpMyAdmin Configuration
Often, phpMyAdmin has hardcoded credentials in its configuration file that do not match the actual MySQL user. Locate the config.inc.php file (usually in the phpMyAdmin root directory or /etc/phpmyadmin/).
Ensure the following lines match your database credentials:
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'your_actual_password';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
2. Reset the MySQL Root Password
If you have forgotten the root password, you must reset it via the command line. Stop the MySQL service and restart it in safe mode to bypass authentication.
# Stop MySQL
sudo service mysql stop
# Start in safe mode
sudo mysqld_safe --skip-grant-tables &
# Login without password
mysql -u root
Once inside the MySQL prompt, update the password for the root user:
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewSecurePassword123';
EXIT;
3. Sync Host Definitions
MySQL distinguishes between localhost and 127.0.0.1. If phpMyAdmin is trying to connect via an IP address while the user is defined for “localhost”, the login will fail. Verify the user host settings:
SELECT user, host FROM mysql.user WHERE user='root';
Prevention
To avoid “Access Denied” errors in the future, implement a consistent credential management strategy. Avoid using the root account for daily phpMyAdmin tasks; instead, create a dedicated user with specific database privileges.
Always use an environment-specific configuration file or `.env` variables if your setup supports it. This prevents hardcoding passwords into the `config.inc.php` file, which is a security risk.
Finally, ensure that your MySQL service is set to start automatically on system boot. A stopped service is a frequent “false positive” for login failures.
sudo systemctl enable mysql