我有一个带有 utf8_general_ci 编码的 mysql 数据库,
我正在使用 utf-8 页面和文件编码使用 php 连接到同一个数据库,没有问题,但是当使用 C# 连接 mysql 时,我有这样的字母غزة
我将连接字符串编辑为这样
server=localhost;password=root;User Id=root;Persist Security Info=True;database=mydatabase;Character Set=utf8
但同样的问题。
我有一个带有 utf8_general_ci 编码的 mysql 数据库,
我正在使用 utf-8 页面和文件编码使用 php 连接到同一个数据库,没有问题,但是当使用 C# 连接 mysql 时,我有这样的字母غزة
我将连接字符串编辑为这样
server=localhost;password=root;User Id=root;Persist Security Info=True;database=mydatabase;Character Set=utf8
但同样的问题。
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; CharSet=utf8;
笔记!使用小写值 utf8 而不是大写 UTF8,因为这将失败。
你能试试:
Server=localhost;Port=3306;Database=xxx;Uid=x xx;Pwd=xxxx;charset=utf8;"
编辑:我有一个新想法:
//To encode a string to UTF8 encoding
string source = "hello world";
byte [] UTF8encodes = UTF8Encoding.UTF8.GetBytes(source);
//get the string from UTF8 encoding
string plainText = UTF8Encoding.UTF8.GetString(UTF8encodes);
祝你好运
您可能需要为该列使用“utf8mb4”字符集以支持这样的 4 字节字符:“λ”
utf8 字符集仅支持每个字符 1-3 个字节,因此不能支持所有 unicode 字符。
有关详细信息,请参阅http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html 。
CHARSET 应该是大写的
Server=localhost;Port=3306;Database=xxx;Uid=x xx;Pwd=xxxx;CHARSET=utf8;
Just in case some come here later.
I needed to create a Seed method using Mysql with EF6, to load a SQL file. After running it I got weird characters on database like ? replacing é, ó, á
SOLUTION: Make sure I read the file using the right charset: UTF8 on my case.
var path = System.AppDomain.CurrentDomain.BaseDirectory;
var sql = System.IO.File.ReadAllText(path + "../../Migrations/SeedData/scripts/sectores.sql", Encoding.UTF8);
And then M.Shakeri reminder:
CHARSET=utf8 on cxn string in web.config. Using CHARSET as uppercase and utf8 lowercase.
Hope it helps.
R.
我发现但没有机会真正浏览的一件事是这里提供的整理图表:http: //www.collation-charts.org/mysql60/
这将向您显示哪些字符是给定 MySQL 排序规则的一部分,因此您可以为数据集选择最佳选项。
在连接字符串中设置字符集是指发送到服务器的查询的字符集。它不影响从服务器返回的结果。
https://dev.mysql.com/doc/connectors/en/connector-net-connection-options.html
我发现从客户端指定字符集的一种方法是在打开连接后运行它。
set character_set_results='utf8';