mysql 8 结果行集大小写的变化是什么?
what are the changes in mysql 8 result rowset case?
当 运行
SELECT maxlen FROM `information_schema`.`CHARACTER_SETS`;
mysql 5.7 和 mysql 8 产生不同的结果:
- on mysql 5.7 结果行名称是小写的,
- 在 mysql 8 结果行名称是大写的。
注意:在 CHARACTER_SETS
table 中,comumn 名称是 MAXLEN
(大写)。
由于找不到记录它的资源,我的问题是:
what are the changes in mysql 8 result rowset case ?
区分大小写没有变化。如果您查看 mysql 关于标识符区分大小写的文档,v5.7 and v8.0 都说字段名称不区分大小写:
Column, index, stored routine, event, and resource group names are not case-sensitive on any platform, nor are column aliases.
对我来说,这更像是显示差异。
MySQL 8.0确实更改了INFORMATION_SCHEMA中一些视图的实现:
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.
这样做是有充分理由的,但我知道当您根据列名获取关联数组中的结果时,它已经扰乱了您的一些查询。
你可以看到视图的定义明确声明了大写的列名:
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
您可以通过多种方式解决此更改:
您可以在查询视图时根据需要声明自己的列别名:
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 |
+--------+
或者您可以将结果提取到非关联数组中,并按列号而不是按名称引用列。
当 运行
SELECT maxlen FROM `information_schema`.`CHARACTER_SETS`;
mysql 5.7 和 mysql 8 产生不同的结果:
- on mysql 5.7 结果行名称是小写的,
- 在 mysql 8 结果行名称是大写的。
注意:在 CHARACTER_SETS
table 中,comumn 名称是 MAXLEN
(大写)。
由于找不到记录它的资源,我的问题是:
what are the changes in mysql 8 result rowset case ?
区分大小写没有变化。如果您查看 mysql 关于标识符区分大小写的文档,v5.7 and v8.0 都说字段名称不区分大小写:
Column, index, stored routine, event, and resource group names are not case-sensitive on any platform, nor are column aliases.
对我来说,这更像是显示差异。
MySQL 8.0确实更改了INFORMATION_SCHEMA中一些视图的实现:
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.
这样做是有充分理由的,但我知道当您根据列名获取关联数组中的结果时,它已经扰乱了您的一些查询。
你可以看到视图的定义明确声明了大写的列名:
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
您可以通过多种方式解决此更改:
您可以在查询视图时根据需要声明自己的列别名:
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 |
+--------+
或者您可以将结果提取到非关联数组中,并按列号而不是按名称引用列。