How to deal with the memory overflow problem of Mysql integer data _mysql

Source: Internet
Author: User

Today, I received a call from a friend who said that the database was changed by others, and the problem of incorrect data appeared. After a long time, the data type has overflowed (the version of the problem is MySQL 5.1). Later, through the friend side of the MySQL 5.1 to upgrade to MySQL 5.5 to solve this problem. It also gives me an interest in understanding MySQL's handling mechanism for different versions of data type overflow.

First look at the number of integers supported by MySQL and size, storage space:

In addition, please remember that MySQL data processing will be turned into bigint processing, so here is a few bigint test:

Selectcast (0ASUNSIGNED)-1;
 
select9223372036854775807+1;

MySQL 5.1 under:

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 under:

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) '

Where the processing of such data is to be careful to overflow (such as early have to do the harm of the Q currency is to use this method to deal with)

This problem is likely to appear in the integration message, integral addition, or some money related to the business, the main library 5.1, from the library MySQL 5.5 situation will also be a problem of synchronization.
Recommendation: This kind of business system as far as possible upgrade to MySQL 5.5 version

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.