C# mysql 插入数据 中文乱码解决方法

使用dapper 连接mysql 数据库的时候, 插入中文数据出现乱码。

可以通过执行下面SQL语句查看编码情况:

show variables like 'character%';

有两种解决方法:

方案一:

通过“set names”命令,修改client编码

MySQLCommand mCommand = new MySQLCommand("set names gb2312", m_Connection);

方案二:

连接字符串增加Charset=utf8;

string connectionString="server=127.0.0.1;UId=root;PassWord=root;Persist Security Info=True;database=test;Charset=utf8;";

猜你喜欢

转载自blog.csdn.net/gotowest123/article/details/112509937