MySQL: Perform Case Sensitive string comparison

In this post, I am providing a small demonstration to perform case sensitive string comparison with MySQL.

For example, if you are searching string with LIKE ‘a%’, also you get all records of LIKE ‘A%’ because of case insensitive.
By default, string comparisons are case insensitive because strings are nonbinary. For the case sensitive comparison, we should use binary collation.

If you require to perform all string comparison operations with Case Sensitive, you can use this COLLATION latin1_bin.
You can visit this article about, How to change default COLLATION in MySQL.

The String Case Sensitive Comparison using LIKE BINARY:

You can also perform string case sensitive comparison using LIKE BINARY operator.
Generally, we require this kind of requirement during password comparison.

Below is a full demonstration of this:

First, create sample table and data,

Execute below three queries and check the result:

Using normal LIKE you will get Case insensitive result and using LIKE BINARY you will get Case sensitive result.

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from

Leave a Reply

1 Comment on "MySQL: Perform Case Sensitive string comparison"

Notify of
Sort by:   newest | oldest | most voted

Hi Patel..thanks for share really I like your post keep in touch from Indonesia.