基本的思路是,以安全模式启动mysql,这样不须要密码能够直接以root身份登陆,而后重设密码。mysql
#先关闭mysql服务 service mysqld stop #安全模式启动mysql,加入--skip-networking 防止远程无密码登陆 mysqld_safe --skip-grant-tables --skip-networking & #无密码登陆 mysql -u root #修改密码 mysql> use mysql; mysql> update user set password=PASSWORD("mynewpassword") where User='root'; mysql> flush privileges; #执行完毕就退出,无需加分号 quit #重启mysql service mysqld restart #从新登陆便可 mysql -u root -p