关键词:innodb 存储引擎 mysql debug环境搭建
摘要:个人学习记录,仅供参考。
innodb存储引擎是mysql数据库的默认存储引擎,对mysql性能优化具有决定性地位,并且其许多特性直接决定了mysql的特性路线。最重要的是学习innodb存储引擎对于程序员了解c++算法、学习数据库性能优化具有极高的价值。
正文:一个好的环境对于程序员来说是十分重要的。
像我自己这样的菜鸟来说如果有个十分便利的环境供我使用,我一定会感激涕零。有时候程序员很多的时候都将时间花费在了环境抓虫上了,尽管这个过程是痛苦并快乐着,但是对于许多菜鸟来说却会成为,吓退前进的勇气。
如果需要学习innodb存储引擎,必不可少的环境就是mysql,但是官方提供的mysql都是不带编译信息的,你无法gdb这个执行环境,所以当务之急应该就是build一个带debug选项的mysql可执行文件。
环境:vmware player
centos 6.3 X64
mysql-5.5.34.tar.gz from skysql download
前期准备:centos: yum install gcc-c++* cmake automake ...etc
以下内容参考与mysql 官方网站(install from source)
安装过程:
第一步:创建mysql用户组和mysql用户
[root@localhost /]# groupadd mysql
[root@localhost /]# useradd -r -g mysql mysql
第二步:解压缩mysql压缩包
[root@localhost Documents]# pwd
/home/mysql/Documents
[root@localhost Documents]# ls
mysql-5.5.34.tar.gz
[root@localhost Documents]# tar -zxvf mysql-5.5.34.tar.gz
[root@localhost Documents]# ls
mysql-5.5.34 mysql-5.5.34.tar.gz
[root@localhost Documents]# cd mysql-5.5.34
[root@localhost mysql-5.5.34]#
第三步:安装和修改相应权限
[root@localhost mysql-5.5.34]# BUILD/compile-amd64-debug-max --prefix=/usr/local/mysql
[root@localhost mysql-5.5.34]#make && make install
[root@localhost mysql-5.5.34]# cd /usr/local/mysql
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# scripts/mysql_install_db --user=mysql
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql data
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql.server
第四步:开启mysqld服务
[root@localhost mysql]$ /etc/init.d/mysql.server restart
ERROR! MySQL server process #3186 is not running!
Starting MySQL.. SUCCESS!
[root@localhost mysql]$
[root@localhost mysql]$ ps -A | grep mysql
3340 pts/0 00:00:00 mysqld_safe
3617 pts/0 00:00:00 mysqld
[root@localhost mysql]$
第五步:调试mysqld,使用gdb
[root@localhost mysql]# gdb
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) attach 3617
...............
(gdb) b /home/mysql/Documents/mysql-5.5.34/sql/sql_show.cc:260
Breakpoint 1 at 0x65a1ca: file /home/mysql/Documents/mysql-5.5.34/sql/sql_show.cc, line 260.
(gdb) c
Continuing.
open another termimal and cd to /usr/local/mysql
[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]#
下图是俩个terminal的交互截图
参考:
百度文库,《使用GDB、DDD调试mysql》
mysql官网,《install from source》