MySQL5.7忘记root密码的处理方式


本篇内容主要讲解“MySQL5.7忘记root密码的处理方式”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“MySQL5.7忘记root密码的处理方式”吧!
MySQL忘记root密码,而且不能使用操作系统认证直接进入数据库修改密码时,需要重置root密码。
1、在配置文件/etc/my.cnf添加skip-grant-tables一行,跳过密码验证。
2、重启mysql数据库主进程# /etc/init.d/mysqld restart(也可以直接先停掉MySQL进程后使用skip-grant-tables参数重启MySQL)
3、登录数据库修改密码。
mysql> update user set authentication_string=password(”) where user=’root’ and host=’localhost’;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> exit
这里需要修改的字段是authentication_string,这点和之前的版本不同。
4、这个时候,如果你设置的密码太简单,则在数据库执行任何命令都会报类似如下错误:
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘database’ at line 1
mysql> update user set authentication_string=password(‘mysql’) where user=’root’ and host=’localhost’;
ERROR 1046 (3D000): No database selected
mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
5、注意:如果只想设置简单密码需要修改两个全局参数:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> set password=password(“mysql”);
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with开发云主机域名 -A

Database changed
————————-End————————————————————————–到此,相信大家对“MySQL5.7忘记root密码的处理方式”有了更深的了解,不妨来实际操作一番吧!这里是开发云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

相关推荐: MySQL数据库执行analyze采集信息的示例

这篇文章给大家分享的是有关MySQL数据库执行analyze采集信息的示例的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。之前,有开发找到我,说应用的某个功能查询比以前慢了很多,让开发提供了慢的SQL语句,去对应的MySQL数据库看了…

免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 06/21 17:45
下一篇 06/21 17:45

相关推荐