资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

mysql8.0.11数据库用户密码修改诡异的限制

近期,协助一客户重置MySQL 8.0.11的root密码,碰到了奇怪的问题。

永定网站制作公司哪家好,找创新互联建站!从网页设计、网站建设、微信开发、APP开发、响应式网站等网站项目制作,到程序开发,运营维护。创新互联建站自2013年起到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联建站

    操作系统版本:rhel 7.6

    数据库版本:mysql 8.0.11

    根据mysql 8.0官方文档说明,mysql的用户密码有限制,并且被硬编码,没有明确说明密码长度是多少。

Warning

The MySQL user name length limit is hardcoded in MySQL servers and clients, and trying to circumvent it by modifying the definitions of the tables in the   mysql database   does not work.

You should never alter the structure of tables in the   mysql database in any manner whatsoever except by means of the procedure that is described in   Section 2.11, “Upgrading MySQL”. Attempting to redefine MySQL's system tables in any other fashion results in undefined and unsupported behavior. The server is free to ignore rows that become malformed as a result of such modifications.

    另外,mysql 8.0不再支持password()函数,因此,不能像mysql5.x那样通过update mysql.user表来修改用户密码。

    但是,在mysql 8.0的root密码重置时遇到报错:

[mysql@mysql8~]$ mysql -uroot -p  -S /home/mysql/mysql/tmp/mysql.sock                                                                                          

Enter password:                                                                                                                                              

Welcome to the MySQL monitor.  Commands end with ; or \g.                                                                                                    

Your MySQL connection id is 7                                                                                                                                

Server version: 8.0.11 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>                                                                                                                                                       

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            

--update mysql.user重置用户密码失败                                                                                                                                 

mysql> update user set authentication_string = '123456'  where user='root' and host='%' ;                                                                    

Query OK, 1 row affected (0.00 sec)                                                                                                                          

Rows matched: 1  Changed: 1  Warnings: 0                                                                                                                     

mysql> flush privileges;                                                                                                                                     

Query OK, 0 rows affected (0.01 sec)                                                                                                                         

mysql> select user,host,authentication_string from mysql.user;                                                                                               

+------------------+-----------+------------------------------------------------------------------------+                                                    

| user             | host      | authentication_string                                                  |                                                    

+------------------+-----------+------------------------------------------------------------------------+                                                    

| root             | %         | 123456                                                                 |                                                    

| mysql.infoschema | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |                                                    

| mysql.session    | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |                                                    

| mysql.sys        | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |                                                    

+------------------+-----------+------------------------------------------------------------------------+                                                    

5 rows in set (0.00 sec)                       

--password函数不被mysql8.0支持

mysql> update user set authentication_string =PASSWORD('123456')  where user='root' and host='%' ;                   

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 '('

123456')  where user='root' and host='%'' at line 1                                                                                                         

mysql> 

--奇怪的是使用alter命令重置root密码长度为6位时报错,但是不是语法错误

mysql> alter user 'root'@'%' identified by '123456';                                                                                                         ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%'                                                                                --但是,将root密码长度增加到8位时获得成功

mysql> ALTER USER root IDENTIFIED WITH mysql_native_password BY '123456789';                                                                                 

Query OK, 0 rows affected (0.01 sec)                                                                                                                         

mysql> flush privileges;                                                                                                                                     

Query OK, 0 rows affected (0.00 sec)                                                                                                                         

mysql> select user,host,authentication_string from mysql.user;                                                                                               

+------------------+-----------+------------------------------------------------------------------------+                                                    

| user             | host      | authentication_string                                                  |                                                    

+------------------+-----------+------------------------------------------------------------------------+                                                    

| root             | %         | *CC67043C7BCFF5EEA5566BD9B1F3C74FD9A5CF5D                              |                                                    

| mysql.infoschema | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |                                                    

| mysql.session    | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |                                                    

| mysql.sys        | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE                              |                                                    

+------------------+-----------+------------------------------------------------------------------------+                                                    

5 rows in set (0.00 sec)                                                                                                                                     

     但是,我本地的centos 7.6上的mysql 8.0重置root密码缺没有密码长度限制,两套库用的是相同的参数文件。

mysql 8.0.11 数据库用户密码修改诡异的限制                                                                  

     官方关于用户密码长度没有特别说明,网上也没有类似密码长度问题的资料,很奇怪!

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29357786/viewspace-2704307/,如需转载,请注明出处,否则将追究法律责任。

烟台医大胃肠医院 http://www.ytwcbyy.com/


网站名称:mysql8.0.11数据库用户密码修改诡异的限制
新闻来源:http://cdkjz.cn/article/pohoig.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220