1、修改配置文件:vim /etc/my.cnf
添加 skip-grant-tables
#跳过数据库权限验证
保存退出:wq
2、重启mysql:service mysq restart
#看你的服务名是哈 ?有的是mysqlid
3、免密登录:./mysql -u root
#有的是不加 ./
进入数据库:use mysql
4、修改root
密码:
update user set authentication_string = password('新密码'),password_last_changed=now() where user='root';
退出mysql
数据库:quit
5、再次修改配置文件:vi /etc/my.cnf
删除skip-grant-tables
保存退出
重启mysql
服务即可