To reset the MySQL root password and configure MySQL to run without grant tables using skip-grant-tables
Follow these steps:
1. Edit the MySQL Configuration File (my.ini
)
-
Navigate to the MySQL configuration file:
-
If you are using XAMPP, the file will likely be located at:
-
Open
my.ini
with a text editor (e.g., Notepad or Notepad++) with administrative privileges.
-
-
Add the
skip-grant-tables
line: Inside the[mysqld]
section, addskip-grant-tables
to disable the privilege checks temporarily. This allows you to connect to MySQL without a password and reset the root password.Your configuration should look like this:
-
Save the changes and close the file.
2. Restart MySQL Server in Skip-Grant-Table Mode
-
Open XAMPP Control Panel.
-
Stop the MySQL service if it's running.
-
Start MySQL again by clicking the Start button next to MySQL.
3. Access MySQL Without Password
Since the skip-grant-tables
option disables the need for a password, you can now access MySQL without any password.
-
Open the Command Prompt or PowerShell.
-
Enter the following command to access MySQL without a password:
You should now be in the MySQL shell without requiring a password.
4. Reset the Root Password
Once you're inside the MySQL prompt, follow these steps to reset the root password:
-
Select the MySQL database:
-
Update the root password. Replace
'YourNewPassword'
with the password you want to set. -
Flush privileges to apply the changes:
-
Exit MySQL:
5. Stop and Restart MySQL
-
Go back to XAMPP Control Panel.
-
Stop the MySQL service.
-
Remove
skip-grant-tables
from themy.ini
file (to re-enable the usual password protection). -
Start MySQL again from the XAMPP Control Panel.
6. Test the New Root Password
-
Open a new Command Prompt or PowerShell window.
-
Run the following command to check if the password was set successfully:
-
Enter the new password when prompted, and you should be logged into MySQL.
7. Configuring phpMyAdmin (if needed)
If you are using phpMyAdmin to manage your MySQL databases, you may need to update its configuration file to reflect the new root password:
-
Navigate to your XAMPP installation directory, typically:
-
Open the file and find the following section:
-
Update the
password
line with your new root password, like this: -
Save the file.
8. Access phpMyAdmin
Now you can open phpMyAdmin by visiting:
Log in with the username root
and the new password you just set.
Important Notes:
-
The
skip-grant-tables
option allows full access to the MySQL database, bypassing authentication checks. Use this with caution and only when you need to reset the password or fix a MySQL issue. -
Always ensure that you remove it
skip-grant-tables
after you've finished the reset, as leaving it active could expose your MySQL server to unauthorized access.
Let me know if you need further assistance with any of these steps!