我們使用MySQL時,有時會忘記密碼,可以通過如下方式將密碼進行重置。
[root@localhost ~]# /etc/init.d/mysqld stop 停止MySQL服務
Stopping mysqld: [ OK ]
[root@localhost ~]# mysqld_safe --skip-grant-tables & 使用安全模式進入
[1] 13694
[root@localhost ~]# 180316 00:57:08 mysqld_safe Logging to '/var/log/mysqld.log'.
180316 00:57:08 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
mysql 輸入mysql 命令連接數(shù)據庫
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.38 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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 user set password = password("123456") where user = 'root'; 重置root密碼
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
重啟mysql服務器段化,使用新密碼就能登錄了。