C#开发使用MySQL存储过程的中文乱码解决方法

设置MYSQL默认编码方式为UTF8

1.查看默认的编码格式:
mysql> show variables like "%char%";
+--------------------------+---------------+
| 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 |
+--------------------------+-------------+

2.如果遇到character_set_server为latin1的,可以通过修改my.ini解决

[mysql]
default-character-set=utf8

[mysqld]
character_set_server = utf8

设置完成后需要重启MySQL以便设置生效,命令:

net stop mysql

net start mysql

3.将数据编码格式保存为utf-8

设置数据库db_name默认为utf8:
ALTER DATABASE `db_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
设置表tb_name默认编码为utf8:
ALTER TABLE `tb_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

4.指定存储过程参数定义字符集:例如:in name char(50) character set utf8;

5.C#连接字符串设置编码方式:data source=127.0.0.1;database=test;uid=root;pwd=123456;Charset=utf8

 

 

posted @ 2013-08-14 10:25  TandyChan  阅读(670)  评论(0编辑  收藏  举报