新之助meow

Kratos
专注于用户阅读体验的响应式博客主题
  1. 首页
  2. 未分类
  3. 正文

关于mysql 支持毫秒时间和全局查询日志记录毫秒时间

2017年9月21日 558点热度 0人点赞 0条评论

mysql 5.6.4开始可以通过
定义datetime(6) timestamp(6) 列,这种方式来打开时间对毫秒的支持
使用函数 CURRENT_TIMESTAMP(6) now(6) 来生成带毫秒的时间

参考
Why doesn't MySQL support millisecond / microsecond precision?
Date and Time Functions

mysql 5.6的全局日志记录的时间没有毫秒,无法详细分析sql的执行时间。mysql 5.7就有毫秒了
1尝试修改表结构将时间列改为 timestamp(6) ,但插入的时间的毫秒都是000,不管用。
2尝试添加一列timestamp(6) 设置默认值,也不行,mysql errorlog里报错了。
3尝试添加触发器修改插入表时的时间,报错,系统表不能添加触发器

delimiter $$
create trigger general_log_tr before insert
on mysql.general_log for each row
begin
set new.event_time=now(6);
end
$$
delimiter ;

参考
MySQL触发器
MySQL的学习--触发器
https://github.com/wvanbergen/request-log-analyzer

4把日志改回输出到文件,通过tail 捕获文件改动然后给日志添加一列时间

tail -f tjdfdb.log|perl -M'POSIX qw(strftime setsid)' -M'Time::HiRes qw(gettimeofday)'  -nle 'BEGIN{setsid();$SIG{CHLD} = "IGNORE";}($sec,$milli)=gettimeofday;$tm=strftime("%Y-%m-%d %H:%M:%S",localtime($sec)).".".$milli;$dt=substr($tm,0,10);print $tm."\t$_";'>/data/sqllog.txt

标签: 暂无
最后更新:2017年9月21日

tjccn_wx@hotmail.com

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

归档

  • 2026 年 10 月
  • 2024 年 2 月
  • 2023 年 7 月
  • 2023 年 1 月
  • 2022 年 10 月
  • 2022 年 9 月
  • 2022 年 6 月
  • 2022 年 4 月
  • 2022 年 3 月
  • 2022 年 2 月
  • 2021 年 11 月
  • 2021 年 10 月
  • 2021 年 9 月
  • 2021 年 1 月
  • 2020 年 12 月
  • 2020 年 11 月
  • 2020 年 10 月
  • 2020 年 9 月
  • 2020 年 7 月
  • 2020 年 6 月
  • 2020 年 5 月
  • 2020 年 4 月
  • 2020 年 3 月
  • 2020 年 2 月
  • 2019 年 10 月
  • 2019 年 8 月
  • 2019 年 7 月
  • 2019 年 4 月
  • 2019 年 3 月
  • 2018 年 12 月
  • 2018 年 11 月
  • 2018 年 10 月
  • 2018 年 6 月
  • 2018 年 5 月
  • 2018 年 4 月
  • 2018 年 3 月
  • 2018 年 2 月
  • 2018 年 1 月
  • 2017 年 12 月
  • 2017 年 11 月
  • 2017 年 10 月
  • 2017 年 9 月
  • 2017 年 8 月
  • 2017 年 7 月
  • 2017 年 6 月
  • 2017 年 5 月
  • 2017 年 4 月
  • 2017 年 3 月
  • 2017 年 2 月
  • 2017 年 1 月
  • 2016 年 12 月
  • 2016 年 11 月
  • 2016 年 10 月
  • 2016 年 9 月
  • 2016 年 8 月
  • 2016 年 7 月
  • 2016 年 6 月
  • 2016 年 5 月
  • 2016 年 4 月
  • 2016 年 3 月
  • 2015 年 12 月
  • 2015 年 8 月

分类

  • android
  • mysql
  • nethunter
  • proxmark
  • 未分类

COPYRIGHT © 2026 新之助meow. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang