原文地址:https://www.cnblogs.com/beliveli/articles/6541936.html
本机安装包路径: D:sharesrclinux-mysqlsqlAdvisor
1.克隆代码
git clone https://github.com/Meituan-Dianping/SQLAdvisor.git
2.安装依赖
yum install -y cmake libaio-devel libffi-devel glib2 glib2-devel bison
3.安装percona56
yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm -y
yum install Percona-Server-shared-56 -y
4.编译sqladvisor时依赖perconaserverclient_r, 因此需要安装Percona-Server-shared-56。有可能需要配置软链接例如:
cd /usr/lib64/
ln -s libperconaserverclient_r.so.18 libperconaserverclient_r.so
5. 编译sqladvisor的依赖项sqlparser
cd /usr/local/src/SQLAdvisor/
cmake -DBUILD_CONFIG=mysql_release -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=/usr/local/sqlparser ./
make && make install
6.正式编译sqladvisor(源码目录)
cd ./sqladvisor/
cmake -DCMAKE_BUILD_TYPE=debug ./
make
7.完成测试
cp /usr/local/src/SQLAdvisor/sqladvisor/sqladvisor /usr/bin/sqladvisor
sqladvisor -h 127.0.0.1 -P 3306 -u root -p '123456' -d test -q "sql语句" -v 1
8.简化命令
方式1:
在/etc/下新建sql.cnf
---------------------
[sqladvisor]
username=xxx
password=xxx
host=xxx
port=xxx
dbname=xxx
---------------------
sqladvisor -f /etc/sql.cnf -q "sql语句" -v 1
方式2:
[root@backup /opt/tools 12:01:44&&36]#cat /etc/sql.cnf
-------------------------
[sqladvisor]
username=root
password=xxxxxx
host=127.0.0.1
port=3306
dbname=application_serverdb
sqls=SELECT sap.id AS apId,tapt.todayPeak,taypt.todayPeak AS yestodayPeak,tampt.todayPeak AS monthPeak,talpt.todayPeak AS lastMonthPeak FROM spider_ap sap LEFT JOIN t_ap_today_peak_temp tapt ON sap.id = tapt.apId LEFT JOIN t_ap_yestoday_peak_temp taypt ON sap.id = taypt.apId LEFT JOIN t_ap_month_peak_temp tampt ON sap.id = tampt.apId LEFT JOIN t_ap_lastmonth_peak_temp talpt ON sap.id = talpt.apId WHERE sap.dev_id = 'iot_cq_13_17'
-------------------
sqladvisor -f /etc/sql.cnf -v 1