1. 程式人生 > 實用技巧 >mysql 5.7密碼修改

mysql 5.7密碼修改

官網下載安裝包:https://dev.mysql.com/downloads/mysql/

一、停止mysqld服務

二、編輯配置檔案

有的Linux版本是/etc/my.cnf
有的Linux版本是/etc/mysql/mysql.conf.d/mysqld.cnf
windows配置檔名字為my.INI

# 在配置檔案中新增配置項 [mysqld] skip-grant-tables

三、重新啟動mysqld服務並登陸

systemctl restart mysqld

mysql -u root -p 

四、修改root密碼

# 注意,user表沒有“password”欄位了,取代的是“authentication_string”。
update mysql.user set authentication_string=password('123456') where User='root' and Host='localhost'; #上面密碼是不可取的!會在後續操作中遇到如下提示: ERROR 1819 (HY000) at line 1: Your password does not satisfy the current policy requirements 請設定一個稍微複雜的密碼吧!例如【大寫字母+小寫字母+特殊字元+數字】。

五、重新整理配置

flush privileges;

# 去掉skip-grant-tables配置項
因為這一配置項的意思是“跳過許可權表的限制,不用密碼驗證,直接登入”,在生產環境中是絕對不行的。 再次執行mysql命令需要密碼了。

轉自:https://www.cnblogs.com/yoyotl/p/6387207.html