mysql 中文乱码
mysql数据库中采用charset=latin1,C#读取时乱码
第一种方式:
1、连接字符串指定Charset=latin1
2、MySqlCommand先执行set names 'latin1',MySqlCommand cmd = new MySqlCommand("set names 'latin1'", connection);
cmd .ExecuteNonQuery();
3、读取时Encoding.UTF8.GetString(Encoding.GetEncoding("latin1").GetBytes(str));//把latin1字符读取bytes数组,然后采用UTF8编码读出来。
第二种方式:
mysql中转化latin1->UTF8
set names latin1;
create TEMPORARY table tmp(roleid int,rolename varchar(100));
insert into tmp
select roleid,name from table1
where account=in_account;
ALTER TABLE tmp MODIFY COLUMN rolename VARBINARY(50);
ALTER TABLE tmp MODIFY COLUMN rolename varchar(50) character set utf8;
set names utf8;
select roleid,rolename from tmp;
drop table tmp;
参考:
http://www.cnblogs.com/jishu/archive/2012/01/11/2318891.html
http://note.tc.edu.tw/399.html
http://www.cnblogs.com/fdyang/archive/2013/04/20/3032171.html
http://www.oschina.net/question/565065_86411
字节序问题
http://blog.csdn.net/yeh201111/article/details/8188646
http://blog.okbase.net/haobao/archive/25.html