環境:
問題:
安裝過程中沒有提示設定密碼。
解決步驟:
1. 修改
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
2. 在[mysqld]中加入skip-grant-tables,之後重新開機mysql。
3. mysql -uroot -p,如果提示輸入密碼直接回車即可。進入mysql後執行:
use mysql;
update user set authentication_string=password("你的密碼") where user="root";
flush privileges;
4. 退出mysql,在/etc/mysql/mysql.conf.d/mysqld.cnf中删除skip-grant-tables,之後重新開機mysql即可進入。
5. 若提示:
再執行第一步,進入mysql,執行:
可以看到root 的plugin字段是auth_socket,這裡更改為mysql_native_password就可以使用密碼。
執行:
update user set authentication_string=password("djw1234"),plugin='mysql_native_password' where user='root';
然後檢視:
最後再去除mysqld.cnf中的skip-grant-tables,儲存後重新開機mysql就可使用密碼登入。