How to deal with the memory overflow problem of MySQL integer data, mysql integer

Source: Internet
Author: User

How to deal with the memory overflow problem of MySQL integer data, mysql integer

Today, I received a call from a friend saying that the database was changed by someone else and the data was incorrect. After a long time of troubleshooting, the Data Type overflows (the problematic version is MySQL 5.1 ). Later, I upgraded MySQL 5.1 to MySQL 5.5 to solve this problem. This also makes me interested in learning about the processing mechanism of data overflow in different MySQL versions.

Let's take a look at the integer data and storage space supported by MySQL:

In addition, remember that mysql's data processing will be converted to bigint processing, so here we will use several bigint tests:

SELECTCAST(0ASUNSIGNED)-1; SELECT9223372036854775807+1;

MySQL 5.1:

mysql>SELECTCAST(0ASUNSIGNED)-1;+-------------------------+|CAST(0ASUNSIGNED)-1|+-------------------------+|18446744073709551615|+-------------------------+1ROWINSET(0.01 sec) mysql>SELECT9223372036854775807+1;+-------------------------+|9223372036854775807+1|+-------------------------+|-9223372036854775808|+-------------------------+1ROWINSET(0.01 sec)

MySQL 5.5, 5.6, 5.7:

mysql>SELECTCAST(0ASUNSIGNED)-1;ERROR 1690(22003): BIGINTUNSIGNEDVALUEISOUTOF range IN'(cast(0 as unsigned) - 1)'mysql> mysql> mysql> mysql>SELECT9223372036854775807+1;ERROR 1690(22003): BIGINTVALUEISOUTOF range IN'(9223372036854775807 + 1)'

When processing this type of data, you must be careful with the overflow. (For example, you can use this method to handle the problem in the early days)

This problem may result in point message, point addition, or some money-related businesses. The master database is 5.1, And the slave database MySQL is 5.5.
Suggestion: upgrade this type of business system to MySQL 5.5 or later.

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.