MySQL diacritic insensitive search (spanish accents)

前端 未结 5 746
孤街浪徒
孤街浪徒 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:21

    Character sets & collations, not my favorites, but they DO work:

    mysql> SET NAMES latin1;
    mysql> SELECT 'lápiz' LIKE 'lapiz';
    +-----------------------+
    | 'lápiz' LIKE 'lapiz' |
    +-----------------------+
    |                     0 | 
    +-----------------------+
    1 row in set (0.01 sec)
    
    mysql> SET NAMES utf8;
    mysql> SELECT 'lápiz' LIKE 'lapiz';
    +-----------------------+
    | 'lápiz' LIKE 'lapiz' |
    +-----------------------+
    |                     1 | 
    +-----------------------+
    
    
    mysql> SET NAMES latin1;
    mysql> SELECT _utf8'lápiz' LIKE _utf8'lapiz' ;
    +---------------------------------+
    | _utf8'lápiz' LIKE _utf8'lapiz' |
    +---------------------------------+
    |                               1 | 
    +---------------------------------+
    

    A nice chapter to read in the manual:Character Set Support

提交回复
热议问题