Ubuntu 美团sql优化工具SQLAdvisor的安装(转)

            <!-- 文章主体部分 -->
            <!-- <div class="media-body participation-body question col-md-8"> -->
            <div class="media-body participation-body question col-md-8">

                <div class="media-heading" style="display:none;"><!-- 文章作者及发表时间信息 -->
                    <h5 class="participation__name">
                        <a href="https://www.by2009.com/user/profile/1.html">by2009</a>
                    </h5>
                    <span class="participation-body-date">
                        发表于 3 个月前                        </span>
                </div>

                <p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; white-space: normal;"><strong>SQLAdvisor简介</strong></p><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; white-space: normal;"><span style="font-family: sans-serif;">SQLAdvisor是由美团点评公司技术工程部DBA团队(北京)开发维护的一个分析SQL给出索引优化建议的工具。它基于MySQL原生态词法解析,结合分析SQL中的where条件、聚合条件、多表Join关系 给出索引优化建议。目前SQLAdvisor在美团点评内部广泛应用,公司内部对SQLAdvisor的开发全面转到github上,开源和内部使用保持一致,主要功能:输出SQL索引优化建议,<a href="https://github.com/Meituan-Dianping/SQLAdvisor" target="_blank">github地址</a></span></p><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(36, 41, 46); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; white-space: normal;"><span style="font-family: sans-serif;">下边记录一下在ubuntu 上安装的过程<br></span></p><table border="0" cellpadding="0" cellspacing="0" class="syntaxhighlighter  bash"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="bash comments">#系统信息</code></div><div class="line number2 index1 alt1"><code class="bash plain">root@d:~</code><code class="bash plain">/SQLAdvisor/sqladvisor</code><code class="bash comments">#&nbsp;uname&nbsp;-a</code></div><div class="line number3 index2 alt2"><code class="bash plain">Linux&nbsp;d&nbsp;3.13.0-32-generic&nbsp;</code><code class="bash comments">#57-Ubuntu&nbsp;SMP&nbsp;Tue&nbsp;Jul&nbsp;15&nbsp;03:51:08&nbsp;UTC&nbsp;2014&nbsp;x86_64&nbsp;x86_64&nbsp;x86_64&nbsp;GNU/Linux</code></div></div></td></tr></tbody></table><p><br></p><p><strong>1、拉取代码</strong></p><table border="0" cellpadding="0" cellspacing="0" class="syntaxhighlighter  bash"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="bash plain">git&nbsp;clone&nbsp;https:</code><code class="bash plain">//github</code><code class="bash plain">.com</code><code class="bash plain">/Meituan-Dianping/SQLAdvisor</code><code class="bash plain">.git</code></div></div></td></tr></tbody></table><p><strong>2、安装依赖项</strong></p><table border="0" cellpadding="0" cellspacing="0" class="syntaxhighlighter  bash"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="bash plain">apt-get&nbsp;</code><code class="bash functions">install</code>&nbsp;<code class="bash plain">cmake&nbsp;libaio-dev&nbsp;libffi-dev</code></div><div class="line number2 index1 alt1"><code class="bash plain">apt-get&nbsp;</code><code class="bash functions">install</code>&nbsp;<code class="bash plain">libglib2.0-dev</code></div><div class="line number3 index2 alt2"><code class="bash plain">apt-get&nbsp;</code><code class="bash functions">install</code>&nbsp;<code class="bash plain">libperconaserverclient18.1-dev</code></div><div class="line number4 index3 alt1"><code class="bash plain">apt-get&nbsp;</code><code class="bash functions">install</code>&nbsp;<code class="bash plain">g++</code></div></div></td></tr></tbody></table><p>percona的安装参考&nbsp;<a href="https://www.percona.com/doc/percona-server/5.6/installation/apt_repo.html" _src="https://www.percona.com/doc/percona-server/5.6/installation/apt_repo.html">https://www.percona.com/doc/percona-server/5.6/installation/apt_repo.html</a> </p><table border="0" cellpadding="0" cellspacing="0" class="syntaxhighlighter  bash"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="bash plain">wget&nbsp;https:</code><code class="bash plain">//repo</code><code class="bash plain">.percona.com</code><code class="bash plain">/apt/percona-release_0</code><code class="bash plain">.1-4.$(lsb_release&nbsp;-sc)_all.deb</code></div><div class="line number2 index1 alt1"><code class="bash plain">dpkg&nbsp;-i&nbsp;percona-release_0.1-4.$(lsb_release&nbsp;-sc)_all.deb</code></div><div class="line number3 index2 alt2"><code class="bash plain">apt-get&nbsp;update</code></div><div class="line number4 index3 alt1"><code class="bash plain">apt-get&nbsp;</code><code class="bash functions">install</code>&nbsp;<code class="bash plain">percona-server-server-5.7</code></div></div></td></tr></tbody></table><p><strong>3、编译依赖项sqlparser</strong></p><table border="0" cellpadding="0" cellspacing="0" class="syntaxhighlighter  bash"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="bash plain">cmake&nbsp;-DBUILD_CONFIG=mysql_release&nbsp;-DCMAKE_BUILD_TYPE=debug&nbsp;-DCMAKE_INSTALL_PREFIX=</code><code class="bash plain">/usr/local/sqlparser</code>&nbsp;<code class="bash plain">./</code></div><div class="line number2 index1 alt1"><code class="bash functions">make</code>&nbsp;<code class="bash plain">&amp;&amp;&nbsp;</code><code class="bash functions">make</code>&nbsp;<code class="bash functions">install</code></div></div></td></tr></tbody></table><p><strong>4、编译安装SQLAdvisor源码</strong></p><table border="0" cellpadding="0" cellspacing="0" class="syntaxhighlighter  bash"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="bash functions">cd</code>&nbsp;<code class="bash plain">SQLAdvisor</code><code class="bash plain">/sqladvisor/</code></div><div class="line number2 index1 alt1"><code class="bash plain">cmake&nbsp;-DCMAKE_BUILD_TYPE=debug&nbsp;./</code></div><div class="line number3 index2 alt2"><code class="bash functions">make</code>&nbsp;<code class="bash comments">#在本路径下生成一个sqladvisor可执行文件,即是我们想要的</code></div></div></td></tr></tbody></table><p><strong>5、测试:</strong></p><p style="text-align:center"><img src="http://7xrn7z.com1.z0.glb.clouddn.com/1505813478.png" title="1505813478.png" alt="QQ图片20170919173054.png" width="784" height="422" style="width: 784px; height: 422px;"></p><p><strong><br></strong><br></p><p><strong><br></strong></p><p><strong>备注:</strong><br></p><p><span style="font-size: 14px;"><em><span style="text-decoration: none;">如果在第4步中出现类似错误:glibconfig.h: No such file or directory</span></em></span></p><p><span style="font-size: 14px;"><em><span style="font-size: 14px; text-decoration: none;">解决方法(摘自README):跟据glib安装的路径,修改SQLAdvisor/sqladvisor/CMakeLists.txt中的两处include_directories针对glib设置的path</span></em></span></p><p><span style="font-size: 14px;"><em><span style="font-size: 14px; text-decoration: none;">glib 的 path 可以通过命令来查找:find / -name 'glibconfig.h' 找到后 替换一下include_directories就可以了</span></em></span></p><p><br></p><p><br></p>
                <br>
                <div>
                    <span style="font-size: 20px;font-weight: 700;color: red;">全文完</span>
                </div>
                <br>
    原文地址:http://www.by2009.com/a/135.html</br>

