关于查询字段内容无法区分大小写问题
root@localhost 20:32: [pwb_inn]> select * from sys_account_login where corp_code='TEST';
+----+------------+------------+----------------------------------+-------------+--------------------------+--------+-----------+----------+------+--------+-------------+----------------+---------------------+------------------+---------+-----------------+----------+---------------------+---------------------+---------+-----------+
| ID | ACCOUNT_ID | LOGIN_NAME | LOGIN_PASS | REALNAME | EMAIL | STATUS | USER_TYPE | BIRTHDAY | SEX | REMARK | LOGIN_COUNT | LAST_IP | LAST_LOGIN_TIME | MOBILE | ID_CARD | CREATE_LOGIN_ID | GROUP_ID | CREATE_TIME | MODIFIED_TIME | DELETED | CORP_CODE |
+----+------------+------------+----------------------------------+-------------+--------------------------+--------+-----------+----------+------+--------+-------------+----------------+---------------------+------------------+---------+-----------------+----------+---------------------+---------------------+---------+-----------+
| 0 | 1 | admin | 9db06bcff9248837f86d1a6bcf41c9e7 | lwwww122211 | xxxxx.qq.1111 | 1 | 0 | NULL | NULL | NULL | 555 | 192.168.60.197 | 2017-06-01 20:27:37 | 1300000000012222 | NULL | NULL | NULL | 2015-03-30 19:52:25 | 2017-06-01 20:27:40 | 0 | test |
| 18 | NULL | wangcx | 9db06bcff9248837f86d1a6bcf41c9e7 | wangcx1 | chixu.wang@zhiyoubao.com | 1 | 2 | NULL | 0 | NULL | NULL | | NULL | 13000000000 | | NULL | NULL | 2017-05-18 14:36:24 | 2017-05-18 15:06:55 | 1 | test |
| 19 | 1 | 11 | 28c8edde3d61a0411511d3b1866f0636 | 12 | 12 | 1 | 2 | NULL | 0 | NULL | NULL | | NULL | 12 | | NULL | NULL | 2017-05-18 14:50:58 | 2017-05-18 15:06:55 | 1 | test |
| 20 | 1 | 3 | 38026ed22fc1a91d92b5d2ef93540f20 | 3 | 3 | 1 | 2 | NULL | 0 | NULL | NULL | | NULL | 3 | | NULL | NULL | 2017-05-18 14:52:38 | 2017-05-18 15:06:55 | 1 | test |
| 21 | 1 | 1111112 | 3ed80171b1f4ab825f2038fc203c887c | 1 | 1 | 1 | 2 | NULL | 0 | NULL | NULL | | NULL | 1 | | NULL | NULL | 2017-05-18 14:56:31 | 2017-05-18 15:06:55 | 1 | test |
| 22 | 1 | wangcx222 | 63ee451939ed580ef3c4b6f0109d1fd0 | 211111 | | 1 | 2 | NULL | 0 | NULL | NULL | | NULL | | | NULL | NULL | 2017-05-18 15:32:54 | 2017-05-18 15:34:25 | 1 | test |
| 23 | 1 | wangcx | 14e1b600b1fd579f47433b88e8d85291 | wangcx | | 1 | 2 | NULL | 0 | NULL | 1 | 192.168.60.197 | 2017-05-27 10:03:13 | | | NULL | NULL | 2017-05-27 10:02:47 | 2017-05-27 10:03:23 | 0 | test |
| 24 | 1 | wangqq | 9db06bcff9248837f86d1a6bcf41c9e7 | 王强强 | 451766647@qq.com | 1 | 2 | NULL | 0 | NULL | NULL | | NULL | 13639887172 | | NULL | NULL | 2017-05-31 09:40:56 | 2017-05-31 10:36:49 | 1 | test |
| 25 | 1 | wangqq | 9db06bcff9248837f86d1a6bcf41c9e7 | 王强强 | | 0 | 2 | NULL | 0 | NULL | 5 | 192.168.60.103 | 2017-05-31 16:46:49 | 13632145698 | | NULL | NULL | 2017-05-31 10:37:25 | 2017-05-31 16:59:42 | 1 | test |
| 26 | 1 | wangqq | 9db06bcff9248837f86d1a6bcf41c9e7 | wangqq | | 1 | 2 | NULL | 0 | NULL | 8 | 192.168.60.103 | 2017-06-01 10:37:46 | | | NULL | NULL | 2017-06-01 09:33:22 | 2017-06-01 10:37:50 | 0 | test |
查询大写但是小写也显示
怀疑字符集问题
root@localhost 20:29: [pwb_inn]> show create table sys_account_login \G
*************************** 1. row ***************************
Table: sys_account_login
Create Table: CREATE TABLE `sys_account_login` (
`ID` varchar(20) NOT NULL COMMENT 'SEQENCE',
`ACCOUNT_ID` varchar(20) DEFAULT NULL COMMENT '账户信息主键',
`LOGIN_NAME` varchar(128) DEFAULT NULL COMMENT '登录名',
`LOGIN_PASS` varchar(128) DEFAULT NULL COMMENT '登录密码',
`REALNAME` varchar(128) DEFAULT NULL COMMENT '真实姓名',
`EMAIL` varchar(128) DEFAULT NULL COMMENT '电子邮件',
`STATUS` varchar(64) DEFAULT '' COMMENT '用户状态 0:锁定1:正常\r\n ',
`USER_TYPE` varchar(16) NOT NULL DEFAULT '0' COMMENT '用户类型:1深大客服2客栈管理员3客栈操作员(二期改动后,只有类型2,即供应商登录,0是企业主账户,无法删除)',
`BIRTHDAY` datetime DEFAULT NULL COMMENT '生日 yyyy-MM-dd',
`SEX` varchar(16) DEFAULT '0' COMMENT '1男,0女',
`REMARK` varchar(1024) DEFAULT NULL COMMENT '备注',
`LOGIN_COUNT` varchar(20) DEFAULT NULL COMMENT '登录次数 每次登录+1',
`LAST_IP` varchar(64) DEFAULT '' COMMENT '最后登录IP',
`LAST_LOGIN_TIME` datetime DEFAULT NULL COMMENT '最后登录时间',
`MOBILE` varchar(64) DEFAULT '' COMMENT '手机号',
`ID_CARD` varchar(64) DEFAULT '' COMMENT '身份证号',
`CREATE_LOGIN_ID` varchar(20) DEFAULT NULL COMMENT '用户创建人',
`GROUP_ID` varchar(20) DEFAULT NULL,
`CREATE_TIME` datetime DEFAULT NULL COMMENT '创建时间',
`MODIFIED_TIME` datetime DEFAULT NULL COMMENT '修改时间',
`DELETED` smallint(6) NOT NULL DEFAULT '0' COMMENT '删除标志 0:未删除 1:已删除',
`CORP_CODE` varchar(32) NOT NULL COMMENT '企业码(二期)',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
最后查询是字符集校对问题
Mysql collate规则:
*_bin: 表示的是binary case sensitive collation,也就是说是区分大小写的
*_cs: case sensitive collation,区分大小写
*_ci: case insensitive collation,不区分大小写
修改校对规则
root@localhost 20:44: [pwb_inn]> ALTER TABLE sys_account_login CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_cs;
ERROR 1273 (HY000): Unknown collation: 'utf8_general_cs'
5.6不支持utf8_general_cs
root@localhost 20:44: [pwb_inn]> ALTER TABLE sys_account_login CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
root@localhost 20:44: [pwb_inn]> ALTER TABLE sys_account_login CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
Query OK, 17 rows affected (0.01 sec)
Records: 17 Duplicates: 0 Warnings: 0
root@localhost 20:45: [pwb_inn]> select * from sys_account_login where corp_code='TEST';
Empty set (0.00 sec)
root@localhost 20:32: [pwb_inn]> select * from sys_account_login where corp_code='TEST';
+----+------------+------------+----------------------------------+-------------+--------------------------+--------+-----------+----------+------+--------+-------------+----------------+---------------------+------------------+---------+-----------------+----------+---------------------+---------------------+---------+-----------+
| ID | ACCOUNT_ID | LOGIN_NAME | LOGIN_PASS | REALNAME | EMAIL | STATUS | USER_TYPE | BIRTHDAY | SEX | REMARK | LOGIN_COUNT | LAST_IP | LAST_LOGIN_TIME | MOBILE | ID_CARD | CREATE_LOGIN_ID | GROUP_ID | CREATE_TIME | MODIFIED_TIME | DELETED | CORP_CODE |
+----+------------+------------+----------------------------------+-------------+--------------------------+--------+-----------+----------+------+--------+-------------+----------------+---------------------+------------------+---------+-----------------+----------+---------------------+---------------------+---------+-----------+
| 0 | 1 | admin | 9db06bcff9248837f86d1a6bcf41c9e7 | lwwww122211 | xxxxx.qq.1111 | 1 | 0 | NULL | NULL | NULL | 555 | 192.168.60.197 | 2017-06-01 20:27:37 | 1300000000012222 | NULL | NULL | NULL | 2015-03-30 19:52:25 | 2017-06-01 20:27:40 | 0 | test |
| 18 | NULL | wangcx | 9db06bcff9248837f86d1a6bcf41c9e7 | wangcx1 | chixu.wang@zhiyoubao.com | 1 | 2 | NULL | 0 | NULL | NULL | | NULL | 13000000000 | | NULL | NULL | 2017-05-18 14:36:24 | 2017-05-18 15:06:55 | 1 | test |
| 19 | 1 | 11 | 28c8edde3d61a0411511d3b1866f0636 | 12 | 12 | 1 | 2 | NULL | 0 | NULL | NULL | | NULL | 12 | | NULL | NULL | 2017-05-18 14:50:58 | 2017-05-18 15:06:55 | 1 | test |
| 20 | 1 | 3 | 38026ed22fc1a91d92b5d2ef93540f20 | 3 | 3 | 1 | 2 | NULL | 0 | NULL | NULL | | NULL | 3 | | NULL | NULL | 2017-05-18 14:52:38 | 2017-05-18 15:06:55 | 1 | test |
| 21 | 1 | 1111112 | 3ed80171b1f4ab825f2038fc203c887c | 1 | 1 | 1 | 2 | NULL | 0 | NULL | NULL | | NULL | 1 | | NULL | NULL | 2017-05-18 14:56:31 | 2017-05-18 15:06:55 | 1 | test |
| 22 | 1 | wangcx222 | 63ee451939ed580ef3c4b6f0109d1fd0 | 211111 | | 1 | 2 | NULL | 0 | NULL | NULL | | NULL | | | NULL | NULL | 2017-05-18 15:32:54 | 2017-05-18 15:34:25 | 1 | test |
| 23 | 1 | wangcx | 14e1b600b1fd579f47433b88e8d85291 | wangcx | | 1 | 2 | NULL | 0 | NULL | 1 | 192.168.60.197 | 2017-05-27 10:03:13 | | | NULL | NULL | 2017-05-27 10:02:47 | 2017-05-27 10:03:23 | 0 | test |
| 24 | 1 | wangqq | 9db06bcff9248837f86d1a6bcf41c9e7 | 王强强 | 451766647@qq.com | 1 | 2 | NULL | 0 | NULL | NULL | | NULL | 13639887172 | | NULL | NULL | 2017-05-31 09:40:56 | 2017-05-31 10:36:49 | 1 | test |
| 25 | 1 | wangqq | 9db06bcff9248837f86d1a6bcf41c9e7 | 王强强 | | 0 | 2 | NULL | 0 | NULL | 5 | 192.168.60.103 | 2017-05-31 16:46:49 | 13632145698 | | NULL | NULL | 2017-05-31 10:37:25 | 2017-05-31 16:59:42 | 1 | test |
| 26 | 1 | wangqq | 9db06bcff9248837f86d1a6bcf41c9e7 | wangqq | | 1 | 2 | NULL | 0 | NULL | 8 | 192.168.60.103 | 2017-06-01 10:37:46 | | | NULL | NULL | 2017-06-01 09:33:22 | 2017-06-01 10:37:50 | 0 | test |
查询大写但是小写也显示
怀疑字符集问题
root@localhost 20:29: [pwb_inn]> show create table sys_account_login \G
*************************** 1. row ***************************
Table: sys_account_login
Create Table: CREATE TABLE `sys_account_login` (
`ID` varchar(20) NOT NULL COMMENT 'SEQENCE',
`ACCOUNT_ID` varchar(20) DEFAULT NULL COMMENT '账户信息主键',
`LOGIN_NAME` varchar(128) DEFAULT NULL COMMENT '登录名',
`LOGIN_PASS` varchar(128) DEFAULT NULL COMMENT '登录密码',
`REALNAME` varchar(128) DEFAULT NULL COMMENT '真实姓名',
`EMAIL` varchar(128) DEFAULT NULL COMMENT '电子邮件',
`STATUS` varchar(64) DEFAULT '' COMMENT '用户状态 0:锁定1:正常\r\n ',
`USER_TYPE` varchar(16) NOT NULL DEFAULT '0' COMMENT '用户类型:1深大客服2客栈管理员3客栈操作员(二期改动后,只有类型2,即供应商登录,0是企业主账户,无法删除)',
`BIRTHDAY` datetime DEFAULT NULL COMMENT '生日 yyyy-MM-dd',
`SEX` varchar(16) DEFAULT '0' COMMENT '1男,0女',
`REMARK` varchar(1024) DEFAULT NULL COMMENT '备注',
`LOGIN_COUNT` varchar(20) DEFAULT NULL COMMENT '登录次数 每次登录+1',
`LAST_IP` varchar(64) DEFAULT '' COMMENT '最后登录IP',
`LAST_LOGIN_TIME` datetime DEFAULT NULL COMMENT '最后登录时间',
`MOBILE` varchar(64) DEFAULT '' COMMENT '手机号',
`ID_CARD` varchar(64) DEFAULT '' COMMENT '身份证号',
`CREATE_LOGIN_ID` varchar(20) DEFAULT NULL COMMENT '用户创建人',
`GROUP_ID` varchar(20) DEFAULT NULL,
`CREATE_TIME` datetime DEFAULT NULL COMMENT '创建时间',
`MODIFIED_TIME` datetime DEFAULT NULL COMMENT '修改时间',
`DELETED` smallint(6) NOT NULL DEFAULT '0' COMMENT '删除标志 0:未删除 1:已删除',
`CORP_CODE` varchar(32) NOT NULL COMMENT '企业码(二期)',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
最后查询是字符集校对问题
Mysql collate规则:
*_bin: 表示的是binary case sensitive collation,也就是说是区分大小写的
*_cs: case sensitive collation,区分大小写
*_ci: case insensitive collation,不区分大小写
修改校对规则
root@localhost 20:44: [pwb_inn]> ALTER TABLE sys_account_login CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_cs;
ERROR 1273 (HY000): Unknown collation: 'utf8_general_cs'
5.6不支持utf8_general_cs
root@localhost 20:44: [pwb_inn]> ALTER TABLE sys_account_login CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
root@localhost 20:44: [pwb_inn]> ALTER TABLE sys_account_login CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
Query OK, 17 rows affected (0.01 sec)
Records: 17 Duplicates: 0 Warnings: 0
root@localhost 20:45: [pwb_inn]> select * from sys_account_login where corp_code='TEST';
Empty set (0.00 sec)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24486203/viewspace-2140180/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/24486203/viewspace-2140180/