mysql, space equals empty string
问题 Just took me 2 hours to troubleshoot an issue on my backend. Cause was that of empty string being equal to space: SELECT ' ' = ''; -> 1 SELECT STRCMP(' ', ''); -> 0 /* means equal */ Interestingly enough, SELECT '' REGEXP '[ ]'; -> 0 SELECT '' REGEXP ' '; -> 0 SELECT ' ' REGEXP ' '; -> 1 Can I prevent this? Is it a setting? 回答1: The reason this fails is explained in the docs here http://dev.mysql.com/doc/refman/5.0/en/char.html: Values in CHAR and VARCHAR columns are sorted and compared