MySQL 忘记密码该怎么办?如何修改密码?
如果忘记root密码或其他用户密码,不要急,按下面操作即可。
- 编辑mysql主配置文件 my.cnf
vim /etc/my.cnf
在[mysqld]字段下添加参数 skip-grant
- 重启数据库服务
service mysqld restart - 这样就可以进入数据库不用授权了
mysql -uroot - 修改相应用户密码
**use mysql;
update user set password=password('your password') where user='root';
flush privileges;** - 修改/etc/my.cnf 去掉 skip-grant , 重启mysql服务
下面的操作可能更简单,但思路是一样的
bash> service mysqld stop
bash> mysqld --skip-grant-tables &
bash> mysql -u root
mysql> use mysql;
mysql> set password for 'root'@'localhost' = password('hello123');
mysql> flush privileges;