常用命令

    指定配置文件

    1. # yaml format config file
    2. online-dsn:
    3. addr: 127.0.0.1:3306
    4. schema: sakila
    5. user: root
    6. disable: false
    7. test-dsn:
    8. addr: 127.0.0.1:3306
    9. schema: sakila
    10. user: root
    11. password: "1t'sB1g3rt"
    12. disable: false
    1. echo "select title from sakila.film" | ./soar -test-dsn="root:1t'sB1g3rt@127.0.0.1:3306/sakila" -allow-online-as-test -log-output=soar.log

    打印所有的启发式规则

    忽略某些规则

    1. $ soar -ignore-rules "ALI.001,IDX.*"
    1. $ soar -list-report-types

    以指定格式输出报告

    语法检查工具

    1. $ echo "select * from tb" | soar -only-syntax-check
    2. $ echo $?
    3. 0
    4. $ echo "select * fromtb" | soar -only-syntax-check
    5. At SQL 0 : syntax error at position 16 near 'fromtb'
    6. $ echo $?
    7. 1

    慢日志进行分析示例

    1. # parse pt-query-digest's output which example script
    2. $ python2.7 doc/example/digest_pt.py slow.log.digest > slow.md
    1. $ echo "select * from film where col='abc'" | soar -report-type=fingerprint
    1. select * from film where col=?

    将UPDATE/DELETE/INSERT语法转为SELECT

    合并多条ALTER语句

    1. $ echo "alter table tb add column a int; alter table tb add column b int;" | soar -report-type rewrite -rewrite-rules mergealter
    1. ALTER TABLE `tb` add column a int, add column b int ;

    SQL美化

    1. $ echo "select * from tbl where col = 'val'" | ./soar -report-type=pretty
    1. SELECT
    2. *
    3. FROM
    4. tbl
    5. WHERE
    6. col = 'val';
    1. $ soar -report-type explain-digest << EOF
    2. +----+-------------+-------+------+---------------+------+---------+------+------+-------+
    3. | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
    4. +----+-------------+-------+------+---------------+------+---------+------+------+-------+
    5. | 1 | SIMPLE | film | ALL | NULL | NULL | NULL | NULL | 1131 | |
    6. +----+-------------+-------+------+---------------+------+---------+------+------+-------+

    markdown转HTML

    1. $ cat test.md | soar -report-type md2html > test.html