how to search for exact string in mysql

后端 未结 5 1985
一整个雨季
一整个雨季 2020-12-08 22:36

I\'m trying to search for an exact match of a string in mysql. The string is \'nrew\'. But when I do the queries below, I still get a result:

SELECT UserID F         


        
5条回答
  •  一生所求
    2020-12-08 23:18

    The default collation which MySQL uses to make comparisons is case insensitive. You need to specify a case sensitive collation or binary. You can either do this when creating the column, or in the query.

    For example:

    SELECT UserID FROM sys_users WHERE UserID='NREW' COLLATE latin1_bin
    

    The proper collation depends on your character set. For latin1, the default, you can use latin1_bin. For utf8, utf8_bin.

提交回复
热议问题