MySQL密码相关操作
时间:2022-03-13 22:53
MySQL密码忘记了,操作步骤:
1、service mysqld stop
2、vim /etc/my.cnf #编辑MySQL配置文件,找到[mysqld],在下面添加一行skip-grant-tables
3、mysql -u root -p直接进入MySQL控制台
4、update mysql.user set password=password(‘MySQL新密码‘) where User="root" and Host="localhost";
flush privileges; #刷新系统授权表
grant all on *.* to ‘root‘@‘localhost‘ identified by ‘MySQL新密码‘ with grant option;
5、取消/etc/my.cnf中的siop-grant-tables
service mysqld stop
vi /etc/my.cnf
删除skip-grant-tables行
保存退出
6、service mysqld start
为mysql添加用户:
insert into mysql.user (host,user,password) values (‘localhost‘,‘cacti‘,password (‘cacti123‘));
flush privileges;
更改MySQLroot用户的密码:
mysql> update user set password=password(”xxxxxxxxxx″) where user=‘root’;
mysql> flush privileges; //刷新数据库
MySQL密码相关操作,布布扣,bubuko.com