从来就没有救世主  也不靠神仙皇帝  要创造人类的幸福  全靠我们自己  

mysql 常用sql

 

常用

1. ip

(1)ipv4

  4字节,因此可用一个int存储

INET_ATON('127.0.0.1')   ip字符串转数字
INET_NTOA(xx)    数字转ip字符串

 

(2)ipv6

  16字节,需要两个bigint

 

2. unix时间戳

UNIX_TIMESTAMP()   以unix时间戳返回当前时间
FROM_UNIXTIME(xx) 将unix时间戳转换为普通格式时间

 

1、2:

  一个表,存储ip和时间:

CREATE TABLE table_fun (
    id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    ip INT(10) UNSIGNED NOT NULL DEFAULT 0,
    addtime INT(10) UNSIGNED NOT NULL DEFAULT 0
    );

  插入数据:

insert into table_fun(ip,addtime) values(inet_aton('192.168.1.1'),unix_timestamp());

  查询数据:

select inet_ntoa(ip),from_unixtime(addtime) from table_fun;

  

 

  

 

  删除数据:

delete from table_fun where inet_ntoa(ip)='192.168.1.0';

 

posted @ 2020-06-26 11:06  T,X  阅读(110)  评论(0编辑  收藏  举报