read/write unicode data in MySql

前端 未结 4 1845
心在旅途
心在旅途 2020-12-03 21:54

I am using MySql DB and want to be able to read & write unicode data values. For example, French/Greek/Hebrew values.

My client program is C# (.NET framework 3.

相关标签:
4条回答
  • 2020-12-03 22:15

    The Solution!

    OK, so for C# client to read & write unicode values, you must include in the connection string: charset=utf8

    for example: server=my_sql_server;user id=my_user;password=my_password;database=some_db123;charset=utf8;

    of course you should also define the relevant table as utf8 + collation utf8_bin.

    0 讨论(0)
  • 2020-12-03 22:16

    You have to set the collation for your MySQL schema, tables or even columns.

    Most of the time, the utf8_general_ci collation is used because it is case insensitive and accent insensitive comparisons.

    On the other hand, utf8_unicode_ci is case sensitive and uses more advanced sorting technics (like sorting eszet ('ß') near 'ss'). This collation is a tiny bit slower than the other two.

    Finally, utf8_bin compares string using their binary value. Thus, it also is case sensitive.

    If you're using MySQL's Connector/NET (which I recommend), everything should go smoothly.

    0 讨论(0)
  • 2020-12-03 22:32

    try to use this query before any other fetch or send:

    SET NAMES UTF8
    
    0 讨论(0)
  • 2020-12-03 22:33

    You need to set the db charset to UTF-8 (if you are using utf-8), collation for relevant tables/fields to utf, execute SET NAMES 'UTF-8' before doing queries, and of course make sure you set the proper encoding in the html that is showing the output.

    0 讨论(0)
提交回复
热议问题