MySQL - Change the root password

MySQL – Change the root password


#MySQL #Change #root #password

In MySQL, it is always useful to change your administrator password (root user) either at the time of the first installation or after losing your password. In this article, see the options you have for resetting the administrator password.


Loss of MySQL root password

In order to change the MySQL root password, you must still be able to connect to the account. However, if you do not have the current root password, the problem will be greater.

Skip the authentication step

You can connect to MySQL by skipping the authentication phase. First, stop the MySQL server with the following command:

 #/etc/init.d/mysql stop

Then, restart MySQL by overriding identification and disabling network listening to avoid being hacked when MySQL is vulnerable:

 #mysqld --skip-grant-tables - skip-networking &

Reset the MySQL password

Once the previous step has been performed, or if you just want to change your root password, connect to the database MySQL system with the command below:

# mysql mysql -u root

Then enter the command to update the root password (obviously, replacing the new password with yours):

 UPDATE user SET password=PASSWORD ('novasenha') WHERE user="root";

If you have not gone through the first step, just enter this command for the changes to be taken into account:

FLUSH PRIVILEGES;

If, however, you started MYSQL manually in degraded mode, just restart the server as follows:

#/etc/init.d/mysql restart

Photo: © Everypixel

Related Posts