MySQL 5.6。我无法在视图中获得字符串常量以正确填充具有默认UCS2字符集的数据库。在5.7上工作正常。
我在下面创建了一个可重复性最低的示例。
DROP SCHEMA IF EXISTS test3;
CREATE SCHEMA test3 CHARACTER SET ucs2;
CONNECT test3;
CREATE TABLE testtable (
testname VARCHAR(15)
);
INSERT INTO testTable( testname ) VALUES ('foo');
INSERT INTO testTable( testname ) VALUES ('bar');
CREATE OR REPLACE VIEW testview AS
SELECT * FROM testtable
WHERE testname = 'foo';
SELECT * FROM testview;
^^^此select语句不返回任何结果。
MySQL [test3]> show create view testview \G *************************** 1. row *************************** View: testview Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `testview` AS select `testtable`.`testname` AS `testname` from `testtable` where (`testtable`.`testname` = '\0\0\0f\0\0\0o\0\0\0o') character_set_client: utf8 collation_connection: utf8_general_ci
那是什么,utf32 ??
以下 可以正常工作,但我不想将整理直接写入语句,因为这需要是可移植代码,语法看起来不标准:
CREATE OR REPLACE VIEW testview AS
SELECT * FROM testtable
WHERE testname = 'foo' COLLATE utf8_general_ci;
我尝试将客户端,连接和服务器字符集设置为ucs2和utf16,但这没有任何改变。与* _general_ci的排序相同。
有任何想法吗?
编辑:
MySQL [test3]> show variables like "char%"; +--------------------------+------------------------------------------------------------+ | Variable_name | Value | +--------------------------+------------------------------------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | ucs2 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | C:\Program Files\MySQL\mysql-5.6.36-winx64\share\charsets\ | +--------------------------+------------------------------------------------------------+
答案 0 :(得分:2)
基本上没有理由在MySQL表中使用usc2或utf16或utf32。仅使用utf8mb4。 (如果您有旧版本的MySQL,请使用utf8。)
请提供git remote add bundle /local/path/to/my_changes.bundle
不应更改某些内容:
SHOW VARIABLES LIKE "char%";
创建视图时,未设置charset。我可以在mysql> SHOW VARIABLES LIKE "char%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary | <--
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 | <--
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
说出来时看到:
SHOW