300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > mysql8区分大小写_mysql区分大小写

mysql8区分大小写_mysql区分大小写

时间:2021-11-16 23:59:37

相关推荐

mysql8区分大小写_mysql区分大小写

两种情况下会区分大小写,

1、建表时,表的编码是utf8_bin(utf8_general_ci不会区分大小写),注意是表编码不是数据库编码。区分大小写与数据库编码无关。

2、建表后,可以通过 binary调整。语句如下:

alter table `wl_testdx_bin`.`wlt_testDx_bin` modify `currency` varchar(5) binary;

开始测试:

drop table `testDx_bin`;

CREATE TABLE `testDx_bin` (

`id` bigint(20) NOT NULL AUTO_INCREMENT,

`currency` varchar(5) NOT NULL DEFAULT 'USD' COMMENT '资产币种',

`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

PRIMARY KEY (`id`),

UNIQUE `idx_currency` (`currency`) USING BTREE

) ENGINE=InnoDB COLLATE=utf8_bin;

INSERT INTO `testDx_bin`( `currency`, `create_time`, `update_time`)

VALUES ( 'uSD', '-10-08 22:37:04', '-10-08 22:37:08');

执行成功。

INSERT INTO `testDx_bin`( `currency`, `create_time`, `update_time`)

VALUES ( 'USD', '-10-08 22:37:04', '-10-08 22:37:08');

执行成功。

drop table `testDx_bin`;

CREATE TABLE `testDx_bin` (

`id` bigint(20) NOT NULL AUTO_INCREMENT,

`currency` varchar(5) NOT NULL DEFAULT 'USD' COMMENT '资产币种',

`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

PRIMARY KEY (`id`),

UNIQUE `idx_currency` (`currency`) USING BTREE

) ENGINE=InnoDB COLLATE=utf8_general_ci;

INSERT INTO `testDx_bin`( `currency`, `create_time`, `update_time`)

VALUES ( 'uSD', '-10-08 22:37:04', '-10-08 22:37:08');

执行成功。

INSERT INTO `testDx_bin`( `currency`, `create_time`, `update_time`)

VALUES ( 'USD', '-10-08 22:37:04', '-10-08 22:37:08');

执行失败。

alter table `testDx_bin` modify `currency` varchar(5) binary;

INSERT INTO `testDx_bin`( `currency`, `create_time`, `update_time`)

VALUES ( 'USD', '-10-08 22:37:04', '-10-08 22:37:08');

执行成功。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。