Question

Today I'm reported a confused problem by our QA that our app's log in feature ignores case condiersation, and by debuging backend code I found the following SQL scripts run with the same results(Our database has only one user with name of 'duno'):

SELECT * FROM T_USER WHERE username = 'duno';

and

SELECT * FROM T_USER WHERE username = 'DUNO';

Above 2 SQL scripts run with the same user record. I just get confused about that, what special settings to MySQL need I do? or other reasons?

Thanks in advance.

Was it helpful?

Solution

By default mysql query is case-insensitive.

To make it case sensitive use BINARY Keyword

SELECT * FROM T_USER WHERE BINARY username = 'duno';


Or

Instead of using the = operator, you use LIKE operator

SELECT * FROM T_USER WHERE username LIKE 'duno';

OTHER TIPS

By default MySQL does case insensitive search. You can either change your query or your table definition to make the searches case sensitive. Read more about it in MySQL documentation Case Sensitivity in String Searches.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top