Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all privileges back to the root user in MySQL?

I have logged in to MySQL with the --skip-grant-tables option. But I don't know how to get all privileges back to the root user.

I tried:

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

MySQL said:

# 1290 - The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

Trying:

GRANT ALL PRIVILEGES ON * . * TO 'root'@'localhost'
WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0
MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

MySQL said:

# 1290 - The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
like image 601
Steven Avatar asked Nov 11 '09 03:11

Steven


People also ask

How do I show all privileges in MySQL?

Answer: In MySQL, you can use the SHOW GRANTS command to display all grant information for a user. This would display privileges that were assigned to the user using the GRANT command.

How do I flush user privileges in MySQL?

To tell the server to reload the grant tables, perform a flush-privileges operation. This can be done by issuing a FLUSH PRIVILEGES statement or by executing a mysqladmin flush-privileges or mysqladmin reload command.


1 Answers

For mysql 8.0.12+
I've tried the documentation (not working) I've tried various other options, all failed.

PASSWORD() is deprecated, SET PASSWORD is disabled, ALTER USER is disabled as well.

  1. stop mysql service
  2. Start it this way: /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
  3. Login (mysql) and exec: update user set authentication_string='' where User='root';
  4. killall mysqld
  5. Start service again

Now you can use set password or alter user after logging in without a password

like image 107
John Avatar answered Oct 19 '22 04:10

John