如果 charset 不是对 insert 进行限制的,那是用在什么地方的?
测试过程如下:
mysql server 版本:
+-------------------------+---------------------+
| Variable_name | Value |
+-------------------------+---------------------+
| protocol_version | 10 |
| version | 5.1.73 |
| version_comment | Source distribution |
| version_compile_machine | x86_64 |
| version_compile_os | redhat-linux-gnu |
+-------------------------+---------------------+
连接信息
mysql> SHOW SESSION VARIABLES LIKE 'character\_set\_%';
+--------------------------+--------+
| Variable_name | Value |
+--------------------------+--------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
+--------------------------+--------+
7 rows in set (0.00 sec)
mysql> SHOW SESSION VARIABLES LIKE 'collation\_%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)
测试的数据库和表信息:
mysql> show create database sunny_test;
+------------+-----------------------------------------------------------------------+
| Database | Create Database |
+------------+-----------------------------------------------------------------------+
| sunny_test | CREATE DATABASE `sunny_test` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+------------+-----------------------------------------------------------------------+
mysql> show create table pet;
+-------+------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------------------------------------------------+
| pet | CREATE TABLE `pet` (
`name` varchar(20) NOT NULL DEFAULT '',
PRIMARY KEY (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+-------+------------------------------------------------------------------------------------------------------------------------------+
mysql> insert into pet values ("你好");
Query OK, 1 row affected (0.00 sec)
mysql> select * from pet;
+--------+
| name |
+--------+
| 你好 |
+--------+
1 row in set (0.00 sec)
mysql> insert into pet values ("♥");
Query OK, 1 row affected (0.00 sec)
mysql> select * from pet;
+--------+
| name |
+--------+
| ♥ |
| 你好 |
+--------+
2 rows in set (0.00 sec)
救救孩子
1
rebeccaMyKid OP 这 markdown 的代码自动高亮怎么取消啊。。
|