Access Denied for User 'root'@'localhost' (using password: YES) - No Privileges?
#1
I’ve encountered a serious issue with MySQL where the root user has lost all privileges out of nowhere. I'm using MySQL Workbench and it's apparent that the schema privileges for the root user are gone. It’s causing significant disruption across various platforms that rely on this server. I've tried to approach this problem by running a couple of commands like FLUSH PRIVILEGES, but nothing seems to work. The peculiar part is that [email protected] has proper access, but when I log in, the privileges aren’t there, and it defaults to 'localhost' which doesn't have any privileges either. The lack of access is what's so baffling and is hindering my ability to solve this problem. I don’t understand how to restore root access when I can’t even execute GRANT statements due to the lack of privileges.
Here’s what I get when running SHOW GRANTS FOR root:

Code:
@ 'localhost';

But it returns nothing, implying there are no privileges to show. I'm in a deadlock situation here and could use some expert guidance on how to restore root privileges from this state.
Reply
#2
It seems like a tricky situation you've gotten into, especially since root should theoretically have all privileges. Since you've lost access, you’ll need to start the MySQL server with the --skip-grant-tables option to bypass the privilege system. Here's how you can do it:
First, stop your MySQL server:


Next, you’ll need to start it with the --skip-grant-tables option, but make sure to do so with caution as this will allow unrestricted access to all databases.


After you have restarted the MySQL server with the grant tables skipped, you should be able to log in as root without a password.


Once logged in, issue the following commands to reset the privileges:

Code:
@ 'localhost'
WITH GRANT OPTION;

You should also assign a password to the root account if it's not already set:

Code:
@ 'localhost'
IDENTIFIED BY 'new_password';

Don't forget to restart the MySQL server normally after you've performed these actions to ensure that the privilege system works as intended:


Note: Make sure to replace 'new_password' with a strong password of your choosing.
Reply
#3
Alright, I followed the steps you provided, and I was able to restore root access. For anyone else facing the same ordeal, here’s the full solution:
1. First, stop the MySQL service:


2. Start the MySQL server with no grant tables:


3. Log into MySQL as root:


4. Flush the privileges and then grant them:

Code:
@ 'localhost'
WITH GRANT OPTION;

5. Set a new root password:

Code:
@ 'localhost'
IDENTIFIED BY 'your_new_password';

6. Restart the MySQL service for normal operation:


Be sure to replace 'your_new_password' with a secure password. This has resolved my issue and root now has full privileges as expected. Thanks for the assist, techwiz84.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)