我在 mysql 做了慢查询日志 /var/log/msyql/slow-queries.log现在要从这个巨大的文件(2g)中仅仅取最近2天的慢mysql ,问该如何取?

解决方案 »

  1.   

    没有好办法,你需要一些文本编辑工具,或者可以使用tail命令(UNIX)
      

  2.   

    WINDOWS下的,可以用MORE命令、
      

  3.   

     sed '1,/100901/d' file
      

  4.   

    Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]
    Parse and summarize the MySQL slow query log. Options are
      --verbose     verbose
      --debug       debug
      --help        write this text to standard output
      -v            verbose
      -d            debug
      -s ORDER      what to sort by (t, at, l, al, r, ar etc), 'at' is default
      -r            reverse the sort order (largest last instead of first)
      -t NUM        just show the top n queries
      -a            don't abstract all numbers to N and strings to 'S'
      -n NUM        abstract numbers with at least n digits within names
      -g PATTERN    grep: only consider stmts that include this string
      -h HOSTNAME  hostname of db server for *-slow.log filename (can be wildcard),
                    default is '*', i.e. match all
      -i NAME       name of server instance (if using mysql.server startup scrīpt)
      -l            don't subtract lock time from total time
    -s,是order的顺序,说明写的不够详细,俺用下来,包括看了代码,主要有 
    c,t,l,r和ac,at,al,ar,分别是按照query次数,时间,lock的时间和返回的记录数来排序,前面加了a的时倒叙 
    -t,是top n的意思,即为返回前面多少条的数据 
    -g,后边可以写一个正则匹配模式,大小写不敏感的 
      

  5.   

    sed -n '/# Time: 100901/,$p' file------------一行不掉 最好sed '1,/# Time : 100901/d' file  ------掉1行  可以用的awk '/^# Time: 100901/{T=1}T' file
    awk '/# Time: 100901/{T=1}T' file