ef 操作 mysql 中文乱码问题
1.保证mysql数据的编码为utf8
启动mysql
mysql -hlocalhost -uroot -p
输入密码
show VARIABLES like 'character_%';
SET character_set_client='utf8';
SET character_set_connection='utf8';
SET character_set_results='utf8';
2.已经生成数据库的,注意数据库的collation,表的collation,以及表中字符串列的collation都要为utf8
2.在EF连接字符串中添加Character Set=utf8
- <connectionStrings>
- <add name="MyContext"
- connectionString="Server=127.0.0.1;port=3306;Database=xxx;uid=xxx;pwd=xxx;Character Set=utf8;"
- providerName="MySql.Data.MySqlClient"/>
- </connectionStrings>