无法在mysql中插入一些特殊字符

时间:2016-02-03 00:03:52

标签: mysql

该字符后的值被切断

为什么会这样?

create table tmp2(t1 varchar(100)); 

insert into tmp2 values('beforeafter'); 

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命令行上测试它。

1 个答案:

答案 0 :(得分:1)

我找到了解决方案here

我在utf8中学到了一些不包含的字符

有一篇好文章here

我需要将列utf8更改为utf8mb4并且它有效

alter table tmp2 modify t1 varchar(100) character set utf8mb4;

SET NAMES utf8mb4;

insert tmp2 values('beforeafter');