How to reset mysql 5.7 root password from command line
MySQL version
[msteam@dbbackup ~]$ mysql -V
mysql Ver 14.14 Distrib 5.7.15, for Linux (x86_64) using EditLine wrapper
[msteam@dbbackup ~]$
Check status and stop mysql service
[msteam@dbbackup ~]$ sudo service mysqld status
mysqld (pid 29946) is running...
[msteam@dbbackup ~]$
[msteam@dbbackup ~]$ sudo service mysqld stop
Stopping mysqld: [ OK ]
[msteam@dbbackup ~]$
[msteam@dbbackup ~]$ sudo service mysqld status
mysqld is stopped
Start mysql service with skipping grant table
[msteam@dbbackup ~]$ sudo mysqld_safe --skip-grant-tables &
[1] 27503
[msteam@dbbackup ~]$ 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
[msteam@dbbackup ~]$
Enter to mysql and change the root password
[msteam@dbbackup ~]$ 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
[msteam@dbbackup ~]$
Restart mysql service
[msteam@dbbackup ~]$ 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
[msteam@dbbackup ~]$
Trying login to mysql without password to make sure our grant table not skipping
[msteam@dbbackup ~]$ mysql
ERROR 1045 (28000): Access denied for user 'msteam'@'localhost' (using password: NO)
[msteam@dbbackup ~]$
Enter to mysql using new root password that we set before
[msteam@dbbackup ~]$ 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