windows
1.在DOS窗口下输入net stop mysql 停掉服务器(或者通过进程)
2.mysqld --skip-grant-tables;
3。
update mysql.user set authentication_string=password('root') where user='root' ;
update user set password_expired='N' where user='root';
flush privileges;
quit
4.重新登录
linux
vi /etc/my.cnf
[mysqld]下面加上 skip-grant-tables
mysql -uroot -p
mysql> use mysql;
mysql> update user set password=password('123') where user='root';
mysql> flush privileges;
退出mysql
删除skip-grant-tables
重启mysql,完成。