为什么SQL比较忽略大小写

时间:2019-08-01 14:43:13

标签: mysql sql sql-injection

我正在做一些sqli挑战(overthewire.org,natas Web应用程序挑战),在其中一个sqli挑战中,我遇到了以下问题。

当我比较substr(password,1,1)=“ a”时,它将忽略大小写。例如

Select * from users where username="user" and substr(password,1,1)='a'

将为真,

Select * from users where username="user" and substr(password,1,1)='A'

如果我使用

`Select * from users where username="user" and ascii(substr(password,1,1))=ascii('a')` 

相反,一切正常。

有人知道为什么要以这种方式实施吗?这是默认的mysql行为吗? 最好

1 个答案:

答案 0 :(得分:4)

简而言之,您可以指定数据库将使用的排序规则,并且最默认为不区分大小写的排序规则,因此在比较文本时它将忽略大小写。

https://dev.mysql.com/doc/refman/8.0/en/charset-general.html