mysql重置root密码

前提:centos7、mysql5.7

1.停止mysql服务
systemctl stop mysqld.service

2.修改配置文件无密码登录
vim /etc/my.cnf
在最后加上
skip-grant-tables
保存
3.启动mysql
systemctl start mysqld.service

4.登录mysql
mysql -u root
注意这里不要加-p
5.修改密码,mysql5.7用此语法
use mysql;
update mysql.user set authentication_string=password('123456') where user='root' ;
6.回到第二部把刚加的那句删掉
保存,重启mysql就可以了

修改密码
set password=password('root@123QWE');
use mysql;
create user 'admin'@'%' identified by '123456';
grant all privileges on *.* to 'admin'@'%';

flush privileges;

做一个决定,并不难,难的是付诸行动,并且坚持到底。
原文地址:https://www.cnblogs.com/wukc/p/13236140.html