1. 程式人生 > 資料庫 >解決MySQL不需要密碼就能登入問題

解決MySQL不需要密碼就能登入問題

因為執行了一個更改資料庫root使用者密碼的命令,當我更改完後,發現用我新密碼和舊密碼都能登陸,於是感覺沒有輸密碼,直接回車就能登入,而我在配置中也沒有進行免密碼登陸的操作,最後,執行了一條命令解決update user set plugin = "mysql_native_password";

修改密碼及解決無密碼登陸問題都在下面命令中:

> use mysql;

> update user set authentication_string=password("你的密碼") where user='root';  #(無password欄位的版本,也就是版本<=5.7的)
> update user set password=password('你的密碼') where user='root'; #(有password欄位的版本,版本>5.7的)

> update user set plugin="mysql_native_password"; 

> flush privileges;

> exit;

重啟mysql服務