数据库
首页 > 数据库> > mysql 8结果rowset案例有哪些变化?

mysql 8结果rowset案例有哪些变化?

作者:互联网

跑步的时候

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中一些视图的实现:

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 |
+--------+

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

标签:mysql,case-sensitive,mysql-8-0
来源: https://codeday.me/bug/20191007/1866046.html