Is there a way to force case sensitivity in MySQL / Rails for a single find?

后端 未结 3 1723
离开以前
离开以前 2021-02-09 02:11

I\'m doing some searching of tags, and some users like \"cat\" while others like \"Cat\" Go figure...

Anyways, is there a way to force a particular find to be case sens

3条回答
  •  我在风中等你
    2021-02-09 02:46

    In the mysql database, set your text's data type to utf_collate_bin. For example:

    ALTER TABLE `sets` CHANGE `set_name` `set_name` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
    

    Where 'sets' is the table, 'set_name' is the column of type VARCHAR(64). You can also do this in PhpMyAdmin..

    Any binary collate will do the job; but utf8 is preferable.

    If you were wondering what the _ci at the end of your current collate is, it means "Case Insensitive" :p

提交回复
热议问题