Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is MySQL treating é the same as e?
    primarykey
    data
    text
    <p>I'm storing Unicode strings in a MySQL database with a Django web application. I can store Unicode data fine, but when querying, I find that <code>é</code> and <code>e</code> are treated as if they were the same character:</p> <pre><code>In [1]: User.objects.filter(last_name='Jildén') Out[1]: [&lt;User: Anders Jildén&gt;] In [2]: User.objects.filter(last_name='Jilden') Out[2]: [&lt;User: Anders Jildén&gt;] </code></pre> <p>This is also the case when using the MySQL shell directly:</p> <pre><code>mysql&gt; select last_name from auth_user where last_name = 'Jildén'; +-----------+ | last_name | +-----------+ | Jildén | +-----------+ 1 row in set (0.00 sec) mysql&gt; select last_name from auth_user where last_name = 'Jilden'; +-----------+ | last_name | +-----------+ | Jildén | +-----------+ 1 row in set (0.01 sec) </code></pre> <p>Here are the database charset settings:</p> <pre><code>mysql&gt; SHOW variables LIKE '%character_set%'; +--------------------------+------------------------------------------------------+ | 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/local/Cellar/mysql/5.1.54/share/mysql/charsets/ | +--------------------------+------------------------------------------------------+ </code></pre> <p>here's the table schema:</p> <pre><code>CREATE TABLE `auth_user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(30) CHARACTER SET utf8 NOT NULL, `first_name` varchar(30) CHARACTER SET utf8 NOT NULL, `last_name` varchar(30) CHARACTER SET utf8 NOT NULL, `email` varchar(200) CHARACTER SET utf8 NOT NULL, `password` varchar(128) CHARACTER SET utf8 NOT NULL, `is_staff` tinyint(1) NOT NULL, `is_active` tinyint(1) NOT NULL, `is_superuser` tinyint(1) NOT NULL, `last_login` datetime NOT NULL, `date_joined` datetime NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB AUTO_INCREMENT=7952 DEFAULT CHARSET=utf8 COLLATE=utf8_bin </code></pre> <p>and here are the options I'm passing via Django's <code>DATABASES</code> setting:</p> <pre><code>DATABASES = { 'default': { # ... 'OPTIONS': { 'charset': 'utf8', 'init_command': 'SET storage_engine=INNODB;', }, }, } </code></pre> <p>Note that I have tried setting the table collation to <code>utf8_bin</code>, with no effect:</p> <pre><code>mysql&gt; alter table auth_user collate utf8_bin; mysql&gt; select last_name from auth_user where last_name = 'Jilden'; +-----------+ | last_name | +-----------+ | Jildén | +-----------+ 1 row in set (0.00 sec) </code></pre> <p>How can I get MySQL to treat these as different characters?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload