MySQL 5.5 5.6修改方法
/etc/init.d/mysql stop
/etc/init.d/mysql start --skip-grant-table #忽略授权表启动
mysql -uroot
update mysql.user set password=PASSWORD("6") where User='root' and host='localhost';
mysql> flush privileges;
多实例修改忘记root密码方法
mysqladmin -uroot -p222222 -S /data/3306/mysql.sock shutdown
mysqld_safe --defaults-file=/data/3306/my.cnf --skip-grant-table &
mysql -uroot -S /data/3306/mysql.sock
update mysql.user set password=PASSWORD(“222222”) where User=‘root’ and host=‘localhost’;
cd /data/3306/
./mysql start
mysql -uroot -p222222 -S /data/3306/mysql.sock
MySQL 5.7 修改方法
/etc/init.d/mysqld stop
mysqld_safe --skip-grant-tables --skip-networking &
注:–skip-grant-tables 忽略授权表
–skip-networking 禁止远程网络连接(可以不加这个参数)
登录并修改
mysql
flush privileges;
alter user root@'localhost' identified by '1';
或
grant all on *.* to root@'localhost' identified by '2';
注:因为MySQL密码字段已经不是password 变成了authentication_string
所以也可以按照5.6的方法来该
update mysql.user set authentication_string=PASSWORD("3") where user='root' and host='localhost';