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; //刷新數據庫