Mysql implicit type conversion principle and mysql implicit Principle

Source: Internet
Author: User

Mysql implicit type conversion principle and mysql implicit Principle

MySQL implicit type conversion principle:

-If either of the two parameters is NULL, the comparison result is NULL. The exception is that when two NULL values are compared, 1 is returned. No type conversion is required in both cases.
-Both parameters are strings and will be compared by strings without type conversion.
-Both parameters are integers, which are compared by integers without type conversion.
-When the hexadecimal value is compared with a non-numeric value, it is treated as a binary string. When compared with a number, it is processed according to the following rule.
-If one parameter is TIMESTAMP or DATETIME and the other parameter is a constant, the constant is converted to timestamp.
-One parameter is of the decimal type. If another parameter is of the decimal or Integer type, the integer is converted to a decimal type before comparison. If the other parameter is of the floating point type, converts decimal to a floating point number for comparison.
-In all other cases, the two parameters are converted to floating point numbers for comparison.

Note a security question: if the password type is string and the query condition is int 0, it will match.

Because the implicit conversion rules of MySQL are complex, it is easy to encounter unexpected problems depending on MySQL implicit conversion. MySQL implicit conversion itself is also very expensive for MySQL server performance, therefore, this is not recommended.

 

See blog: http://www.cnblogs.com/rollenholt/p/5442825.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.