停止mysql
service mysqld status 或者 service mysql status 命令来查看mysql 的启动状态
如果是启动状态,需要停止:
/etc/init.d/mysqld stop
去掉的登录验证
vi /etc/my.cnf
在[mysqld]下加入参数 skip-grant-tables=1
保存退出
启动mysql
/etc/init.d/mysqld start 或者 /etc/init.d/mysqld restart
修改密码
1、登录:mysql -uroot -p 直接回车 2、use mysql 3、查看表字段 show columns from user 4、如果有 password 字段,没有 authentication_string,就只需修改password字段;
update user set password=PASSWORD('123456') where User='root';1
5、如果有 authentication_string 字段,没有 password,就只需authentication_string字段;
update user set authentication_string=PASSWORD('123456') where User='root';1
6、如果两个都有,两个字段都要改
update user set password=PASSWORD('123456') where User='root';
update user set authentication_string=PASSWORD('123456') where User='root';1
2
2
7、刷新权限:flush privileges 8、还原登录验证:vi /etc/my.cnf;加个井号注释掉:# skip-grant-tables=1 9、登录,show databases 如果提示如下错误
You must reset your password using ALTER USER statement
before executing this statement.1
2
2
重新将密码设置一遍即可
set password = password ('newpassword');