- 关闭mysqld
1
ps aux | grep mysqld | grep -v grep | awk '{print $2}' | xargs kill -9
- 修改my.conf
1
2
3vim /etc/my.conf
# 找到[mysqld]这个section,添加skip-grant-tables,意思是忽略所有表的授权
skip-grant-tables - 开启mysqld服务
1
mysqld &
- 进入mysql
1
2
3
4
5mysql -u root
mysql> use mysql;
mysql> update mysql.user set authentication_string=password('new password') where user='root';
mysql> flush privileges;
mysql> exit; - 撤回skip-grant-tables
1
2vim /etc/my.conf
# 找到[mysqld]这个section,注释掉skip-grant-tables - 重启mysqld
1
2ps aux | grep mysqld | grep -v grep | awk '{print $2}' | xargs kill -9
mysqld & - 密码登录mysql
1
2mysql -uroot -p
#输入刚配置的新密码