拥有原来的用户名账户的密码
mysqladmin -u root -p password "test123"
Enter password: 【输入原来的密码】
忘记原来root密码
第一步:如果MySQL服务没有关闭,则关闭
service mysqld stop
第二步:在MySQL配置文件中增加忽略密码的配置,即在my.cnf中的[mysqld]下配置skip-grant-tables
vim /etc/my.cnf
如图,将:
第三步:开启MySQL服务
service mysqld start
第四步:进入MySQL数据库,不用输入密码,直接回车就行
mysql -u root -p
第五步:设置root用户密码
注意:代码中root_password就是新设置的密码
use mysql;
update mysql.user set authentication_string=password('root_password') where user='root';
第六步:退出MySQL,关闭MySQL服务,将my.cnf中的skip-grant-tables注释
关闭MySQL服务
service mysqld stop
注释skip-grant-tables,如图
启动MySQL服务
service mysqld start