MySQL5.7和8.0
方法一
update mysql.user set authentication_string=password('123456') where host='localhost' and user='root';方法二
skip-grant-tables
mysql -S /var/lib/mysql/mysql.sock
flush privileges;
alter user 'root'@'localhost' identified by '123456';MySQL5.6
update mysql.user set password=password('123456') where host='localhost' and user='root';通过启动脚本的方法
service mysqld restart --init-file=/usr/local/mysql57/init.sq
bin/mysqld_safe --defaults-file=my.cnf --init-file=/usr/local/mysql57/init.sql &
init.sql内容:alter user 'root'@'localhost' identified by '123456';
还不快抢沙发