mysql 8.0.15大小写,mysql 8结果行集大小写有什么变化?

when running

SELECT maxlen FROM `information_schema`.`CHARACTER_SETS`;

mysql 5.7 and mysql 8 produce different results:

on mysql 5.7 the results row names are lower cased,

on mysql 8 the results row names are upper cased.

NB : in the CHARACTER_SETS table, the comumn name is MAXLEN (upper cased).

Since I can't find a resource documenting it, my question is :

what are the changes in mysql 8 result rowset case ?

解决方案

MySQL 8.0 did change the implementation of some views in the 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.

So it's being done for good reasons, but I understand that it has upset some of your queries when you fetch results in associative arrays based on column name.

You can see the definition of the view declares the column name explicitly in uppercase:

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

You can work around the change in a couple of ways:

You can declare your own column aliases in the case you want when you query a view:

mysql 8.0.14> SELECT MAXLEN AS `maxlen`

FROM `information_schema`.`CHARACTER_SETS` LIMIT 2;

+--------+

| maxlen |

+--------+

| 2 |

| 1 |

+--------+

You could start a habit of querying columns in uppercase prior to 8.0. Here's a test showing results in my 5.7 sandbox:

mysql 5.7.24> SELECT MAXLEN

FROM `information_schema`.`CHARACTER_SETS` LIMIT 2;

+--------+

| MAXLEN |

+--------+

| 2 |

| 1 |

+--------+

Or you could fetch results into a non-associative array, and reference columns by column number, instead of by name.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值