安裝完MySQL后,使用sudo grep 'temporary password' /var/log/mysqld.log查看初始密碼,No such file or directory,找了很多方法修改密碼都不能修改成功,最后找到一個簡單粗暴的方法
1、創建一個新用戶
CREATE USER 'root'@'%' IDENTIFIED BY '你的密碼'; GRANT ALL ON *.* TO 'root'@'%'; ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密碼';
2、創建完成后刷新
FLUSH PRIVILEGES;
3、刪除掉多余的沒有密碼的用戶
select host,user,authentication_string from user;
確認查詢出來的列表是存在兩個user為root的用戶,host分別為localhost和上面的新建的%,刪除user為root,host為localhost的用戶數據
delete from user where host='localhost' and user = 'root';
4、退出之后再重新使用密碼登錄
exit; mysql -uroot -p 輸入自己設置的密碼即可登錄