There are many ways recovering or resetting MySQL root password but the one i like & follow is below procedure,
1) Update MySQL configuration file to add "skip-grant-tables"(without quotes) under [mysqld] section. When the server is restarted this option causes the MySQL service / process to start without using the privilege system at all, which gives anyone with access to the server unrestricted access to all databases.
2) Now restart MySQL process / service issuing following command.
$ sudo systemctl restart mysqld
3) Once the server is restarted you can change the password of the root user issuing following command in sequence,
[siva@mysql ~]$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 Server version: 5.7.14 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> UPDATE mysql.user SET authentication_string=PASSWORD("xxxyyy") WHERE User='root';
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
4) Now, you have successfully updated the root password. You have to secure the MySQL access by removing "skip-grant-tables" from my.cnf file & restart MySQL service.5) Now you should be able to login to MySQL using updated root password.
6) But once you try to perform any operations it may throw below exception & solution follows, (here when you execute alter you may retain same passowrd or change the password based on your policy requirements)
mysql> select * from mysql.user where user="root"; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxyyyzzz'; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> exit
No comments:
Post a Comment