【发布时间】:2016-05-12 00:11:40
【问题描述】:
在那个字符之后被截断的值????
为什么会这样?
create table tmp2(t1 varchar(100));
insert into tmp2 values('before????after');
mysql> select * from tmp2;
+--------+
| t1 |
+--------+
| before |
+--------+
1 row in set (0.01 sec)
我运行了以下命令并返回了一些有用的信息
mysql> SHOW FULL COLUMNS FROM tmp2;
+-------+--------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+-------+--------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
| t1 | varchar(100) | utf8_general_ci | YES | | NULL | | select,insert,update,references | |
+-------+--------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
1 row in set (0.00 sec)
还有这个,
mysql> SELECT character_set_name FROM information_schema.`COLUMNS` WHERE table_schema = "test" AND table_name = "tmp2" AND column_name = "t1";
+--------------------+
| character_set_name |
+--------------------+
| utf8 |
+--------------------+
1 row in set (0.00 sec)
我正在 ubuntu/mysql 命令行上对此进行测试。
【问题讨论】:
-
对您观察到的行为最可能的解释是客户端应用程序、MySQL 服务器和/或列之间的字符集中存在不匹配。 joelonsoftware.com/articles/Unicode.html 和 kunststube.net/encoding/。 MySQL 参考手册:http://dev.mysql.com/doc/refman/5.6/en/charset.html。修复可能像
SET names 'utf8';一样简单 -
@spencer7593 设置名称'utf8';没用。
-
列的字符集是什么?由于您没有指定它,它将默认为表的。由于也没有指定,它将默认为数据库的字符集。该设置可能是 MySQL 服务器的默认设置。我的猜测是客户端使用的是 UTF-8,并且字符串值包含一个有效的 UTF-8 字符,该字符 not 在列的字符集中有效。但这只是猜测。
-
@spencer7593 我更新了问题并获得了有关列的更多信息。我认为那里没有任何问题。
标签: mysql