Saturday, March 07, 2009

NonLatin symbols in MySQL

While developing my recent program in databases I found that my program on C# doesn't work correctly with onlatin chracters. It happend with recent version MySql.Data connector assembly from MySql. But there was no such problem when I've used old ByteFX.Data assembly. But old connector has some other error (at least when it works with server 5.2). After digesting a problem I found how to make my program work correctly with nonlatin characters. The solution is obvious: program must use a unicode, so here I'll show that to change in configurations of database and cliet software.
  1. Encoding of connection must be Unicode. For this in connection string add this parameter: CharSet=utf8;
  2. Encoding of database also must be Unicode. In my.cnf file following variables must be set to utf8: default-character-set and chracter-set-server
  3. However this helped me only on Linux machine, on Windows MySQL crashed after string with such prameters. So on Windows I found another possible solution: specify charset only for database: CREATE DATABASE dbName CHARACTER SET = utf8;. This solution is more flexible than previous because it affects only your database and not whole server.