linux系統
1,在Linux,先進入/etc,修改my.cnf,任意一行加上"skip-grant-tables"。
2,重啓MySQL:service mysqld restart
3,use mysql;
update mysql.user set authentication_string=password(‘your new password’) where user=‘root’;
4,flush privileges;
exit;
5,重啓MySQL:service mysqld restart (這步可以省略)
windows系統
版本是5.7
1、默認安裝地址:C:\ProgramData\MySQL\MySQL Server 5.7
2、打開my.ini,在mysqld下面加上 skip-grant-tables
表示不用密碼就可以登錄。
3、打開電腦的服務,重啓MySQL服務。
4、進入MySQL命令行
不用輸入密碼,直接進入
5、use mysql;
update mysql.user set authentication_string=password(‘your new password’) where user=‘root’;
flush privileges;
6、再回到my.ini,給skip-grant-tables加上“#”,表示註釋掉。
7、重啓MySQL服務,即可。