MySQL源码分析整理稿

上传人:re****.1 文档编号:552020229 上传时间:2023-03-06 格式:DOCX 页数:32 大小:762.62KB
返回 下载 相关 举报
MySQL源码分析整理稿_第1页
第1页 / 共32页
MySQL源码分析整理稿_第2页
第2页 / 共32页
MySQL源码分析整理稿_第3页
第3页 / 共32页
MySQL源码分析整理稿_第4页
第4页 / 共32页
MySQL源码分析整理稿_第5页
第5页 / 共32页
点击查看更多>>
资源描述

《MySQL源码分析整理稿》由会员分享,可在线阅读,更多相关《MySQL源码分析整理稿(32页珍藏版)》请在金锄头文库上搜索。

1、MySQL 源码分析Jon Yao编译安装为了实现 MySQL 的更高级别的性能调优,我们通常需要理解其内部实现机制,并对其进行优化调试。在下面的系列中,我们会分别介绍MySQL的部分内部实现机制。首先我们介绍如何从源代码部署一台MySQL服务器。1. 下载MySQL源码http:/ 本文中演示使用的是 mysql-5.5.8 版本。2. 安装环境:rootlocalhost # uname -aLinux nx 2.6.35-24-generic #42-Ubuntu SMP Thu Dec 2 01:41:57 UTC 2010 i686 GNU/Linuxrootlocalhost #

2、gcc -vUsing built-in specs.Target: i686-linux-gnuConfigured with: ./src/configure -v -with-pkgversion=Ubuntu/Linaro4.4.4-14ubuntu5 -with-bugurl=file:/usr/share/doc/gcc-4.4/README.Bugs-enable-languages=c,c+,fortran,objc,obj-c+ -prefix=/usr-program-suffix=-4.4 -enable-shared -enable-multiarch-enable-l

3、inker-build-id -with-system-zlib -libexecdir=/usr/lib-without-included-gettext -enable-threads=posix-with-gxx-include-dir=/usr/include/c+/4.4 -libdir=/usr/lib -enable-nls-with-sysroot=/ -enable-clocale=gnu -enable-libstdcxx-debug -enable-objc-gc-enable-targets=all -disable-werror -with-arch-32=i686

4、-with-tune=generic-enable-checking=release -build=i686-linux-gnu -host=i686-linux-gnu-target=i686-linux-gnuThread model: posixgcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)添加运行MySQL程序的mysql用户(root权限):A groupadd mysqlA useradd mysql g mysqlA cmake . -DCMAKE_BUILD_TYPE:STRING=Release-DCMAKE_INSTALL

5、_PREFIX:PATH=/usr/local/mysql-DCOMMUNITY_BUILD:BOOL=ON -DENABLED_PROFILING:BOOL=ON -DENABLE_DEBUG_SYNC:BOOL=OFF-DINSTALL_LAYOUT:STRING=STANDALONE -DMYSQL_DATADIR:PATH=/usr/local/mysql/data -DMYSQL_MAINTAINER_MODE:BOOL=OFF -DWITH_EMBEDDED_SERVER:BOOL=ON-DWITH_EXTRA_CHARSETS:STRING=all -DWITH_SSL:STRI

6、NG=bundled-DWITH_UNIT_TESTS:BOOL=OFF -DWITH_ZLIB:STRING=bundled -LH3. 配置配置 MySQL 的参数,可以 support-files 下配置文件的模板: 跳转到MySQL安装路径,cmake指定的地址:/usr/local/mysql cp support-files/my-f /etc/fvi /etc/f #/# Uncomment the following if you are using InnoDB tables innodb_data_home_dir = /usr/local/mysql/data innod

7、b_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /usr/local/mysql/data# You can set ._buffer_pool_size up to 50 - 80 %# of RAM but beware of setting memory usage too high innodb_buffer_pool_size = 16Minnodb_additional_mem_pool_size = 2M# Set ._log_file_size to 25 % of buffer poo

