Centos6下一键安装美团开源SQL优化工具SQLAdvisor脚本
https://github.com/aqzt/kjyw/blob/master/shell/sqladvisor.sh
Centos6下安装美团开源SQL优化工具SQLAdvisor具体安装步骤
1. SQLAdvisor安装
1.1 wget最新代码
wget https://github.com/Meituan-Dianping/SQLAdvisor/archive/master.zip
1.2 安装依赖项
yum install -y http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
yum install -y gcc-c++ make gcc httpd php mysql php-mysql php-devel php-pear libssh2 libssh2-devel unzip cmake libaio-devel libffi-devel glib2 glib2-devel Percona-Server-shared-56 bison libaio-devel ncurses-devel
注意
配置软链接,例如:
ln -s /usr/lib64/libperconaserverclient_r.so.18 /usr/lib64/libperconaserverclient_r.so
1.3 编译依赖项sqlparser
unzip SQLAdvisor.zip
cd SQLAdvisor-master
cmake -DBUILD_CONFIG=mysql_release -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=/usr/local/sqlparser ./
make && make install
1.4 安装SQLAdvisor源码
cd sqladvisor
cmake -DCMAKE_BUILD_TYPE=debug ./
make
cp sqladvisor /usr/bin/sqladvisor
在本路径下生成一个sqladvisor可执行文件,这即是我们想要的。
2. SQLAdvisor使用
2.1 –help输出
./sqladvisor –help
Usage:
sqladvisor [OPTION…] sqladvisor
SQL Advisor Summary
Help Options:
-?, –help Show help options
Application Options:
-f, –defaults-file sqls file
-u, –username username
-p, –password password
-P, –port port
-h, –host host
-d, –dbname database name
-q, –sqls sqls
-v, –verbose 1:output logs 0:output nothing
2.2 命令行传参调用
./sqladvisor -h xx -P xx -u xx -p ‘xx’ -d xx -q “sql” -v 1
#####注意:命令行传参时,参数名与值需要用空格隔开
2.3 配置文件传参调用
$> cat sql.cnf
[sqladvisor]
username=xx
password=xx
host=xx
port=xx
dbname=xx
sqls=sql1;sql2;sql3….
cmd: ./sqladvisor -f sql.cnf -v 1