Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start MySQL with --skip-grant-tables?

I locked my root user out from our database. I need to get all privileges back to the root user. I have my password and I can log in to MySQL. But the root user has no all privileges.

like image 674
Steven Avatar asked Nov 10 '09 14:11

Steven


People also ask

How do I start MySQL with Skip grant tables Ubuntu?

The easiest method would be to temporarily modify /etc/init. d/mysql to include the option --skip-grant-tables and then start it with this script (/etc/init. d/mysql start). On upstart systems like Ubuntu 16.04 this needs to be done in /lib/systemd/system/mysql.

How do I stop Skip grant tables?

Using --skip-grant-tables In this method, you stop the server and start it by specifying --skip-grant-tables , which will not load the grant tables.

How do I start Mysqld as root?

To ensure this, run mysqld_safe as root and include the --user option as shown. Otherwise, you should execute the program while logged in as mysql , in which case you can omit the --user option from the command.


2 Answers

I had the same problem as the title of this question, so incase anyone else googles upon this question and wants to start MySql in 'skip-grant-tables' mode on Windows, here is what I did.

Stop the MySQL service through Administrator tools, Services.

Modify the my.ini configuration file (assuming default paths)

C:\Program Files\MySQL\MySQL Server 5.5\my.ini 

or for MySQL version >= 5.6

C:\ProgramData\MySQL\MySQL Server 5.6\my.ini  

In the SERVER SECTION, under [mysqld], add the following line:

skip-grant-tables 

so that you have

# SERVER SECTION # ---------------------------------------------------------------------- # # The following options will be read by the MySQL Server. Make sure that # you have installed the server correctly (see above) so it reads this  # file. # [mysqld]  skip-grant-tables 

Start the service again and you should be able to log into your database without a password.

like image 185
tonycoupland Avatar answered Sep 19 '22 17:09

tonycoupland


How to re-take control of the root user in MySQL.

DANGER: RISKY OPERATTION

  • Start session ssh (using root if possible).
  • Edit my.cnf file using.

    sudo vi /etc/my.cnf 
  • Add line to mysqld block.*

    skip-grant-tables 
  • Save and exit.

  • Restart MySQL service.

    service mysql restart 
  • Check service status.

    service mysql status 
  • Connect to mysql.

    mysql 
  • Using main database.

    use mysql; 
  • Redefine user root password.

    UPDATE user SET `authentication_string` = PASSWORD('myNuevoPassword') WHERE `User` = 'root';  
  • Edit file my.cnf.

    sudo vi /etc/my.cnf 
  • Erase line.

    skip-grant-tables 
  • Save and exit.

  • Restart MySQL service.

    service mysqld restart 
  • Check service status.

    service mysql status 
  • Connect to database.

    mysql -u root -p 
  • Type new password when prompted.

This action is very dangerous, it allows anyone to connect to all databases with no restriction without a user and password. It must be used carefully and must be reverted quickly to avoid risks.

like image 38
gizmo_marco Avatar answered Sep 21 '22 17:09

gizmo_marco