MySQL Tables With UTF-8

Here is how to properly setup your database to store and query UTF-8 characters

1. You will need to make sure your tables are setup to store UTF-8 values.

e.g. show create table {tablename}; <– this will output table setup

If you see the ‘DEFAULT CHARSET=latin1′, then you will need to change it to ‘DEFAULT CHARSET=utf8′

e.g. alter table {table name} default charset utf8;

2. Now that we have setup all the tables to be able to store UTF8 characters, the next step is to display them from your script.

To properly display utf-8 characters, you will need to tell it that the output contains UTF-8 characters.

e.g. set names utf8;

The above command needs to be called before your ‘select’ statements. Otherwise, all you queries will return with a question (?) marks for any values that contain utf-8 characters.