CentOS下Mysql密碼忘了如何重置
阿新 • • 發佈:2018-11-01
- 系統版本
[[email protected] sbin]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
- Mysql版本
[[email protected] sbin]# mysql -V
mysql Ver 14.14 Distrib 5.7.23, for Linux (x86_64) using EditLine wrapper
- 修改/etc/my.cnf檔案
[[email protected] sbin]# vi /etc/my.cnf
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables #新增此行
- 重啟mysql
[[email protected] sbin]# systemctl restart mysqld
- 重設Mysql密碼
[[email protected] sbin]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.23 MySQL Community Server ( GPL)
Copyright (c) 2000, 2018, 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> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> UPDATE user SET Password = password ( 'Qwert123!' ) WHERE User = 'root';
ERROR 1054 (42S22): Unknown column 'Password' in 'field list'
#報錯了,阿西吧。錯誤的原因是 5.7版本下的mysql資料庫下已經沒有password這個欄位了,password欄位改成了authentication_string
mysql> update mysql.user set authentication_string=password('Qwert123!') where user='root';
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> exit
Bye
[[email protected] sbin]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.23 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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> exit
Bye
[[email protected] sbin]# vi /etc/my.cnf
skip-grant-tables #將剛才新增的此行再刪除