2017-12-28更新:

上面提到的问题我碰到了,也许是编译C源码少的原因,或这作者假定了一些前置至少,自此做个补充,上文中提到缺少’glibconfig.h‘的错误,我用“fing”命令找到路径和文件后,将两个关于glib的“include_directories”的设置都设置到了“/usr/lib/i386-linux-gnu/glib-2.0/....” 发现有提示提示“glib.h”找不到,我仔细看了下官网的默认CMakeList.txt文件,发现下面的是默认是从“/usr/include/...”开始的,我用“find”查找“glib.h”发现路径是“/usr/include/glib-2.0/glib.h”和官网默认路径相同,因此这里就不能按照上面文章查到的“/usr/lib/i386-linux-gnu/glib-2.0/....”而应该再““/usr/include/...”中去找头文件,最后make成功,整体配置文件如下:
	cmake_minimum_required (VERSION 2.6)</br>
	project(sqladvisor)</br></br>

	# /usr/local/sqlparser为sqlparser库安装目录,必要时进行修改</br>
	include_directories("/usr/local/sqlparser/include")</br>
	include_directories("/usr/local/sqlparser/include/regex")</br>
	include_directories("/usr/lib/i386-linux-gnu/glib-2.0/include")</br>
	include_directories("/usr/include/glib-2.0")</br>
	link_directories("/usr/local/sqlparser/lib")</br>
	link_directories("/usr/lib64")</br>

	set(TEST_SRC main.cc)</br>
	add_executable(sqladvisor ${TEST_SRC})</br>

	#如果是sqlparser debug库,则应连接的库为sqlparser-debug</br>
	target_link_libraries(sqladvisor sqlparser-debug)</br>
	target_link_libraries(sqladvisor perconaserverclient_r)</br>
	target_link_libraries(sqladvisor glib-2.0)</br>

    
                        
        </article>

2018-01-09更新:

Ubuntu下的安装成功的步骤梳理,给大家参考 :
1.拉取代码 git clone https://github.com/Meituan-Dianping/SQLAdvisor.git

2.安装依赖项

apt-get install cmake libaio-dev libffi-dev
apt-get install libglib2.0-dev
apt-get install libperconaserverclient18.1-dev
//g++不知道有没有起作用,中间各种出错后尝试安装了他
apt-get install g++
percona的安装参考 https://www.percona.com/doc/percona-server/5.6/installation/apt_repo.html

3.编译依赖项sqlparser

cmake -DBUILD_CONFIG=mysql_release -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=/usr/local/sqlparser ./
make && make install
4.安装SQLAdvisor源码

cd SQLAdvisor/sqladvisor/
cmake -DCMAKE_BUILD_TYPE=debug ./
make
在本路径下生成一个sqladvisor可执行文件,这即是我们想要的。

posted @ 2017-12-28 10:45  星朝  阅读(1051)  评论(0编辑  收藏  举报