Monday, January 11, 2016

Reset mysql root password | bash: mysqld_safe: command not found

Installed new mysql-server (like i did mysql  Ver 14.14 Distrib 5.7.10) and forgot the root password for mysql. here are tried steps to get your access back.

[root@buggzbox amit] systemctl stop mysqld
[root@buggzbox amit] systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
[root@buggzbox amit] systemctl start mysqld
[root@buggzbox amit] mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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('newpassword') WHERE User = 'root' AND Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye
[root@buggzbox amit]# systemctl stop mysqld;
[root@buggzbox amit]# systemctl unset-environment MYSQLD_OPTS
[root@buggzbox amit]# systemctl start mysqld
[root@buggzbox amit]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10

Copyright (c) 2000, 2015, 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> ^DBye
[root@buggzbox amit]#

No comments:

Post a Comment