gpt4 book ai didi

mysql - mysql 8 结果行集大小写有哪些变化?

转载 作者:行者123 更新时间:2023-12-02 00:23:50 25 4
gpt4 key购买 nike

运行时

SELECT maxlen FROM `information_schema`.`CHARACTER_SETS`;

mysql 5.7 和 mysql 8 产生不同的结果:

  • 在 mysql 5.7 上,结果行名称是小写的,
  • 在 mysql 8 上,结果行名称是大写的。

注意:在 CHARACTER_SETS 表中,comumn 名称是 MAXLEN(大写)。

因为我找不到记录它的资源,我的问题是:

what are the changes in mysql 8 result rowset case ?

最佳答案

MySQL 8.0 确实更改了 INFORMATION_SCHEMA 中某些 View 的实现:

https://mysqlserverteam.com/mysql-8-0-improvements-to-information_schema/说:

Now that the metadata of all database tables is stored in transactional data dictionary tables, it enables us to design an INFORMATION_SCHEMA table as a database VIEW over the data dictionary tables. This eliminates costs such as the creation of temporary tables for each INFORMATION_SCHEMA query during execution on-the-fly, and also scanning file-system directories to find FRM files. It is also now possible to utilize the full power of the MySQL optimizer to prepare better query execution plans using indexes on data dictionary tables.

所以这样做是有充分理由的,但我知道当您根据列名获取关联数组中的结果时,它已经扰乱了您的一些查询。

您可以看到 View 的定义以大写形式显式声明了列名:

mysql 8.0.14> SHOW CREATE VIEW CHARACTER_SETS\G
*************************** 1. row ***************************
View: CHARACTER_SETS
Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`mysql.infoschema`@`localhost` SQL SECURITY DEFINER VIEW `CHARACTER_SETS` AS
select
`cs`.`name` AS `CHARACTER_SET_NAME`,
`col`.`name` AS `DEFAULT_COLLATE_NAME`,
`cs`.`comment` AS `DESCRIPTION`,
`cs`.`mb_max_length` AS `MAXLEN` -- delimited column explicitly uppercase
from (`mysql`.`character_sets` `cs`
join `mysql`.`collations` `col` on((`cs`.`default_collation_id` = `col`.`id`)))

character_set_client: utf8
collation_connection: utf8_general_ci

您可以通过多种方式解决此更改:

在查询 View 时,您可以根据需要声明自己的列别名:

mysql 8.0.14> SELECT MAXLEN AS `maxlen` 
FROM `information_schema`.`CHARACTER_SETS` LIMIT 2;
+--------+
| maxlen |
+--------+
| 2 |
| 1 |
+--------+

在 8.0 之前,您可以养成查询大写列的习惯。这是在我的 5.7 沙箱中显示结果的测试:

mysql 5.7.24> SELECT MAXLEN 
FROM `information_schema`.`CHARACTER_SETS` LIMIT 2;
+--------+
| MAXLEN |
+--------+
| 2 |
| 1 |
+--------+

或者您可以将结果提取到非关联数组中,并按列号而不是按名称引用列。

关于mysql - mysql 8 结果行集大小写有哪些变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54538448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com