8、l size innodb_log_file_size = 5M innodb_log_buffer_size = 8Minnodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50 #/ 按照测试的需求修改,注意加上 datadir 和 innodb 等部分重要参数。修改/usr/local/mysql用户访问权限,chown -R mysql .chgrp -R mysql . 软连接,配置 MySQL 的资源文件路径 /usr/local/share/mysql - /usr/local/mysql/share/ 设置 p

9、ath 环境变量,方便实用: PATH=/usr/local/mysql/bin:/usr/JDK/bin:.设置服务启动cp support-files/my.server /etc/inid.d/mysqlvi /etc/init.d/mysql修改配置路径basedir=/usr/local/mysql datadir=/usr/local/mysql/datamysqld_pid_file_path=/usr/local/mysql/data/nx.pid4. 安装数据库bin/mysql_install_db -user=mysql这里安装必要的数据库文件,如MySQL的系统表,-u

10、ser=mysql是用来运行mysql的用户。5. 试运行服务简单测试一下,运行/etc/init d/mysql start在Ubuntu系统上以root运行mysqld_safe时,会自动切换至U mysql用户来运行mysqld程序。 查看mysqld进程,记录下启动时参数(斜体加粗部分),为今后的调试做准备。rootlocalhost # ps aux | grep mysqlroot2002308001896584 pts/0 S 19:360:00 /bin/sh/usr/local/mysql/bin/mysqld_safe -datadir=/usr/local/mysql/d

11、ata-pid-file=/usr/local/mysql/data/nxpidmysql 204462627 320624 27848 pts/0 Sl 19:360:00/usr/local/mysql/bin/mysqld -basedir=/usr/local/mysql-datadir=/usr/local/mysql/data -plugin-dir=/usr/local/mysql/lib/plugin-user=mysql -log-error=/usr/local/mysql/data/nxerr -open-files-limit=65535-pid-file=/usr/l

12、ocal/mysql/data/nxpid -socket=/tmp/mysqlsock -port=33066. 停止服务/etc/initd/mysql stop调试安装结束,进入正题调试环节。通常Linux下程序员倾向于使用强大的gdb(GNU Project Debugger) 来调试程序,可以查看程序的内部结构、设置断点、查看调用堆栈等。在本文中,我们尝试使用Eclipse CDE,其本质上是带有图形界面的gdb,更方便直观,但依赖Java桌面环境。1. 安装至H ww八w. eclipse .org 下载最新版的 Eclipse C+ 版本2.3.在调试选项中输入前面记录 mysq

13、ld 的启动参数。设置断点,按 F5 开始运行调试。4. 当程序运行到断点时会暂停,此时可以查看输出、调用栈和当前的堆栈值等。参考资料http:/ http:/ http:/www.kdbg.org/主要模块及数据流经过多年的发展,mysql的主要模块已经稳定,基本不会有大的修改。源码结构(M ySQL-558)1.BUILD: 内含在各个平台、各种编译器下进行编译的脚本。如 compile-pentium-debug表示在 pentium 架构上进行编译的脚本。Client:客户端工具,如 mysql, mysqladmin 之类。Cmake:新版mysql使用编译配置初始化工具包 Cmd-

14、line-utils: readline, libedit 工具。Config.给aclocal使用的配置文件。Dbug: 提供一些调试用的宏定义。Docs: 文档库Extra: 提供 innochecksum, resolveip 等额外的小工具。 Include: 包含的头文件libmysql: 库文件,生产 libmysqlclient.so。 libmysql_r: 线程安全的库文件,生成 libmysqlclient_r.so。libservices: 5.5.x 中新加的目录,实现了打印功能。Man: 手册页。Mysql-test: mysqld 的测试工具一套。Mysys: 为跨平台计, MySQL 自己实现了一套常用的数据结构和算法,如 string, hash2.3.4.56.7.8.9.10.11.12.13.14.15.等16.1718.1920.21.22.23.24.25.26.27.28.29.30.31.32.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 建筑资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号