Enter password: #此行输入.mysql_secret里第二行内容
官方的方法,笔者无论是否应用--skip-grant-tables启动mysql都测试掉败,亲们可以测试:
- [root@www.woai.it ~]# service mysql stop
旧版本,安装后ROOT无暗码,按如下操作:
办法一:
- shell>service mysqld stop #停止mysql办事
- shell>mysqld_safe --skip-grant-tables & #以不启用grant-tables模式启动mysql
- shell>mysql -uroot -p #输入敕令回车进入,出现输入暗码提示直接回车。
- mysql>use mysql;
- mysql>update user set password=PASSWORD("123456")where user="root"; #更改暗码为 newpassord
- mysql>flush privileges; #更新权限
- mysql>quit #退出
办法二:
- shell>service mysqld stop #停止mysql办事
- shell>mysqld_safe --skip-grant-tables & #以不启用grant-tables模式启动mysql
- shell>mysql -uroot -p #输入敕令回车进入,出现输入暗码提示直接回车。
- mysql > set password for root@localhost = password('mysqlroot');
办法三:
- shell>/path/mysqladmin -u UserName -h Host password 'new_password' -p
参考:http://www.jb51.net/article/77858.htm
忘记mysql root用户暗码的解决办法(skip-grant-tables)
skip-grant-tables
顾名思义,数据库启动的时刻 跳跃权限表的限制,不消验证暗码,直接登录。
留意:
这种情况只有在忘记root暗码 不得已重启数据库的情况下应用的。现网情坑字擅,须要重启数据库,并且安然性也比较难以包管。
*特别提示留意的一点是,新版的mysql数据库下的user表中已经没有Password字段了
/etc/my.cnf
1.修改设备参数
[mysqld] 下面加上:
skip-grant-tables
设备项。
2.重启MySQL
使得参数生效:
service mysqld restart
3.留意事项
此时所有效户登录当前数据库都是免暗码的,所以此时数据库的安然性是异常低的。
4.修改暗码
具体的办法:
参考以上介绍
5.去掉落参数
a.暗码修改好了之后再将设备文件中 skip-grant-tables去掉落
- shell>mysql -uroot -p'password' #password即.mysql_secret里的暗码
- mysql>SET PASSWORD = PASSWORD('newpasswd');
b.再次重启数据库。
【编辑推荐】
- MySQL与PostgreSQL比拟哪个更好?
- 微信开源PhxSQL:高可用、强一致的MySQL集群
推荐阅读
作者:邓凯“他们须要大年夜数据中找到有效的┞锋相,然后解释给引导者。” – Rchard Snee Emc今天这个标题有点大年夜,内容可能涉及的比较多,但也是数据君多年来一向想>>>详细阅读
本文标题:Mysql5.7忘记root密码及mysql5.7修改root密码的方法
地址:http://www.17bianji.com/lsqh/34772.html
1/2 1