一橙垢、更改my.cnf配置文件
1、用命令編輯my.cnf配置文件伦糯,即:
vim /etc/my.cnf
vi /etc/my.cnf
nano /etc/my.cnf
2钢悲、在[mysqld]下添加skip-grant-tables,然后保存并退出
skip-grant-tables
mysql配置.jpg
3舔株、重啟mysql服務(wù):service mysqld restart
service mysqld restart
二、修改密碼
1还棱、重啟以后载慈,執(zhí)行mysql -uroot -p(不需要密碼直接Enter)進(jìn)入mysql命令行
mysql -uroot -p
進(jìn)入mysql命令行.jpg
2、sql語句修改密碼并執(zhí)行退出mysql
注意:如果執(zhí)行修改密碼命令報錯珍手,執(zhí)行后報錯 ERROR 1054(42S22) Unknown column 'password' in ‘field list’ 錯誤的原因是 5.7版本下的mysql數(shù)據(jù)庫下沒有password這個字段办铡,password字段改成了authentication_string
mysql> update user set password=password("*******") where user="*******"; #修改密碼報錯
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> update mysql.user set authentication_string=password('*******') where user='*******'; #修改密碼成功
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.00 sec)
mysql> quit #退出mysql -- 也可以使用 exit;命令
Bye
3辞做、重新執(zhí)行vim /etc/my.cnf,然后刪除剛剛加入的 skip-grant-tables寡具,重新啟動mysql