我已经把数据库test、表中字段name、my.ini文件中都设置为GBK了,win7 32位系统。
问题如下:
mysql> use test;
Database changed
mysql> create table t(
-> id int primary key,
-> name varchar(20),
-> age int);
Query OK, 0 rows affected (0.16 sec)
mysql> insert into t values(1,'李宁',20);
Query OK, 1 row affected (0.00 sec)
mysql> select * from t;
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | | 20 |
+----+------+------+
1 row in set (0.00 sec)
mysql> status
--------------
D:\Program Files\MySQL\MySQL Server 5.1\b
for Win32 (ia32)
Connection id: 4
Current database: test
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.1.30-community
Protocol version: 10
Connection: localhost via TCP
Server characterset: gbk
Db characterset: gbk
Client characterset: gbk
Conn. characterset: gbk
TCP port: 3306
Uptime: 23 min 44 sec
Threads: 4 Questions: 48 Slow queries:
les: 16 Queries per second avg: 0.33
9 个解决方案
#1
set names gbk; 后再试试
#2
set names gbk;
#3
set names 'gbk';
字符集设置的问题。
http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
MySQL 中文显示乱码
字符集设置的问题。
http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
MySQL 中文显示乱码
#4
show variables like 'char%';
set names 'gbk';
set names 'gbk';
#5
不是这个问题,试了,不行。
#6
再帮忙看看,还有哪个地方有问题。
mysql> show variables like 'char%';
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | gbk |
| character_set_system | utf8 |
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.1\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set (0.00 sec)
mysql> set names gbk;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t;
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | | 20 |
+----+------+------+
#7
到底哪儿出问题了啊?以前没出现过这个问题呢,刚发现的。自己设置了好长时间,都不知道是哪儿的问题。
mysql> show variables like 'char%';
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | gbk |
| character_set_system | utf8 |
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.1\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set (0.00 sec)
mysql> set names gbk;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t;
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | | 20 |
+----+------+------+
mysql> show create table t;
+-------+-------------------------------
----------------------------------------
| Table | Create Table
+-------+-------------------------------
----------------------------------------
| t | CREATE TABLE `t` (
`id` int(11) NOT NULL,
`name` varchar(20) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk |
mysql> show full fields from t;
+-------+-------------+----------------+------+-----+---------+-------+---------------------------------+-----
----+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comm
ent |
+-------+-------------+----------------+------+-----+---------+-------+---------------------------------+-----
----+
| id | int(11) | NULL | NO | PRI | NULL | | select,insert,update,references |
|
| name | varchar(20) | gbk_chinese_ci | YES | | NULL | | select,insert,update,references |
|
| age | int(11) | NULL | YES | | NULL | | select,insert,update,references |
|
mysql> set names gbk;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t;
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | | 20 |
+----+------+------+
1 row in set (0.00 sec)
#8
你的字符集查询的时候是正确无误。 估计是写入的时候没有设置正确导致表中实际存放的并不是GBK的数据。
可以直接插入一条,然后检查。
可以直接插入一条,然后检查。
#9
varchar可以单独设定字符集的,可以查看下是否是这个问题。
#1
set names gbk; 后再试试
#2
set names gbk;
#3
set names 'gbk';
字符集设置的问题。
http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
MySQL 中文显示乱码
字符集设置的问题。
http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
MySQL 中文显示乱码
#4
show variables like 'char%';
set names 'gbk';
set names 'gbk';
#5
不是这个问题,试了,不行。
#6
再帮忙看看,还有哪个地方有问题。
mysql> show variables like 'char%';
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | gbk |
| character_set_system | utf8 |
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.1\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set (0.00 sec)
mysql> set names gbk;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t;
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | | 20 |
+----+------+------+
#7
到底哪儿出问题了啊?以前没出现过这个问题呢,刚发现的。自己设置了好长时间,都不知道是哪儿的问题。
mysql> show variables like 'char%';
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | gbk |
| character_set_system | utf8 |
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.1\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set (0.00 sec)
mysql> set names gbk;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t;
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | | 20 |
+----+------+------+
mysql> show create table t;
+-------+-------------------------------
----------------------------------------
| Table | Create Table
+-------+-------------------------------
----------------------------------------
| t | CREATE TABLE `t` (
`id` int(11) NOT NULL,
`name` varchar(20) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk |
mysql> show full fields from t;
+-------+-------------+----------------+------+-----+---------+-------+---------------------------------+-----
----+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comm
ent |
+-------+-------------+----------------+------+-----+---------+-------+---------------------------------+-----
----+
| id | int(11) | NULL | NO | PRI | NULL | | select,insert,update,references |
|
| name | varchar(20) | gbk_chinese_ci | YES | | NULL | | select,insert,update,references |
|
| age | int(11) | NULL | YES | | NULL | | select,insert,update,references |
|
mysql> set names gbk;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from t;
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | | 20 |
+----+------+------+
1 row in set (0.00 sec)
#8
你的字符集查询的时候是正确无误。 估计是写入的时候没有设置正确导致表中实际存放的并不是GBK的数据。
可以直接插入一条,然后检查。
可以直接插入一条,然后检查。
#9
varchar可以单独设定字符集的,可以查看下是否是这个问题。