deepin15.7下使用apt安裝mysql5.7不顯示root密碼設定的解決方法
阿新 • • 發佈:2018-11-08
在安裝MySQL的過程中,並沒有要求設定root賬戶密碼的步驟,導致很多人無法使用root賬戶登入
這個問題早已有解決方案,筆者在deepin15.7下安裝也遇到同樣問題,只是做一個簡單的記錄
解決思路
在安裝mysql-server
的時候,其實會自動設定一個賬戶在系統中,即儲存在/etc/mysql/debian.conf
檔案中。
另外,MySQL的賬戶資訊其實儲存在一個叫mysql
的資料庫的user
表中。
這樣我們可以先登入預設的賬戶,然後修改user
表中的root賬戶資訊即可。
具體步驟
檢視預設賬戶資訊
cat /etc/mysql/debian.conf
結果如下
[client] host = localhost user = debian-sys-maint password = password socket = /var/run/mysqld/mysqld.sock
其中[user]和[password]就是預設的賬戶
登入mysql,修改user表資訊
一般安裝後資料庫會自動啟動,如果沒有service start mysql
即可
執行以下指令
mysql -u debian-sys-maint -p
use mysql;
update user set authentication_string=password("cus_defined_pass") where user='root';
update user set plugin="mysql_native_password";
flush privileges;
之後重啟,service mysql restart
root:cus_defined_pass
登入即可