10 May 2008

Uploading Chinese Text to MySQL database

In SQL Server, if you want to insert Chinese or other language character to a table, it was pretty simple, just specify the column type as NVARCHAR, and when you insert you can just use "N'chinese text here" but I found out that there's no such thing as NVARCHAR in MySQL database and hence this article.

To insert Chinese character:

  • Specify database character-set as UTF-8

  • Specify table or column collation set as UTF-8

  • In your web.config connection string, specify charset UTF-8
    e.g. <add name="MySqlConnString" connectionstring="server=IPAddress;userid=mysqluser;password=pa$$w0rd;database=mydb;pooling=false;charset=utf8 "/>

    This is to tell the application to use UTF-8 charset when talking to the database

No comments: