注意:是在Centos7上安装SQLAdvisor,必须是在没有安装MySQL的Centos7上安装,因为如果事先安装了MySQL,那么安装SQLAdvisor时,MySQL的/etc/my.cnf会与SQLAdvisor的依赖发生冲突。
下面记录下笔记吧:
1.克隆代码
#cd /usr/local/src/
#git clone https://github.com/Meituan-Dianping/SQLAdvisor.git
2.安装依赖包
#yum install -y make cmake libaio-devel libffi-devel glib2 glib2-devel bison gcc gcc-c++
3.编译sqladvisor时依赖perconaserverclient_r, 因此需要安装Percona-Server-shared-56。有可能需要配置软链接例如:
#cd /usr/lib64/
#ln -s libperconaserverclient_r.so.18 libperconaserverclient_r.so
4.安装percona56 yum源及安装:
#wget http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
#yum install percona-release-0.1-3.noarch.rpm -y
#yum install Percona-Server-shared-56 -y
5.编译sqladvisor的依赖项sqlparser(源码目录)
#cd /usr/local/src/SQLAdvisor/
#cmake -DBUILD_CONFIG=mysql_release -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=/usr/local/sqlparser -DIGNORE_AIO_CHECK=/usr/share/doc/libaio-0.3.109 ./
#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.用help查看使用方式
[root@localhost opt]# sqladvisor --help
用法:
sqladvisor [OPTION…] sqladvisor
SQL Advisor Summary
帮助选项:
-?, --help 显示帮助选项
应用程序选项:
-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
来源:oschina
链接:https://my.oschina.net/u/2518341/blog/1858275