How to reset mysql 5.7 root password from command line
MySQL version
[[email protected] ~]$ mysql -V
mysql Ver 14.14 Distrib 5.7.15, for Linux (x86_64) using EditLine wrapper
[[email protected] ~]$
Check status and stop mysql service
[[email protected] ~]$ sudo service mysqld status
mysqld (pid 29946) is running...
[[email protected] ~]$
[[email protected] ~]$ sudo service mysqld stop
Stopping mysqld: [ OK ]
[[email protected] ~]$
[[email protected] ~]$ sudo service mysqld status
mysqld is stopped
Start mysql service with skipping grant table
[[email protected] ~]$ sudo mysqld_safe --skip-grant-tables &
[1] 27503
[[email protected] ~]$ 2018-09-24T10:22:18.602519Z mysqld_safe Logging to '/var/log/mysqld.log'.
2018-09-24T10:22:18.641748Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[[email protected] ~]$
Enter to mysql and change the root password
[[email protected] ~]$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 5.7.15 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('NewPassword') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> quit;
Bye
[[email protected] ~]$
Restart mysql service
[[email protected] ~]$ sudo service mysqld restart
[sudo] password for msteam:
2018-09-24T10:29:47.899437Z mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
[1]+ Done sudo mysqld_safe --skip-grant-tables
[[email protected] ~]$
Trying login to mysql without password to make sure our grant table not skipping
[[email protected] ~]$ mysql
ERROR 1045 (28000): Access denied for user 'msteam'@'localhost' (using password: NO)
[[email protected] ~]$
Enter to mysql using new root password that we set before
[[email protected] ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.15 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>
Tidak ada komentar :
Posting Komentar