常用命令
指定配置文件
# yaml format config file
online-dsn:
addr: 127.0.0.1:3306
schema: sakila
user: root
disable: false
test-dsn:
addr: 127.0.0.1:3306
schema: sakila
user: root
password: "1t'sB1g3rt"
disable: false
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
打印所有的启发式规则
忽略某些规则
$ soar -ignore-rules "ALI.001,IDX.*"
$ soar -list-report-types
以指定格式输出报告
语法检查工具
$ echo "select * from tb" | soar -only-syntax-check
$ echo $?
0
$ echo "select * fromtb" | soar -only-syntax-check
At SQL 0 : syntax error at position 16 near 'fromtb'
$ echo $?
1
慢日志进行分析示例
# parse pt-query-digest's output which example script
$ python2.7 doc/example/digest_pt.py slow.log.digest > slow.md
$ echo "select * from film where col='abc'" | soar -report-type=fingerprint
select * from film where col=?
将UPDATE/DELETE/INSERT语法转为SELECT
合并多条ALTER语句
$ echo "alter table tb add column a int; alter table tb add column b int;" | soar -report-type rewrite -rewrite-rules mergealter
ALTER TABLE `tb` add column a int, add column b int ;
SQL美化
$ echo "select * from tbl where col = 'val'" | ./soar -report-type=pretty
SELECT
*
FROM
tbl
WHERE
col = 'val';
$ soar -report-type explain-digest << EOF
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| 1 | SIMPLE | film | ALL | NULL | NULL | NULL | NULL | 1131 | |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
markdown转HTML
$ cat test.md | soar -report-type md2html > test.html