重置mysql数据库root密码

时间:2022-03-08 22:23:39

一、 在已知MYSQL数据库的ROOT用户密码的情况下,修改密码的方法:
1,shell环境下:
]#mysqladmin –u root –p password “新密码” 回车后要求输入旧密码
2,mysql>环境下:
2.1

mysql>Update mysql.user  set  password=password(‘新密码’)  where  user=’root’ and host='localhost';
mysql>flush privileges;

2.2
mysql>grant all on *.* to root@’localhost’ identified by ‘新密码’;

二、 如查忘记了mysql数据库的ROOT用户的密码:

]#systemctl stop mysqld
]#vim /etc/my.cnf // [mysqld]下面添加skip-grant-table(修改完后在注释)
]#systemctl restart mysqld
]#mysql -u root
Mysql> update mysql.user set password=password(‘新密码’) where
user="root" and host="localhost";
Mysql> flush privileges;
]#vim /etc/my.cnf // [mysqld]下面注销skip-grant-table
]#systemctl restart mysqld