Today I was working on a CakePHP 2.1 project and when I was doing:

my result was coming with encoding errors.

As usual, I went to check de header layout, to be sure that I used UTF-8:

Then I checked the core.php to be sure it was defined with UTF-8:

Also checked the database connection at database.php to be sure it was using UTF-8:

Everything was ok on all files. What could it be then? The only possible reason was MySQL not being configured with utf-8 on table and fields…

To know that, I executed the following commands on MySQL console:

+————————–+—————————-+
| Variable_name | Value |
+————————–+—————————-+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+————————–+—————————-+

+———————-+——————-+
| Variable_name | Value |
+———————-+——————-+
| collation_connection | latin1_swedish_ci |
| collation_database | utf8_general_ci |
| collation_server | latin1_swedish_ci |
+———————-+——————-+

Founded my problem. There was some things to be configured with UTF-8. To do that configuration, just executed the command below on MySQL console:

example:

With that, managed to solve my encoding problem. Reminder: everything that was on latin1 needed a conversion to utf-8.

One thought on “MySQL encoding configuration

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.