1. 使用场景
解决新装mysql后不知道root密码
2. 跳过密码认证
修改mysql配置文件前先备份
vim /etc/my.cnf
[mysqld]
skip-grant-tables //在mysqld下添加一行
修改过配置文件后需要重启mysqld服务
systemctl restart mysqld // 重启mysqld服务
mysql //进入mysql
update mysql.user set password=password('root新密码') where user='root';
exit;
注释或者删除 /etc/my.cnf 中的 skip-grant-tables
vim /etc/my.cnf
[mysqld]
#skip-grant-tables
修改过配置文件后需要重启mysqld服务
systemctl restart mysqld // 重启mysqld服务
使用新密码登录
mysql -uroot -p'新密码'