数据库中字符如下:
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 | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set
vb.net中代码如下:
Dim mSQLcomm As MySqlCommand = New MySqlCommand("set names gb2312", mySQLconn)
中文乱码解决不掉
11 个解决方案
#1
数据库里面的数据本身是乱码?所以你取的结果是乱码?
#2
写入数据库时已经乱码了,,,
写入数据库时已经乱码了,,,读取时不知道哪里乱的
#3
问了一下同事,如果是写入乱码,然后在程序里面转码的话还是转不出来的,所以,这个责任的划分到那个写入数据的人身上了。
#4
这个是我自己写入的。。。我想知道怎么解决
#5
同一个数据库,运行下面这条命令和上午1楼时运行的结果不一样??为什么呢
请对照1楼参考
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set
请对照1楼参考
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set
#6
在.net连接 mysql 的连接串中 加上CharSet=utf8 试试,
这个需要在在连接串中指定
这个需要在在连接串中指定
#7
我将
MySqlConnection="server=192.168.10.10;user id=root;password=123456;database=;charset=utf8"
数据库连接没有问题,乱码的问题还是没解决
#8
mysql数据库:
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set
表:
mysql> show create table mailbox;
| Table | Create Table | mailbox | CREATE TABLE `mailbox` (
`username` varchar(255) NOT NULL default '',
`question` text NOT NULL,
`answer` text NOT NULL,
`autoreply` smallint(1) default NULL,
`autoreplycontent` text,
PRIMARY KEY (`username`),
KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Mailboxes' |
程序部分:
MySqlConnection="server=192.168.10.10;user id=root;password=123456;database=;charset=utf8"
现在我使用.net向mysql写入数据,然后读取,但是写入数据库的中文字符乱码,读取时也乱码,都为"?",英文和数字没事
原因是什么呢?
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set
表:
mysql> show create table mailbox;
| Table | Create Table | mailbox | CREATE TABLE `mailbox` (
`username` varchar(255) NOT NULL default '',
`question` text NOT NULL,
`answer` text NOT NULL,
`autoreply` smallint(1) default NULL,
`autoreplycontent` text,
PRIMARY KEY (`username`),
KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Mailboxes' |
程序部分:
MySqlConnection="server=192.168.10.10;user id=root;password=123456;database=;charset=utf8"
现在我使用.net向mysql写入数据,然后读取,但是写入数据库的中文字符乱码,读取时也乱码,都为"?",英文和数字没事
原因是什么呢?
#9
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;" +
"DATABASE=rebook;" +
"UID=root;" +
"PASSWORD=qwe123;" +
"OPTION=3;CharSet=gbk;";
连接串改成这样看看,这是我以前使用的,不会出现乱码
#10
这是因为数据库里面的中文不是utf8,mysql早期的工具有这个问题,你去mysql官网下一个最新MySQL,我记得是5.6版,这个问题就解决了
#11
自己完成了
http://bbs.csdn.net/topics/390398251
http://bbs.csdn.net/topics/390398251
#1
数据库里面的数据本身是乱码?所以你取的结果是乱码?
#2
写入数据库时已经乱码了,,,
写入数据库时已经乱码了,,,读取时不知道哪里乱的
#3
问了一下同事,如果是写入乱码,然后在程序里面转码的话还是转不出来的,所以,这个责任的划分到那个写入数据的人身上了。
#4
这个是我自己写入的。。。我想知道怎么解决
#5
同一个数据库,运行下面这条命令和上午1楼时运行的结果不一样??为什么呢
请对照1楼参考
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set
请对照1楼参考
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set
#6
在.net连接 mysql 的连接串中 加上CharSet=utf8 试试,
这个需要在在连接串中指定
这个需要在在连接串中指定
#7
我将
MySqlConnection="server=192.168.10.10;user id=root;password=123456;database=;charset=utf8"
数据库连接没有问题,乱码的问题还是没解决
#8
mysql数据库:
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set
表:
mysql> show create table mailbox;
| Table | Create Table | mailbox | CREATE TABLE `mailbox` (
`username` varchar(255) NOT NULL default '',
`question` text NOT NULL,
`answer` text NOT NULL,
`autoreply` smallint(1) default NULL,
`autoreplycontent` text,
PRIMARY KEY (`username`),
KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Mailboxes' |
程序部分:
MySqlConnection="server=192.168.10.10;user id=root;password=123456;database=;charset=utf8"
现在我使用.net向mysql写入数据,然后读取,但是写入数据库的中文字符乱码,读取时也乱码,都为"?",英文和数字没事
原因是什么呢?
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set
表:
mysql> show create table mailbox;
| Table | Create Table | mailbox | CREATE TABLE `mailbox` (
`username` varchar(255) NOT NULL default '',
`question` text NOT NULL,
`answer` text NOT NULL,
`autoreply` smallint(1) default NULL,
`autoreplycontent` text,
PRIMARY KEY (`username`),
KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Mailboxes' |
程序部分:
MySqlConnection="server=192.168.10.10;user id=root;password=123456;database=;charset=utf8"
现在我使用.net向mysql写入数据,然后读取,但是写入数据库的中文字符乱码,读取时也乱码,都为"?",英文和数字没事
原因是什么呢?
#9
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;" +
"DATABASE=rebook;" +
"UID=root;" +
"PASSWORD=qwe123;" +
"OPTION=3;CharSet=gbk;";
连接串改成这样看看,这是我以前使用的,不会出现乱码
#10
这是因为数据库里面的中文不是utf8,mysql早期的工具有这个问题,你去mysql官网下一个最新MySQL,我记得是5.6版,这个问题就解决了
#11
自己完成了
http://bbs.csdn.net/topics/390398251
http://bbs.csdn.net/topics/390398251