1

While trying to navigate or learn more about users in mysql phpmyadmin I accidentally removed the PRIVILEGES of the user root. Now i cant create new database, new user, etc. How can I restore the PRIVILEGES to user root again

  1. What I wanted to do when I made my mistake is to create a sole user for one of my database.I wanted to remove the PRIVILEGES of root for that specific database only and not for everything. It seems that I remove the PRIVILEGES of root for the entire mysql.

Tried

USE mysql;
UPDATE user SET Grant_priv='1' WHERE User='root';
FLUSH PRIVILEGES;

Getting

Error SQL query:

USE mysql;

MySQL said: Documentation

1044 - Access denied for user 'root'@'localhost' to database 'mysql'

Tried

UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
FLUSH PRIVILEGES;
GRANT ALL ON *.* TO 'root'@'localhost';

Getting

Error SQL query:

UPDATE mysql.user SET Grant_priv = 'Y', Super_priv = 'Y' WHERE User = 'root';

MySQL said: Documentation

1142 - UPDATE command denied to user 'root'@'localhost' for table 'user'

UPDATE

I tried creating new user

CREATE USER 'user'@'localhost' IDENTIFIED BY 'user';

and i get this error

1227 - Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation

tried

GRANT ALL PRIVILEGES ON * . * TO 'root'@'localhost' IDENTIFIED BY 'qwe';

getting

1045 - Access denied for user 'root'@'localhost' (using password: YES)

Any idea is appreciated.

2 Answers 2

2

If you've deleted your root user by mistake you can do one thing:

  1. Stop MySQL service
  2. Run mysqld_safe --skip-grant-tables &
  3. Type mysql -u root -p and press enter.
  4. Enter your password
  5. At the mysql command line enter: use mysql; Then execute this query:

     INSERT into user (`Host`, `User`, `Password`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`) values('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','','0','0','0','0');
    

then restart the mysqld

2
  • how do i start the mysql service?do i do it in cmd?i am using windows.if in cmd how can i run the mysqld_safe?sorry very new to database. I think i didnt not delete the root..i just removed the privileges. because i can see that i am currently log in as root
    – guradio
    Dec 13, 2015 at 6:16
  • in windows , go to Services,there you will find list of services with their status. Go to MySql Right click and click on Stop.
    – Naruto
    Dec 13, 2015 at 6:37
0

For MariaDB 5.5.56 and perhaps others, the command needs to be:

INSERT into user (`Host`, `User`, `Password`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`) values('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','','0','0','0','0');

Adding Event_priv, Trigger_priv and Create_tablespace_priv.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.