How to Reset PHPMyAdmin and MySQL Root Password on Debian

How to Reset PHPMyAdmin and MySQL Root Password on Ubuntu


Have you ever found yourself locked out of your PHPMyAdmin and MySQL on your Ubuntu server due to forgotten passwords? Don't worry; it happens to the best of us. In this guide, we'll walk you through the steps to reset the PHPMyAdmin and MySQL root passwords on your Ubuntu system.


Prerequisites

Before we dive into the password reset process, you should have:


- Access to your Ubuntu server with sudo privileges.

- PHPMyAdmin and MySQL installed on your system.


Step 1: Reset MySQL Root Password


The first step is to reset the MySQL root password. Follow these steps:


1. Stop MySQL Service: Open a terminal and stop the MySQL service:

   sudo systemctl stop mysql

2. Start MySQL in Safe Mode: Start MySQL in safe mode to bypass password authentication:

   sudo mysqld_safe --skip-grant-tables &

3. Access MySQL: Log into the MySQL server without requiring a password:

   mysql -u root

4. Reset Root Password: Inside the MySQL prompt, update the root password:

   USE mysql;

   UPDATE user SET authentication_string=PASSWORD('new_password') WHERE User='root';

   FLUSH PRIVILEGES;

   EXIT;


   Replace `'new_password'` with your desired new password.


5. Restart MySQL: Stop the MySQL service in safe mode:


   sudo systemctl stop mysql


Step 2: Reset PHPMyAdmin Password


PHPMyAdmin often uses the MySQL root or a specific user for login. You need to update the password in PHPMyAdmin's configuration:


1. Locate the PHPMyAdmin Configuration File: Open the PHPMyAdmin configuration file in a text editor:

   sudo nano /etc/phpmyadmin/config.inc.php

2. Update PHPMyAdmin Configuration: Find the lines that define the PHPMyAdmin username and password. Update them with the new MySQL root password you set earlier:


   $cfg['Servers'][$i]['user'] = 'root';

   $cfg['Servers'][$i]['password'] = 'new_password';


   Save the file and exit the text editor.

   sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown

   sudo systemctl start mysql


3. Restart Services: Restart both MySQL and your web server (Apache or Nginx) to apply the changes:

   sudo systemctl restart mysql

   sudo systemctl restart apache2  # For Apache

   or

   sudo systemctl restart nginx    # For Nginx

Conclusion


By following these steps, you can successfully reset the PHPMyAdmin and MySQL root passwords on your Ubuntu server. It's essential to keep your passwords secure and easily recoverable to avoid any disruption to your server's services. 


Remember to replace `'new_password'` with your actual desired password during the process. If you encounter any issues or need further assistance, don't hesitate to seek help from the community or online resources.


Now you should be able to access PHPMyAdmin using the updated MySQL root password. Happy database management!