标签:lint -128 函数 数据存储 sel ipv6 timestamp 长度限制 时间戳
1.tinyint 1Bytes -128~127(255)
2.smallint 2Bytes -32768~32676(65535)
3.mdeiumint 3Bytes -8388608~8388607(16777215)
4.int 4Bytes -2147483648~2147483647(4294967295,42亿)
5.bigint 8Bytes -9223372036854775808~9223372036854775807(18446744073709551615)
int列如果是主键不能online DDL 转成bigint,onlineDDL:ptosc(更容易导致主从数据延时,执行过程报错,无法从上一个位置开始,只能重头开始)和gh-ost(推荐,因基于binlog,可以随时停止或继续).
int(11),11是修饰符,不是长度限制,int(8)zerofill zerofill也是修饰符,左侧补零.
cast(9223372036854775807 as unsigned) 改为不符号
select length(‘255.255.255.255‘)
+---------------------------+
| length(‘255.255.255.255‘) |
+---------------------------+
| 15 |
+---------------------------+
root@localhost [(none)]>select inet_aton(‘255.255.255.255‘); //IPv4最大值,正好是int的无符号数最大值.
+------------------------------+
| inet_aton(‘255.255.255.255‘) |
+------------------------------+
| 4294967295 |
+------------------------------+
root@localhost [(none)]>select inet_ntoa(4294967295);
+-----------------------+
| inet_ntoa(4294967295) |
+-----------------------+
| 255.255.255.255 |
+-----------------------+
唯一的原因是MySQL函数同时适用于IPv6和IPv4地址。 BINARY(16)只适用于存储IPv6地址,并保存一个字节。在处理IPv6和IPv4地址时应使用VARBINARY(16)):
root@localhost [(none)]>SELECT HEX(INET6_ATON(‘fdfe::5a55:caff:fefa:9089‘));
+----------------------------------------------+
| HEX(INET6_ATON(‘fdfe::5a55:caff:fefa:9089‘)) |
+----------------------------------------------+
| FDFE0000000000005A55CAFFFEFA9089 |
+----------------------------------------------+
1 row in set (0.00 sec)
root@localhost [(none)]>SELECT HEX(INET6_ATON(‘192.168.9.1‘));
+--------------------------------+
| HEX(INET6_ATON(‘192.168.9.1‘)) |
+--------------------------------+
| C0A80901 |
+--------------------------------+
1 row in set (0.00 sec)
mysql> SELECT INET6_NTOA(INET6_ATON(‘fdfe::5a55:caff:fefa:9089‘));
-> ‘fdfe::5a55:caff:fefa:9089‘
mysql> SELECT INET6_NTOA(INET6_ATON(‘192.168.9.1‘));
-> ‘192.168.9.1‘
mysql> SELECT INET6_NTOA(UNHEX(‘FDFE0000000000005A55CAFFFEFA9089‘));
-> ‘fdfe::5a55:caff:fefa:9089‘
mysql> SELECT INET6_NTOA(UNHEX(‘C0A80901‘));
-> ‘192.168.9.1‘
select unix_timestamp();
root@localhost [(none)]>select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
| 1539644023 |
+------------------+
1 row in set (0.00 sec)
root@localhost [(none)]>select from_unixtime(1539644023);
+---------------------------+
| from_unixtime(1539644023) |
+---------------------------+
| 2018-10-16 06:53:43 |
+---------------------------+
1 row in set (0.00 sec)
标签:lint -128 函数 数据存储 sel ipv6 timestamp 长度限制 时间戳
原文地址:https://www.cnblogs.com/2woods/p/9795811.html