mysql相关操作笔记

一、数据迁移

(1)从源库10.x.x.x的表A的数据复制到目标库192.x.x.x的表B

-- 把源库的数据导出到本地磁盘
select * from table_A into outfile "/tmp/tmp.sql"

-- 目标库导入数据
load data infile "/tmp/tmp.sql" into table table_B;

-- 帮助文档
-- help select
-- help load data

 

 

二、日期相减

注意:直接使用now() - one_time得到的数字特别奇怪,不知道单位是什么。

-- 获取时间差,得到日期
select now(), begin_ts, timediff(now(), begin_ts) as duration from xx limit 1;
+---------------------+---------------------+----------+
| now()               | begin_ts            | duration |
+---------------------+---------------------+----------+
| 2017-03-10 17:26:10 | 2017-03-09 14:58:32 | 26:27:38 |
+---------------------+---------------------+----------+
1 row in set (0.00 sec)


-- 使用time_to_sec转换为秒
select now(), begin_ts, time_to_sec(timediff(now(), begin_ts)) as duration from x limit 1;
+---------------------+---------------------+----------+
| now()               | begin_ts            | duration |
+---------------------+---------------------+----------+
| 2017-03-10 17:27:04 | 2017-03-09 14:58:32 |    95312 |
+---------------------+---------------------+----------+
1 row in set (0.01 sec)



-- 方法二,直接转换成时间戳相减
select now(), begin_ts, unix_timestamp(now()) - unix_timestamp(begin_ts) as duration from x limit 1;                         
+---------------------+---------------------+----------+
| now()               | begin_ts            | duration |
+---------------------+---------------------+----------+
| 2017-03-10 17:28:33 | 2017-03-09 14:58:32 |    95401 |
+---------------------+---------------------+----------+
1 row in set (0.00 sec)

 

转载于:https://my.oschina.net/holton/blog/856341

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值