在mysql的配置文件中的[mysqld]下添加skip-grant-tables
[mysqld] skip-grant-tables #此处添加 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock
然后重启mysql就无需密码登录了!
登录mysql执行update mysql.user set authentication_string=password('密码') where user='root';
[root@zabbix-monit opt]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 45 Server version: 5.7.24 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> update mysql.user set authentication_string=password('hellowin') where user='root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1
如上,密码被修改为hellowin,然后再去掉或者注视掉mysql配置文件skip-grant-tables参数
重启服务即可!
其他:
如果新安装的mysql第一次修改密码登录后,输入命令提示重置密码,则执行如下命令即可!
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
step 1: SET PASSWORD = PASSWORD('密码');
step 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
step 3: flush privileges;
转载请注明:梦绘设计 » 数据库 » mysql5.7忘记root密码(修改)
版权声明
本站《作品展示》类文章均为原创,转载必须注明出处,技术分享类文章部分来源于网络,版权归原作者所有,若侵权请留言。