2015년 3월 12일 목요일

mysql/mariadb supports utf-8 encoding within DB tables, but it doesn't support UTF-8 in /etc/my.cnf???

A few weeks ago, I installed RHEL 6.6 and MariaDB 10.X at a client site but had problems running a DB install script. The message I got was

found option without preceding group in config file /etc/my.cnf at line 1

A google search for this snippet turned up the following StackOverflow thread:

http://stackoverflow.com/questions/8020297/mysql-my-cnf-file-found-option-without-preceding-group

Apparently, the /etc/my.cnf config file for mysql/mariadb only supports ASCII! This was quite a shock, because I know UTF-8 support is now built-into both databases.

I verified that /etc/my.cnf was indeed encoded as UTF-8 text using the file utility:

$ file /etc/my.cnf
/etc/my.cnf: utf-8

To convert text within a file from one encoding to another, use the iconv utility:

iconv -c -f utf8 -t ascii /etc/my.cnf

Explanation of the option flags (from man iconv):
-c   silently discard chars that cannot be converted instead of terminating when encountering such chars

-f   from-encoding

-t   to-encoding

In 2015, virtually all POSIX programs get along just fine with UTF8, so why does mysql/mariadb have a problem with UTF8 in my.cnf? This bit of techno-trivia has now been added to my growing body Linux sysadmin lore, but this should issue should be fixed, in my opinion.