删除root用户
drop user root@'localhost';
停止Mysql
service mysql stop
进入安全模式
mysqld_safe --skip-grant-tables --skip-networking &
添加用户并修改密码
INSERT INTO user SET User='root',Host='localhost',ssl_cipher='',x509_issuer='',x509_subject=''; update user set password=password("654321") where user="root";
或
insert into user(user,host,password,ssl_type,ssl_cipher,x509_issuer,x509_subject) values('root','localhost',PASSWORD('123'),'','','','');
mysql重新启动
service mysql stop
service mysql start
忘记密码
5.6以前版本 update mysql.user set password=PASSWORD('123') where user='oldboy' and host='10.0.0.%'; flush privileges; 5.7版本 update mysql.user set authentication_string=PASSWORD('123') where user='oldboy' and host='10.0.0.%';