You're viewing a single post. I have much more to say! The main blog page is a good starting point.
Tuesday, January 23, 2007 ★ 23:48 ★ Category Programming
This is a simple howto to have MySQL talk UTF-8 (the One True Encoding in most cases) to all clients. I’ve read the MySQL manual about character encodings, and in the end it’s pretty simple to get it working:
CHARACTER SET 'UTF8' to each CREATE TABLE statement. Example: CREATE TABLE test (id SERIAL PRIMARY KEY, somefield VARCHAR(4)) CHARACTER SET 'UTF8';. This can be done at the database level as well (when using CREATE DATABASE), but most of the times this is done for you by an external party (hoster, sysadmins, ...)SET NAMES='UTF8'
That’s all. All data stored in and retrieved from MySQL is now in UTF-8. Make sure existing data is converted to UTF-8 as well before importing. I found the easiest way is to convert a database dump using a text editor (eg. :set encoding=utf8 in Vim) or a character set conversion utility such as iconv.
Random photo from Turkey (May, 2005)
Wouter Bolsterlee, also known as uws, a postmodern geek living in the Netherlands. Read more about me…
Unless stated otherwise, all material on this site is available under a Creative Commons Share-Alike license.