Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL considers 'е' and 'ё' equal, how do I set it to consider them different?

Tags:

mysql

I have a table with a unique constraint on a varchar field. When I try to insert 'e' and 'ё' in two different rows I'm prompted with a unique constraint violation. Executing the following select shows that MySQL considers the letters equivalent in spite of their HEX values being D0B5 and D191 respectively.

select  'е' = 'ё',
        hex('е'),
        hex('ё');

Following a fair amount of Googling I came across this MySQL bug report which seems to deal with this issue. The very last response by Sveta Smirnova states that this behavior is by design and refers to the Collation chart for utf8_unicode_ci, European alphabets (MySQL 6.0.4).

How do I tell MySQL that 'е' is not equal to 'ё' for query purposes and how do I change the unique constraint to take note of this fact?

like image 894
Frank Avatar asked Aug 13 '14 22:08

Frank


People also ask

How do I change the value of a column in MySQL?

The syntax to modify a column in a table in MySQL (using the ALTER TABLE statement) is: ALTER TABLE table_name MODIFY column_name column_definition [ FIRST | AFTER column_name ]; table_name. The name of the table to modify.

How many triggers are possible in MySQL?

There are 6 different types of triggers in MySQL: 1. Before Update Trigger: As the name implies, it is a trigger which enacts before an update is invoked.

Does between include endpoints MySQL?

MySQL's BETWEEN includes all results between two endpoints as well as the endpoints.

What is into Outfile?

INTO OUTFILE is the complement of LOAD DATA . Column values are written converted to the character set specified in the CHARACTER SET clause. If no such clause is present, values are dumped using the binary character set. In effect, there is no character set conversion.

What is equal operator in MySQL with example?

equal operator. MySQL equal operator performs an equality comparison. Syntax: =. MySQL Version: 5.6. Example: MySQL equal operator. The following MySQL statement checks if 1 is equal to 1, if 1 is equal to 2, if NULL is equal to NULL, if NULL is equal to 3 and if 3 is equal to .

How to test for greater than or equal to in MySQL?

In MySQL, you can use the >= operator to test for an expression greater than or equal to. In this example, the SELECT statement would return all rows from the contacts table where the contact_id is greater than or equal to 50. In this case, contact_id equal to 50 would be included in the result set.

How do I test for equality in a MySQL Query?

In MySQL, you can use the = operator to test for equality in a query. The = operator can only test equality with values that are not NULL.

How to use where clause with equal to in MySQL?

A WHERE clause with the ‘equal to’ sign (=) works fine where we want to do an exact match. Like if "tutorial_author = 'Sanjay'". But there may be a requirement where we want to filter out all the results where the tutorial_author name should contain "jay". This can be handled using MySQL LIKE operator along with the WHERE clause.


2 Answers

You may wish to check this answer: Is it possible to remove mysql table collation?

The behavior you're seeing is standard. In most cases it produces the best results. From a point of interest do you have an example of how this is causing a problem for you. Have you found two words which match except for the diacritic?

Either way the only thing you can do about it is to change the collation. This can be done at the server, database, table or even field level.

Rather than my duplicating the manual on how to do this; please follow this link: http://dev.mysql.com/doc/refman/5.7/en/charset-syntax.html

There's a listing here of the different collations supported: http://dev.mysql.com/doc/refman/5.5/en/charset-charsets.html

like image 122
Philip Couling Avatar answered Oct 15 '22 03:10

Philip Couling


If you need that for an especific field you could add a duplicate of the column with a different collation for prevent this issue.

ALTER TABLE yourTable ADD COLUMN `copiedColumn` VARCHAR(100) CHARACTER SET 'binary' COLLATE 'binary';

Also, you can change the collation of your column if you don't need the your current collation in this field

ALTER TABLE yourTable CHANGE COLUMN yourColumn yourColumn VARCHAR(100) CHARACTER SET 'binary' COLLATE 'binary';

like image 31
JCalcines Avatar answered Oct 15 '22 03:10

JCalcines