MySQL diacritic insensitive search (spanish accents)

前端 未结 5 748
孤街浪徒
孤街浪徒 2020-11-29 07:48

I have a MySQL database with words containing accents in Spanish (áéíóú). I\'d like to know if there\'s any way to do a diacritic insensitive search. For instance, if I sear

5条回答
  •  天命终不由人
    2020-11-29 08:20

    If you set the table's charset to UTF-8 and the collation to utf8_*_ci (_ci means "case insensitive) MySQL will perform case and accent-insensitive searches by default

    Read more about charsets and collations here:
    http://dev.mysql.com/doc/refman/5.1/en/charset-charsets.html

    I tested it and

    "lapiz" matches: "lápiz," "lapíz," and "lapiz"
    "nino" matches: "niño," "ninó," and "nino"
    

    You can set up the collation of your table upon creation:

    CREATE TABLE table ( ... )
    CHARACTER SET uft8 COLLATE utf8_general_ci;
    

    Or you can ALTER it if it already exists.For more info, read the manual (link above).
    If you are using phpMyAdmin, you can select the collation when you create your table.

提交回复
热议问题