Forgetting your phpMyAdmin password can be frustrating, especially when you’re in the middle of working on a critical project. Fortunately, resetting the password is a straightforward process. This guide walks you through the steps needed to reset your phpMyAdmin (MySQL/MariaDB) root password on a local or remote server.
Step-by-Step Guide to Reset phpMyAdmin Root Password
Step 1: Stop the MySQL Service
Before making any changes, stop the MySQL or MariaDB service.
sudo systemctl stop mysql
Step 2: Start MySQL in Safe Mode
Run MySQL in safe mode without password authentication.
sudo mysqld_safe --skip-grant-tables &
This allows you to log in without needing a password.
Step 3: Log in to MySQL
Now log into MySQL as the root user:
mysql -u root
You’ll be taken directly to the MySQL shell.
Step 4: Change the Root Password
Run the following commands to change the root password.
For MySQL 5.7+ or MariaDB 10.1+:
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';
For older versions:
USE mysql;
UPDATE user SET password=PASSWORD('your_new_password') WHERE User='root';
FLUSH PRIVILEGES;
Replace 'your_new_password'
with your desired password.
Step 5: Stop MySQL Safe Mode and Restart Normally
Press Ctrl+C
to stop the MySQL safe mode process (if it’s running in foreground), or kill it using:
sudo killall -9 mysqld_safe
sudo killall -9 mysqld
Then start the service again:
sudo systemctl start mysql
Step 6: Test Login to phpMyAdmin
Go to http://localhost/phpmyadmin
or your server’s phpMyAdmin URL and log in using:
- Username:
root
- Password: the new password you just set
If successful, you’re good to go!
Tips for Better Security
- Avoid using the
root
account for daily tasks. Create a separate user with limited privileges. - Use strong, unique passwords and store them securely using a password manager.
- Regularly update MySQL/MariaDB and phpMyAdmin for security patches.
Common Issues & Fixes
Issue: Access denied for user 'root'@'localhost'
Fix: Ensure you flushed privileges and restarted the MySQL server after changing the password.
Issue: phpMyAdmin login loop
Fix: Check config.inc.php
in your phpMyAdmin directory. Ensure $cfg['Servers'][$i]['auth_type']
is set to 'cookie'
.
Conclusion
Resetting a forgotten phpMyAdmin password isn’t difficult when you follow the correct steps. Always remember to restart the MySQL service after resetting the password and ensure your configuration files are properly set. Keeping your credentials secure and using non-root accounts for regular usage can further enhance your database security.