由於mysql更新較快,8.0對比5.7很多操作有了變化,特別修改密碼,和忘記密碼這一塊已經和以前完全不一樣了。
一、 忘記密碼
1、 在my.cnf 文件中添加skip-grant-tables,然后systemctl restart mysqld
2、 直接mysql 登錄,此時不需要填寫密碼。
3、 update mysql.user set authentication_string=’’ where user=’root’ 清空root用戶密碼。
4、 注釋掉skip-grant-tables,重啟mysql
5、 mysql -uroot 無密碼登錄到root模式。
6、 select user,host from user where user='root';
7、 alter user ‘root@’localhost’ identified by ‘password’;
8、 flush privileges; 刷新權限
二、 修改密碼
見上邊第7步
三、 遠程登錄
1、 select user,host from mysql.user where user='user'; 查找用戶名的登錄狀態
2、 修改host登錄主機update mysql.user set host='%' where user='root';
%:表示所有主機可以登錄,可以更改為ip地址
3、 查看權限
4、 flush privileges; 刷新權限