In a short: you need to create database which
supports unicode characters[
^]
Then you have to make some changes in your connection string:
- Treating Binary Blobs As UTF8[^]
- How to Make Unicode Available between C# and MySQL | Assemble Force[^]
Note: in both cases, a proper
connection string option[
^] must be respectively changed. For more details, follow the above links.
Warning: before you change anything in your database, create a backup!!!
Quote:
(...)
If you haven’t created the table, you can create one with the following statement.
CREATE TABLE IF NOT EXISTS (ID BIGINT NOT NULL PRIMARY KEY) ENGINE=MyIASM DEFAULT CHRACTER SET=utf8 COLLATE utf8_general_ci;
This statement will create a table with utf8
encoding and utf8_general_ci
as COLLATE
.
If you want to change the table to support utf8, you can follow the syntax below.
ALTER TABLE _table_name_ CHARACTER SET=UTF8 COLLATE=utf8_general_ci;
Connect to MySQL in C#
There are two point you must follow in order to connect to MySQL and access Unicode. The first step is to open the connection with "Charset=utf8"
, and the second step is to run the command with the connection "set names utf8"
. And the encoding is case sensitive, so you mustn’t write it like "UTF8"
or "utf-8"
.
string conn_str = "server=202.117.15.72;uid=username;pwd=password;database=wordbase;Charset=utf8;";
MySqlConnection conn = new MySqlConnection(connstr);
conn.Open();
MySqlCommand command = new MySqlCommand();
command.Connection = conn;
command.CommandText = "set names utf8";
command.ExecuteNonQuery();
With the steps done above, you can access MySQL with Unicode freely.
(...)