千家信息网

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

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,近期,协助一客户重置mysql 8.0.11的root密码,碰到了奇怪的问题。操作系统版本:rhel 7.6数据库版本:mysql 8.0.11根据mysql 8.0官方文档说明,mysql的用户密码
千家信息网最后更新 2026年11月01日mysql 8.0.11 数据库用户密码修改诡异的限制

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

操作系统版本: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密码缺没有密码长度限制,两套库用的是相同的参数文件。


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

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

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

密码 长度 用户 限制 函数 官方 版本 问题 支持 数据 数据库 相同 成功 操作系统 出处 医院 博客 参数 命令 客户 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 天下捷融互联网科技 郑州华宇互联网科技 上海万想互联网科技 互联网科技股有哪些 甘肃拓世互联网科技有限公司 互联网实体化科技化 互联网企业和科技型企业 崇明区互联网教育科技诚信经营 保险科技服务互联网营销体系 伊宁互联网科技做什么的 广州互联网高科技取餐柜 东营紫格互联网科技 九思连强互联网电子科技有限公司 全球科技与互联网公司市值变化 陕西九四连强互联网科技有限公司 艺电能源互联网科技有限公司招聘 上海万顺科技互联网有限公司招聘 米泉互联网科技专业怎么样 每日互联网科技新闻 武汉亿视互联网科技有限公司 中关村互联网科技集团 广州互联网络科技有限公司 联恩商钥互联网科技有限公司 福建科技产业互联网发展 互联网科技革命什么开始 开一家科技互联网公司需要多少钱 南通创西澳互联网科技有限公司 易企秀互联网科技是做什么的 互联网科技对化妆品行业 恒生科技互联网指数十大成分股
0