1. 程式人生 > >Linux環境下java開發環境搭建四 mysql密碼忘記找回

Linux環境下java開發環境搭建四 mysql密碼忘記找回

pri 配置 tables edi ant ngs oca 登錄mysql tor

第一步:在/etc/my.cnf配置文件中加入skip-grant-tables

[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-storage-engine=InnoDB
innodb-file-per-table=1
character_set_server=utf8mb4

skip
-grant-tables [mysqld_safe] [client] default-character-set=utf8mb4

第二步:重啟mysql

[[email protected]lave1 mysql]# service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 

第三步:不使用密碼直接登錄mysql,然後修改mysql.user表中的authentication_string字段的值

在mysql 5.7之前,mysql數據庫用戶的密碼的字段是password,5.7之後變成了authentication_string

mysql> update mysql.user set authentication_string=password(123456) where user=root and host=localhost;
Query OK, 1 row affected, 1 warning (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> \q

註意一定要執行flush privileges;不然不會生效,重置完密碼之後,要把my.cnf配置文件中的skip-grant-tables註釋到

Linux環境下java開發環境搭建四 mysql密碼忘記找回