在数据库中显示为中文字段的信息,用otl_stream流输出之后是“问号”。
例如:在表中有一个字段名为subject对应的字段内容是:主题,就是主题,subject from。使用m_cOtlStream >> m_cTmp;输出到m_cTmp变量中,结果变成了:????????,subject from。就是说中文字符变成了问号,英文输入下输出的都是正常的,请问如何解决之?
31 个解决方案
#1
字符集问题,贴下你的show variables like 'character_set%';
输出的m_cTmp变量中变量指定下utf8 试试
输出的m_cTmp变量中变量指定下utf8 试试
#2
检查一下你的字符集设置。 可以参考下贴中的检查方法。
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 中文显示乱码
#3
mysql> show 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
|
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.0\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.02 sec)
mysql>
#4
要怎么设置呀?我已经贴出来了。以前没有用过mysql
#5
#2楼 的贴子你看了吗?其它检查结果呢?
#6
set names utf8 再导出;还有就是你的变量声明出来也设置成utf8;试试,
#7
我都设置成UTF8还是不行,输出还是乱码,而且重启mysql服务之后,character_set又变成原先的了。
#8
怎么设置啊?变量声明出来怎么设置成utf8?
#9
如
declare m_cTmp varchar(100) character set utf8;
declare m_cTmp varchar(100) character set utf8;
#10
数据库中现在显示的中文中正常的,只是用otl_stream流写到界面或者输出之后就变乱码了。
你说的是什么意思?m_cTmp我是在VC中定义的char[]变量。
你说的是什么意思?m_cTmp我是在VC中定义的char[]变量。
#11
看看
ACMAIN_CHM 老大给的地址 绝对有帮助。顺便告诉你一声。除了设置数据库 最好也罢变量也设置了类型
#12
就是需要给你的变量设置字符集;
#13
set names 'gbk'
#14
字符集问题,不统一
set names latin1
试试
在统一字符集的下重新插入记录
set names latin1
试试
在统一字符集的下重新插入记录
#15
都说的模凌两可。
#17
在你的程序里set names 'latin1',再取结果看看。
#18
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 5.0.22-community-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mailreceiver |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use test;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> use mailreceiver;
Database changed
mysql> show tables;
+------------------------+
| Tables_in_mailreceiver |
+------------------------+
| mailaccount |
| mailinfo |
| servertable |
| test_tab |
+------------------------+
4 rows in set (0.00 sec)
mysql> show create table mailinfo;
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------+
| Table | Create Table
|
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------+
| mailinfo | CREATE TABLE `mailinfo` (
`Id` int(11) NOT NULL auto_increment,
`Subject` varchar(128) default '',
`From` varchar(64) default NULL,
`To` varchar(64) default NULL,
`DateTime` datetime default '1901-01-01 01:01:01',
`MessageId` varchar(128) default NULL,
`AttachName` varchar(512) default NULL,
`MailPath` varchar(255) default NULL,
`HasRead` bit(1) default '\0' COMMENT '是否阅读',
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312 |
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------+
1 row in set (0.05 sec)
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------------------------------
-----+
| Variable_name | Value
|
+--------------------------+----------------------------------------------------
-----+
| character_set_client | gb2312
|
| character_set_connection | gb2312
|
| character_set_database | gb2312
|
| character_set_filesystem | binary
|
| character_set_results | gb2312
|
| character_set_server | gb2312
|
| character_set_system | utf8
|
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.0\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.00 sec)
mysql> show full columns from mailinfo;
+------------+--------------+-------------------+------+-----+------------------
---+----------------+---------------------------------+----------+
| Field | Type | Collation | Null | Key | Default
| Extra | Privileges | Comment |
+------------+--------------+-------------------+------+-----+------------------
---+----------------+---------------------------------+----------+
| Id | int(11) | NULL | NO | PRI | NULL
| auto_increment | select,insert,update,references | |
| Subject | varchar(128) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| From | varchar(64) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| To | varchar(64) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| DateTime | datetime | NULL | YES | | 1901-01-01 01:01:
01 | | select,insert,update,references | |
| MessageId | varchar(128) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| AttachName | varchar(512) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| MailPath | varchar(255) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| HasRead | bit(1) | NULL | YES | |
| | select,insert,update,references | 是否阅读 |
+------------+--------------+-------------------+------+-----+------------------
---+----------------+---------------------------------+----------+
9 rows in set (0.03 sec)
mysql>
---------------------
老大们,再看一下。就是mailinfo里的subject中有中文,在到界面显示时都变成“问号”了。以上是检查的所有字符集设置,有什么问题没有??谢谢。
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 5.0.22-community-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mailreceiver |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use test;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> use mailreceiver;
Database changed
mysql> show tables;
+------------------------+
| Tables_in_mailreceiver |
+------------------------+
| mailaccount |
| mailinfo |
| servertable |
| test_tab |
+------------------------+
4 rows in set (0.00 sec)
mysql> show create table mailinfo;
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------+
| Table | Create Table
|
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------+
| mailinfo | CREATE TABLE `mailinfo` (
`Id` int(11) NOT NULL auto_increment,
`Subject` varchar(128) default '',
`From` varchar(64) default NULL,
`To` varchar(64) default NULL,
`DateTime` datetime default '1901-01-01 01:01:01',
`MessageId` varchar(128) default NULL,
`AttachName` varchar(512) default NULL,
`MailPath` varchar(255) default NULL,
`HasRead` bit(1) default '\0' COMMENT '是否阅读',
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312 |
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------+
1 row in set (0.05 sec)
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------------------------------
-----+
| Variable_name | Value
|
+--------------------------+----------------------------------------------------
-----+
| character_set_client | gb2312
|
| character_set_connection | gb2312
|
| character_set_database | gb2312
|
| character_set_filesystem | binary
|
| character_set_results | gb2312
|
| character_set_server | gb2312
|
| character_set_system | utf8
|
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.0\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.00 sec)
mysql> show full columns from mailinfo;
+------------+--------------+-------------------+------+-----+------------------
---+----------------+---------------------------------+----------+
| Field | Type | Collation | Null | Key | Default
| Extra | Privileges | Comment |
+------------+--------------+-------------------+------+-----+------------------
---+----------------+---------------------------------+----------+
| Id | int(11) | NULL | NO | PRI | NULL
| auto_increment | select,insert,update,references | |
| Subject | varchar(128) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| From | varchar(64) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| To | varchar(64) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| DateTime | datetime | NULL | YES | | 1901-01-01 01:01:
01 | | select,insert,update,references | |
| MessageId | varchar(128) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| AttachName | varchar(512) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| MailPath | varchar(255) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| HasRead | bit(1) | NULL | YES | |
| | select,insert,update,references | 是否阅读 |
+------------+--------------+-------------------+------+-----+------------------
---+----------------+---------------------------------+----------+
9 rows in set (0.03 sec)
mysql>
---------------------
老大们,再看一下。就是mailinfo里的subject中有中文,在到界面显示时都变成“问号”了。以上是检查的所有字符集设置,有什么问题没有??谢谢。
#19
我试图去改character_set_system 的字符设置也是gb2312,看能否把问题解决了。但是提示我说不能修改。不知道这个是不是我安装mysql是选择的默认字符集,不可以修改吗?
#20
) ENGINE=InnoDB DEFAULT CHARSET=gb2312
你的表中字符集是GB2312 不是UTF。
你的表中字符集是GB2312 不是UTF。
#21
set names 'GB2312'
试试
试试
#22
我要全部改成utf8吗?
#23
在哪里做这个操作?
#24
这个随你自己决定。
如果要改成UTF8的话,你需要把数据先导出,然后改表为UTF8后再导入。
如果要改成UTF8的话,你需要把数据先导出,然后改表为UTF8后再导入。
#25
老大直接说中文出来之后为什么变成问号了,问题出在哪里?
要做到哪些地方统一才不会出现中文变问号?我现在感觉自己上面用的都是gb2312编码啊,为什么还是问号呢?数据导不导无所谓,我现在库也只是测试用的,直接删除了都没关系。
接下来要怎么操作?哪些地方要统一,我不明白。说清楚关键点,这才是关键。
要做到哪些地方统一才不会出现中文变问号?我现在感觉自己上面用的都是gb2312编码啊,为什么还是问号呢?数据导不导无所谓,我现在库也只是测试用的,直接删除了都没关系。
接下来要怎么操作?哪些地方要统一,我不明白。说清楚关键点,这才是关键。
#26
#2楼 的贴子中已经解释得很清楚了。
#27
我按老大帖子说的重做了一个表,设置如下:
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.22-community-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
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.0\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.00 sec)
mysql> select * from test;
ERROR 1046 (3D000): No database selected
mysql> use mailreceiver;
Database changed
mysql> select * from test;
+----+---------------------------------------+
| Id | testchinese |
+----+---------------------------------------+
| 1 | so sosososoos右在夺得地在寺。so yuman |
+----+---------------------------------------+
1 row in set (0.00 sec)
mysql> show full columns from test;
+-------------+--------------+----------------+------+-----+---------+----------
------+---------------------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra
| Privileges | Comment |
+-------------+--------------+----------------+------+-----+---------+----------
------+---------------------------------+---------+
| Id | int(11) | NULL | NO | PRI | NULL | auto_incr
ement | select,insert,update,references | |
| testchinese | varchar(255) | gbk_chinese_ci | YES | | NULL |
| select,insert,update,references | |
+-------------+--------------+----------------+------+-----+---------+----------
------+---------------------------------+---------+
2 rows in set (0.00 sec)
mysql> show create table test;
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------+
| Table | Create Table
|
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------+
| test | CREATE TABLE `test` (
`Id` int(11) NOT NULL auto_increment,
`testchinese` varchar(255) default NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk |
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------+
1 row in set (0.00 sec)
mysql>
-------------------------------
然后我在VC中用如下语句去访问
const char* szTestSql = "select * from test";
if (!m_otldb.Open(szTestSql))
{
return;
}
while (!m_otldb.Eof())
{
std::string strOut = m_otldb.FieldbyName("testchinese").c_str();
}
得到的strOut的值是:so sosososoos????????so yuman
哪里错了? 为什么得到的中文变问号了。。。。。。。。。。。。。。。。。。。。。。。。。。
#28
谁能告诉一下,MS SQL Server的数据库是用的什么字符设置?在哪里看。我用上述一样的库表结构,一样的程序,使用MS SQL Server数据库时,显示中文是没问题的。
#29
我还做了如下测试:
当设置为'latin1'时查询出来的结果和我看到的结果一样的,问号。什么情况?
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10 to server version: 5.0.22-community-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------------------------------
-----+
| Variable_name | Value
|
+--------------------------+----------------------------------------------------
-----+
| character_set_client | utf8
|
| character_set_connection | utf8
|
| character_set_database | utf8
|
| character_set_filesystem | binary
|
| character_set_results | utf8
|
| character_set_server | utf8
|
| character_set_system | utf8
|
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.0\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.00 sec)
mysql> select * from test;
ERROR 1046 (3D000): No database selected
mysql> use mailreceiver;
Database changed
mysql> select * from test;
+----+-----------------------------------------------+
| Id | testchinese |
+----+-----------------------------------------------+
| 1 | so sosososoos鍙冲湪澶哄緱鍦板湪瀵恒€俿o yuman |
+----+-----------------------------------------------+
1 row in set (0.00 sec)
mysql> set names 'gbk';
Query OK, 0 rows affected (0.00 sec)
mysql> select * from test;
+----+---------------------------------------+
| Id | testchinese |
+----+---------------------------------------+
| 1 | so sosososoos右在夺得地在寺。so yuman |
+----+---------------------------------------+
1 row in set (0.00 sec)
mysql> set names 'gb2312';
Query OK, 0 rows affected (0.00 sec)
mysql> select * from test;
+----+---------------------------------------+
| Id | testchinese |
+----+---------------------------------------+
| 1 | so sosososoos右在夺得地在寺。so yuman |
+----+---------------------------------------+
1 row in set (0.00 sec)
mysql> set names 'latin1';
Query OK, 0 rows affected (0.00 sec)
mysql> select * from test;
+----+-------------------------------+
| Id | testchinese |
+----+-------------------------------+
| 1 | so sosososoos????????so yuman |
+----+-------------------------------+
1 row in set (0.00 sec)
mysql> set names 'gbk';
Query OK, 0 rows affected (0.00 sec)
mysql> select * from test;
+----+---------------------------------------+
| Id | testchinese |
+----+---------------------------------------+
| 1 | so sosososoos右在夺得地在寺。so yuman |
+----+---------------------------------------+
1 row in set (0.00 sec)
mysql>
当设置为'latin1'时查询出来的结果和我看到的结果一样的,问号。什么情况?
#30
就是你字符集不一样,导致乱码.你set names gbk,gb2312, 都可以正常显示中文;
你在程序里set names gb2312 取结果试试
你在程序里set names gb2312 取结果试试
#31
楼主解决没呢 继续顶啊 我也遇到同样的问题
#1
字符集问题,贴下你的show variables like 'character_set%';
输出的m_cTmp变量中变量指定下utf8 试试
输出的m_cTmp变量中变量指定下utf8 试试
#2
检查一下你的字符集设置。 可以参考下贴中的检查方法。
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 中文显示乱码
#3
mysql> show 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
|
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.0\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.02 sec)
mysql>
#4
要怎么设置呀?我已经贴出来了。以前没有用过mysql
#5
#2楼 的贴子你看了吗?其它检查结果呢?
#6
set names utf8 再导出;还有就是你的变量声明出来也设置成utf8;试试,
#7
我都设置成UTF8还是不行,输出还是乱码,而且重启mysql服务之后,character_set又变成原先的了。
#8
怎么设置啊?变量声明出来怎么设置成utf8?
#9
如
declare m_cTmp varchar(100) character set utf8;
declare m_cTmp varchar(100) character set utf8;
#10
数据库中现在显示的中文中正常的,只是用otl_stream流写到界面或者输出之后就变乱码了。
你说的是什么意思?m_cTmp我是在VC中定义的char[]变量。
你说的是什么意思?m_cTmp我是在VC中定义的char[]变量。
#11
看看
ACMAIN_CHM 老大给的地址 绝对有帮助。顺便告诉你一声。除了设置数据库 最好也罢变量也设置了类型
#12
就是需要给你的变量设置字符集;
#13
set names 'gbk'
#14
字符集问题,不统一
set names latin1
试试
在统一字符集的下重新插入记录
set names latin1
试试
在统一字符集的下重新插入记录
#15
都说的模凌两可。
#16
#17
在你的程序里set names 'latin1',再取结果看看。
#18
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 5.0.22-community-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mailreceiver |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use test;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> use mailreceiver;
Database changed
mysql> show tables;
+------------------------+
| Tables_in_mailreceiver |
+------------------------+
| mailaccount |
| mailinfo |
| servertable |
| test_tab |
+------------------------+
4 rows in set (0.00 sec)
mysql> show create table mailinfo;
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------+
| Table | Create Table
|
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------+
| mailinfo | CREATE TABLE `mailinfo` (
`Id` int(11) NOT NULL auto_increment,
`Subject` varchar(128) default '',
`From` varchar(64) default NULL,
`To` varchar(64) default NULL,
`DateTime` datetime default '1901-01-01 01:01:01',
`MessageId` varchar(128) default NULL,
`AttachName` varchar(512) default NULL,
`MailPath` varchar(255) default NULL,
`HasRead` bit(1) default '\0' COMMENT '是否阅读',
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312 |
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------+
1 row in set (0.05 sec)
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------------------------------
-----+
| Variable_name | Value
|
+--------------------------+----------------------------------------------------
-----+
| character_set_client | gb2312
|
| character_set_connection | gb2312
|
| character_set_database | gb2312
|
| character_set_filesystem | binary
|
| character_set_results | gb2312
|
| character_set_server | gb2312
|
| character_set_system | utf8
|
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.0\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.00 sec)
mysql> show full columns from mailinfo;
+------------+--------------+-------------------+------+-----+------------------
---+----------------+---------------------------------+----------+
| Field | Type | Collation | Null | Key | Default
| Extra | Privileges | Comment |
+------------+--------------+-------------------+------+-----+------------------
---+----------------+---------------------------------+----------+
| Id | int(11) | NULL | NO | PRI | NULL
| auto_increment | select,insert,update,references | |
| Subject | varchar(128) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| From | varchar(64) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| To | varchar(64) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| DateTime | datetime | NULL | YES | | 1901-01-01 01:01:
01 | | select,insert,update,references | |
| MessageId | varchar(128) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| AttachName | varchar(512) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| MailPath | varchar(255) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| HasRead | bit(1) | NULL | YES | |
| | select,insert,update,references | 是否阅读 |
+------------+--------------+-------------------+------+-----+------------------
---+----------------+---------------------------------+----------+
9 rows in set (0.03 sec)
mysql>
---------------------
老大们,再看一下。就是mailinfo里的subject中有中文,在到界面显示时都变成“问号”了。以上是检查的所有字符集设置,有什么问题没有??谢谢。
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 5.0.22-community-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mailreceiver |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use test;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> use mailreceiver;
Database changed
mysql> show tables;
+------------------------+
| Tables_in_mailreceiver |
+------------------------+
| mailaccount |
| mailinfo |
| servertable |
| test_tab |
+------------------------+
4 rows in set (0.00 sec)
mysql> show create table mailinfo;
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------+
| Table | Create Table
|
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------+
| mailinfo | CREATE TABLE `mailinfo` (
`Id` int(11) NOT NULL auto_increment,
`Subject` varchar(128) default '',
`From` varchar(64) default NULL,
`To` varchar(64) default NULL,
`DateTime` datetime default '1901-01-01 01:01:01',
`MessageId` varchar(128) default NULL,
`AttachName` varchar(512) default NULL,
`MailPath` varchar(255) default NULL,
`HasRead` bit(1) default '\0' COMMENT '是否阅读',
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312 |
+----------+--------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------------------------------------------------------+
1 row in set (0.05 sec)
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------------------------------
-----+
| Variable_name | Value
|
+--------------------------+----------------------------------------------------
-----+
| character_set_client | gb2312
|
| character_set_connection | gb2312
|
| character_set_database | gb2312
|
| character_set_filesystem | binary
|
| character_set_results | gb2312
|
| character_set_server | gb2312
|
| character_set_system | utf8
|
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.0\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.00 sec)
mysql> show full columns from mailinfo;
+------------+--------------+-------------------+------+-----+------------------
---+----------------+---------------------------------+----------+
| Field | Type | Collation | Null | Key | Default
| Extra | Privileges | Comment |
+------------+--------------+-------------------+------+-----+------------------
---+----------------+---------------------------------+----------+
| Id | int(11) | NULL | NO | PRI | NULL
| auto_increment | select,insert,update,references | |
| Subject | varchar(128) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| From | varchar(64) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| To | varchar(64) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| DateTime | datetime | NULL | YES | | 1901-01-01 01:01:
01 | | select,insert,update,references | |
| MessageId | varchar(128) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| AttachName | varchar(512) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| MailPath | varchar(255) | gb2312_chinese_ci | YES | | NULL
| | select,insert,update,references | |
| HasRead | bit(1) | NULL | YES | |
| | select,insert,update,references | 是否阅读 |
+------------+--------------+-------------------+------+-----+------------------
---+----------------+---------------------------------+----------+
9 rows in set (0.03 sec)
mysql>
---------------------
老大们,再看一下。就是mailinfo里的subject中有中文,在到界面显示时都变成“问号”了。以上是检查的所有字符集设置,有什么问题没有??谢谢。
#19
我试图去改character_set_system 的字符设置也是gb2312,看能否把问题解决了。但是提示我说不能修改。不知道这个是不是我安装mysql是选择的默认字符集,不可以修改吗?
#20
) ENGINE=InnoDB DEFAULT CHARSET=gb2312
你的表中字符集是GB2312 不是UTF。
你的表中字符集是GB2312 不是UTF。
#21
set names 'GB2312'
试试
试试
#22
我要全部改成utf8吗?
#23
在哪里做这个操作?
#24
这个随你自己决定。
如果要改成UTF8的话,你需要把数据先导出,然后改表为UTF8后再导入。
如果要改成UTF8的话,你需要把数据先导出,然后改表为UTF8后再导入。
#25
老大直接说中文出来之后为什么变成问号了,问题出在哪里?
要做到哪些地方统一才不会出现中文变问号?我现在感觉自己上面用的都是gb2312编码啊,为什么还是问号呢?数据导不导无所谓,我现在库也只是测试用的,直接删除了都没关系。
接下来要怎么操作?哪些地方要统一,我不明白。说清楚关键点,这才是关键。
要做到哪些地方统一才不会出现中文变问号?我现在感觉自己上面用的都是gb2312编码啊,为什么还是问号呢?数据导不导无所谓,我现在库也只是测试用的,直接删除了都没关系。
接下来要怎么操作?哪些地方要统一,我不明白。说清楚关键点,这才是关键。
#26
#2楼 的贴子中已经解释得很清楚了。
#27
我按老大帖子说的重做了一个表,设置如下:
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.22-community-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
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.0\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.00 sec)
mysql> select * from test;
ERROR 1046 (3D000): No database selected
mysql> use mailreceiver;
Database changed
mysql> select * from test;
+----+---------------------------------------+
| Id | testchinese |
+----+---------------------------------------+
| 1 | so sosososoos右在夺得地在寺。so yuman |
+----+---------------------------------------+
1 row in set (0.00 sec)
mysql> show full columns from test;
+-------------+--------------+----------------+------+-----+---------+----------
------+---------------------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra
| Privileges | Comment |
+-------------+--------------+----------------+------+-----+---------+----------
------+---------------------------------+---------+
| Id | int(11) | NULL | NO | PRI | NULL | auto_incr
ement | select,insert,update,references | |
| testchinese | varchar(255) | gbk_chinese_ci | YES | | NULL |
| select,insert,update,references | |
+-------------+--------------+----------------+------+-----+---------+----------
------+---------------------------------+---------+
2 rows in set (0.00 sec)
mysql> show create table test;
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------+
| Table | Create Table
|
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------+
| test | CREATE TABLE `test` (
`Id` int(11) NOT NULL auto_increment,
`testchinese` varchar(255) default NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk |
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------+
1 row in set (0.00 sec)
mysql>
-------------------------------
然后我在VC中用如下语句去访问
const char* szTestSql = "select * from test";
if (!m_otldb.Open(szTestSql))
{
return;
}
while (!m_otldb.Eof())
{
std::string strOut = m_otldb.FieldbyName("testchinese").c_str();
}
得到的strOut的值是:so sosososoos????????so yuman
哪里错了? 为什么得到的中文变问号了。。。。。。。。。。。。。。。。。。。。。。。。。。
#28
谁能告诉一下,MS SQL Server的数据库是用的什么字符设置?在哪里看。我用上述一样的库表结构,一样的程序,使用MS SQL Server数据库时,显示中文是没问题的。
#29
我还做了如下测试:
当设置为'latin1'时查询出来的结果和我看到的结果一样的,问号。什么情况?
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10 to server version: 5.0.22-community-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------------------------------
-----+
| Variable_name | Value
|
+--------------------------+----------------------------------------------------
-----+
| character_set_client | utf8
|
| character_set_connection | utf8
|
| character_set_database | utf8
|
| character_set_filesystem | binary
|
| character_set_results | utf8
|
| character_set_server | utf8
|
| character_set_system | utf8
|
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.0\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.00 sec)
mysql> select * from test;
ERROR 1046 (3D000): No database selected
mysql> use mailreceiver;
Database changed
mysql> select * from test;
+----+-----------------------------------------------+
| Id | testchinese |
+----+-----------------------------------------------+
| 1 | so sosososoos鍙冲湪澶哄緱鍦板湪瀵恒€俿o yuman |
+----+-----------------------------------------------+
1 row in set (0.00 sec)
mysql> set names 'gbk';
Query OK, 0 rows affected (0.00 sec)
mysql> select * from test;
+----+---------------------------------------+
| Id | testchinese |
+----+---------------------------------------+
| 1 | so sosososoos右在夺得地在寺。so yuman |
+----+---------------------------------------+
1 row in set (0.00 sec)
mysql> set names 'gb2312';
Query OK, 0 rows affected (0.00 sec)
mysql> select * from test;
+----+---------------------------------------+
| Id | testchinese |
+----+---------------------------------------+
| 1 | so sosososoos右在夺得地在寺。so yuman |
+----+---------------------------------------+
1 row in set (0.00 sec)
mysql> set names 'latin1';
Query OK, 0 rows affected (0.00 sec)
mysql> select * from test;
+----+-------------------------------+
| Id | testchinese |
+----+-------------------------------+
| 1 | so sosososoos????????so yuman |
+----+-------------------------------+
1 row in set (0.00 sec)
mysql> set names 'gbk';
Query OK, 0 rows affected (0.00 sec)
mysql> select * from test;
+----+---------------------------------------+
| Id | testchinese |
+----+---------------------------------------+
| 1 | so sosososoos右在夺得地在寺。so yuman |
+----+---------------------------------------+
1 row in set (0.00 sec)
mysql>
当设置为'latin1'时查询出来的结果和我看到的结果一样的,问号。什么情况?
#30
就是你字符集不一样,导致乱码.你set names gbk,gb2312, 都可以正常显示中文;
你在程序里set names gb2312 取结果试试
你在程序里set names gb2312 取结果试试
#31
楼主解决没呢 继续顶啊 我也遇到同样的问题