我用不小心用 mysql 的int(11) 存了用户的手机号,结果里面存的数据都是 10 位的,而且也不是单纯的被截断了一位, 比如手机号 18345231102 会被转成 4294967295 有办法恢复么,急。。。。。
问题补充: 1.数据库的存的手机号是类似这样的 511129633 437709550 947221024 1544096837 2770221786 3052396450 985251741 2147791994 1663290693 3067028521 842826454 2382976437 1811997122 2128974539 694514931 1816715878 876431887 737421250 1107794384 847325325
2.我问了下运维,是开了binlog 的,然后我跟他们要了一份。把里面所有的用户填手机号的sql的都找了出来,但是神奇的是sql里的手机号跟数据库里的是一样的,难道binlog里的sql是溢出之后的?
Sorry LZ, this answer is just as Sunyanzi pointed out, MySQL does not eat the high-order bytes but converts them to the maximum value of Int. Considering that the answer originally submitted took some effort to write, I will still leave it here. It may be helpful to other high-order byte overflow problems.
This is a bit interesting. The problem is that int has only 4 bytes, and the mobile phone number is an 11-digit decimal value composed of 5 bytes, so the highest 5th byte after converting to int is "eaten" ”, and then it fell apart.
Solution: Get the lost byte back. According to the current mobile phone number range of 130 0000 0000 to 189 9999 9999, the missing high-order byte may be 0x03 or 0x04. Therefore, adding 0x03 or 0x04, the restored value (Long type) conforms to the mobile phone number range/format, and the original value can be obtained. Remaining issues: It is possible that adding 0x03 and 0x04 both conforms to the mobile phone number range/format, and the result of adding 0x04 is taken (there is no way around it)
Okay, on to the code (Java) code:
There is no other way. The range of int is -2147483648~2147483647, and unsigned int, which is an unsigned integer, is twice the range of 0~4294967295.
If your data exceeds the limit, the computer will automatically calculate it based on maxinteger. To give a simple analogy - the USB flash drive is full and can no longer be inserted, but you didn't notice it at the time and it was useless when you found it later.
Unless you have external records or LOG such as the MYSQL script that saved the mobile phone number at that time, it is impossible to recover from yourself.
Have you opened bin-log?
According to the processing logic in the MySQL source code, if a number is greater than the maximum value (or less than the minimum value) of the field, the maximum value (or minimum value) will be returned during parsing, so it is impossible to analyze it from the number itself restored. But if your MySQL service has LOG enabled, recovery is possible.
The following is MySQL's integer parsing code Field_num::get_int(), from sql/field.cc 1130
It probably can’t be found, and even if it can be found, there’s no guarantee it’s correct
If the binlog is opened by default, mysql defaults to statement-based binlog, which means that the complete statement is saved and can be restored through binlog
Although Master Po is very tragic, this is a good question and leads to two good answers.