mysql查詢欄位內容無法區分大小寫問題
關於查詢欄位內容無法區分大小寫問題
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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Mysql 的編碼方式使得欄位內容不區分大小寫MySql
- 更改MySql表和欄位區分大小寫MySql
- 使MySQL查詢區分大小寫(轉)MySql
- MySQL模糊查詢(like)時區分大小寫MySql
- 查詢區分大小寫 (轉)
- SQL Server 2008 中SQL查詢語句中欄位值不區分大小寫問題處理SQLServer
- 模糊查詢區分大小寫嗎?
- vim 查詢不區分大小寫
- Mysql模糊查詢預設是不區分字母大小寫的MySql
- MongoDB查詢如何只輸出部分欄位內容MongoDB
- [Mysql 查詢語句]——查詢欄位MySql
- MySQL資料庫中庫、表名、欄位的大小寫問題MySql資料庫
- MySQL的where條件字串區分大小寫的問題MySql字串
- MySQL大小寫問題MySql
- 配置mysql不區分大小寫MySql
- mysql 表明不區分大小寫MySql
- MySQL binary 區分大小寫MySql
- MySQL表名區分大小寫MySql
- mysql字串之大小寫匹配查詢MySql字串
- MySql 查詢某一天日期格式欄位走索引問題MySql索引
- mysql 大小寫敏感問題MySql
- MySQL 大欄位問題MySql
- MySQL不區分大小寫設定MySql
- 關於sqlserver字元型別查詢條件區分大小寫SQLServer字元型別
- Laravel 查詢資料庫欄位內容是 Json 陣列時的查詢語句Laravel資料庫JSON陣列
- 設定MYSQL不區分表大小寫MySql
- Mysql 表名大小寫問題MySql
- mysql大小寫問題解決MySql
- clob 欄位查詢
- mysql多表多欄位查詢並去重MySql
- mysql 查詢欄位為null或者非nullMySqlNull
- 無限級分類---有關查詢問題??
- MySQL:查詢欄位數量多少對查詢效率的影響MySql
- 請問mysql裡面的text欄位怎麼進行模糊查詢MySql
- 更改MYSQL資料庫不區分大小寫MySql資料庫
- Git 區分大小寫Git
- MySQL簡單實現多欄位模糊查詢MySql
- 為 MySQL 的查詢結果新增排名欄位MySql