Thursday, January 30, 2020

How to re-take control of the root user in MySQL ? How to start MySQL with --skip-grant-tables ?

How to re-take control of the root user in MySQL.
DANGER: RISKY OPERATION
  • Start session ssh (using root if possible).
  • Edit my.cnf file using.
    sudo vi /etc/my.cnf
  • Add a 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 the mysql 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 the database.
    mysql -u root -p
  • Type a 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.

No comments:

Post a Comment