MySQL documentation says that since 5.0, varchar lengths refer to character units, not bytes. However, I recently came across an issue where I was getting truncated data warnings when inserting values that should have fit into the varchar column it was designated.
我用简单的表格复制了这一问题。
mysql> show create table testG
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`string` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
之后,我插入了10种特性值,其特性各不相同。
mysql> insert into test (string) values
-> ( abcdefghij ),
-> ( ãáéíçãáéíç ),
-> ( ãáéíç67890 ),
-> ( éíç4567890 ),
-> ( íç34567890 );
Query OK, 5 rows affected, 4 warnings (0.06 sec)
Records: 5 Duplicates: 0 Warnings: 4
mysql> show warnings;
+---------+------+---------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------+
| Warning | 1265 | Data truncated for column string at row 2 |
| Warning | 1265 | Data truncated for column string at row 3 |
| Warning | 1265 | Data truncated for column string at row 4 |
| Warning | 1265 | Data truncated for column string at row 5 |
+---------+------+---------------------------------------------+
mysql> select * from test;
+------------+
| string |
+------------+
| abcdefghij |
| ãáéíç |
| ãáéíç |
| éíç4567 |
| íç345678 |
+------------+
5 rows in set (0.00 sec)
我认为,这表明,var体大小仍然以斜体或至少以体字表示,并非准确的特性单位。
问题在于,我是否正确理解文件,这是否是ug? 还是我对文件的解释有误?