在MySQL中调试MTPower

由于我们MySQL小组开发的MTPower版本极多,到现在为止显得有些混乱,这里推荐大家使用改进的MDB(Multi-threaded Disk Buffer)版本,因为这个版本是在原有版本的基础上改进的版本,MDB性能也是最好的。这个版本在八核服务器/home/robin/bishe/source目录中mysql-6.0.9-alpha目录(可用root用户进入),将整个mysql-6.0.9-alpha文件拷贝到自己的目录中:

[code lang=”shell”]
root@localhost source]# pwd
/home/robin/bishe/source
[root@localhost source]# cp -r mysql-6.0.9-alpha /home/somebody
[root@localhost source]# cd /home/somebody
[root@localhost mysql]# ls -la
total 4
drwxr-xr-x 33 root root 4096 May 4 16:13 mysql-6.0.9-alpha
[/code]

然后改变改变mysql-6.0.9-alpha 的拥有者

[code lang=”shell”]
[root@localhost mysql]# chown -R somebody:somebody mysql-6.0.9-alpha
[/code]

退出超级用户,以用户身份进入

[code lang=”shell”]
[root@localhost mysql]# exit
[/code]

进入到mysql-6.0.9-alpha目录下,配置、编译并安装

[code lang=”shell”]
[liao@localhost mysql]$ cd mysql-6.0.9-alpha/
[liao@localhost mysql-6.0.9-alpha]$
[liao@localhost mysql-6.0.9-alpha]$ ./BUILD/autorun.sh
[liao@localhost mysql-6.0.9-alpha]$ ./configure –prefix=/home/somebody/deploy –with-plugins=mtpower –with-debug=full
[liao@localhost mysql-6.0.9-alpha]$ make
[liao@localhost mysql-6.0.9-alpha]$ make install
[/code]

这里注意几点:

1、./BUILD/autorun.sh是必要的,特别是在MTPower中添加了自己写的C/C++源文件,这一步必不可少;另外若是在此目录下进行第一次编译操作也最好./BUILD/autorun.sh,以后如果还是在此目录下编译或安装都不必再./BUILD/autorun.sh,除非如刚才所说,增删了源文件;

2、–with-plugins=MTPOWER意思是把MTPower编译进mysql并安装,如果是对MTPower进行开发,这个选项肯定要有,默认没有;

3、–with-debug=full 这个选项是调试用的,默认没有(即普通安装,非调试模式)。另外,当我们需要安装MTPower但不需要调试模式时(即–with-debug=full不必写上),还有很重要的一步就是在make之前要吧mysql-6.0.9-alpha/storage/MTPower目录下的Makefile的-O3改成-g,告诉编译器不对MTPower进行优化,否则mtpower会有些难以发现的错误。

4、–prefix=/home/somebody/deploy是设置mysql的安装路径,请务必加上,以免覆盖默认安装目录下的文件。还有一点是安装之后mysql server的启动比较麻烦,如果嫌麻烦,可以配置成–prefix=/home/liao/benchmark/buffer_improved/deploy ,即安装在我的目录下,但需要root权限,即以root用户make install(make install之前的命令用过用户的权限就可以完成)。make install后可以直接进入安装目录运行或调试mysql。据我的经验,这是没有出现什么问题的。

5、在接下来的开发mysql过程中,如果只是增减代码而没有增减文件,每次更改完后不必再/BUILD/autorun.sh和./configure,只需make && make install就可以了。

接下来讲讲如何调试MTPower。如上所述,要对MTPower进行调试,–with-plugins=MTPOWER –with-debug=full必须都要选上,然后再make && make install.
安装完毕后进入到安装目录(这里假设/home/liao/benchmark/buffer_improved/deploy),用ls命令查看。
可以看到有个libexec文件夹,该文件夹下面有个mysqld文件,这个就是服务器端二进制文件,我们要做的就是对这个文件进行调试(调试过程最好用root用户,这样可以避免mysql权限问题)。

如果要设置断点,可以在run -uroot之前设置,比如

(gdb) b ha_mtpower.cc:500 –在ha_mtpower.cc第500行设置断点

(gdb) b ha_mtpower::create –在ha_mtpower类成员函数create中设置断点

另外断点还可以在调试过程中设置。

然后用mysql客户端连接mysql server,

当代码在断点处停止时,就可以进行单步等等之类的调试了,具体可以看gdb使用说明。

另外还可以自己写一些测试程序当作客户端(作为例子可以查看/home/liao/benchmark/buffer_improved/test 目录下的benchmark.c文件),这样就不必每次都在客户端中输入SQL语句了。

文远补充说明:

文远  20:41:22
4.在make install之后,还要执行scripts/mysql_install_db,用于创建数据目录var
文远  20:44:49
cp supoort-files/选一个 /安装目录var/my.cnf,之后在my.cnf中[mysqld]中写入 user = mysqld

用snprintf取代不安全的sprintf,防止程序挂掉(core)

        这里讲的不安全,是指访问内存越界导致程序挂掉。程序挂掉影响大小要看具体的业务。如果程序挂掉导致业务中断,这就是比较严重的,也是不允许的。如果程序真的挂了,也会有相应的机制应对,比如监控并重启。当然了,如果程序不那么重要,比如一些批跑程序,再次运行即可。
MSVC的_snprintf 与gcc的snprintf(C99)行为不一样!!!  _snprintf在buff结尾有可能没有’\0’,所以跨平台时,还是保留最后一个字节安全(长度20的buff,传给snprintf,只用19)snprintf (或者_snprintf )可以用来只计算长度,如:int c = snprintf(NULL,0,……);asprintf 第一个参数是指向指针的指针,它会在heap中自动申请空间(最后要手动free)。使用asprintf ,要加上 #define     _GNU_SOURCE
转帖:
在 C 語言裡,要建立一個字元陣列的字串,常常會使用 sprintf() 這個函數來做格式化的處理。但是實際上,這個函式卻不是那麼「安全」。怎麼說呢?sprintf() 的整個介面長的樣子的是:int sprintf ( char * str, const char * format, … )也就是在使用前,必須要先建立好一個字元陣列的空間,再用這個函式把內容填入,下面就是簡單的例子:

int tmp = 10;
char cstr[20];
sprintf( cstr, “%d * %d = %d”, tmp, tmp, tmp * tmp );

在 這個例子裡,cstr 最後的值,會是「10 * 10 = 100」,看起來好像很好?但是如果把 tmp 的值改成 10000 的話,cstr 則應該要變成「10000 * 10000 = 100000000」,但是由於這時候的字串所需長度為 26,而要寫入的 cstr 的長度只有 20,所以就會造成 buffer overflow 的問題。

像如果是以 Visual C++ 2006 來編譯的話,如果程式裡有用到 sprintf(),他在編譯時就會顯示一個警告訊息:

warning C4996: ‘sprintf’: This function or variable may be unsafe. Consider using sprintf_s instead.

而要怎麼避免 sprintf 的 buffer overflow 的問題呢?除了微軟建議的 sprintf_s() 外,實際上在 C99 裡, 也多了一個 snprinf() 是用來取代現有的 sprintf() 了~他的介面是:

int snprintf(char *str, size_t size, const char * restrict format, …)

應該可以明顯看得出來,snprinf() 這個函式比 sprintf() 多了一個參數 size;這個參數的用處,就是用來限制最大的寫入資料量,可以用來避免 buffer overflow。以上面的例子來說,本來寫:

int tmp = 10000;
char cstr[20];
sprintf( cstr, “%d * %d = %d”, tmp, tmp, tmp * tmp );

的話,會產生 buffer overflow 的問題。而如果改成用 snprinf() 的話,就是變成:

int tmp = 10000;
char cstr[20];
snprintf( cstr, sizeof( cstr ), “%d * %d = %d”, tmp, tmp, tmp * tmp );

這樣一來,snprinf() 在把資料寫到 cstr 時,最多就只會寫入 20 個字元(cstr 的長度),而不會有 buffer overflow 的問題了~

不過比較討厭的是,MSVC 似乎並沒有直接給這個函式,而是另外給了一個 _snprinf()…雖然功能和參數都大同小異,但是光函式名稱不一樣,就已經增加了些麻煩,更別說在行為模式上也有些不同了。而 _snprinf() 和 snprintf() 主要的差別在於:

_snprintf() (MSVC) snprintf()
回傳值 · 當 len <= size 時,會回傳 len· 當 len > size 時,會回傳負值(-1) · 正常狀況會回傳 len。· 如果有錯誤,回傳負值(-1)
字串內容 · 當 len < size 時,str 會包含結尾的 ‘\0’· 當 len >= size 時,str 不會有結尾的 ‘\0’ · str會包含結尾的 ‘\0’
· len:要輸出的字串應有的長度,不包含結尾的 ‘\0’。· size:snprintf/ _snprintf 的第二個參數,寫到 str 的最大資料量。

所以如果要跨平台,大致上應該可以:

如果是使用 MSVC 的話,自行定義 snprintf,讓它變成 _snprintf
#ifdef _MSC_VER
#define snprintf _snprintf
#endif

實際使用,則就可以直接用 snprintf
int tmp = 10000;
char cstr[20];
int size = sizeof( cstr );
int c = snprintf( cstr, size, “%d * %d = %d”, tmp, tmp, tmp*tmp );
if( c > size || c < 0 )
cstr[ size – 1 ] = ‘\0’;

這樣應該就可以在 g++ 和 MSVC 的環境裡,都可以避免 buffer overflow 和字串結尾沒有 ‘\0’ 的問題了~

但是這樣的做法,實際上是產生一個最大長度為 20 的字串,如果超過的話,雖然不會有 buffer overflow 的問題,但是過長的部分還是要切掉。而如果希望可以針對需要,產生一個夠長的字串的話,其實還可以使用 asprintf() 這個函式。他的用法很簡單,基本上和 sprintf() 很像,只是將第一個參數改成一個 char** 而已;下方就是簡單的範例:

char* cstr;
int c = asprintf( &cstr, “%d * %d = %d”, tmp, tmp, tmp*tmp );

如此一來,他就會自動替 cstr 產生一塊夠大的記憶體空間,來存放字串了~

不過 asprintf() 這個函式應該不在 C 語言的標準內,而是 GNU 的 extension(可能要加上「#define     _GNU_SOURCE」才能使用),所以在 MSVC 裡並沒有提供 asprintf() 可以使用。不過雖然沒有現成的可以用,但是還是可以透過執行兩次 snprintf() 來做到同樣的功能~實作的方法,大致上就是:

char* cstr;
int c = snprintf( NULL, 0, “%d * %d = %d”, tmp, tmp, tmp*tmp );
cstr = new char[ c + 1 ];
snprintf( cstr, c + 1, “%d * %d = %d”, tmp, tmp, tmp*tmp );

做法的主要概念,就是第一次的 _snprintf() 實際上並不真正的將字串寫到某個空間,而是單純用來取得字串所需要的長度,然後再根據需要的長度來產生字元陣列,並將資料寫入。

转自:http://heresy.spaces.live.com/blog/cns!E0070FB8ECF9015F!9703.entry

mysql-bin文件的来源及处理方法

用 ports安装了mysql以后,过一段时间发现/var空间不足了,查一下,会发现是mysql-bin.000001、mysql- bin.000002等文件占用了空间,那么这些文件是干吗的?这是数据库的操作日志,例如UPDATE一个表,或者DELETE一些数据,即使该语句没 有匹配的数据,这个命令也会存储到日志文件中,还包括每个语句执行的时间,也会记录进去的。

这样做主要有以下两个目的:
1:数据恢复
如果你的数据库出问题了,而你之前有过备份,那么可以看日志文件,找出是哪个命令导致你的数据库出问题了,想办法挽回损失。
2:主从服务器之间同步数据
主服务器上所有的操作都在记录日志中,从服务器可以根据该日志来进行,以确保两个同步。

处理方法分两种情况:
1:只有一个mysql服务器,那么可以简单的注释掉这个选项就行了。
vi /etc/my.cnf把里面的log-bin, binlog_format=mixed这两行注释掉,重启mysql服务即可。

MySQL的configure详解

configure’ configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]… [VAR=VALUE]…

To assign environment variables (e.g., CC, CFLAGS…), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
-h, –help              display this help and exit
–help=short        display options specific to this package
–help=recursive    display the short help of all the included packages
-V, –version           display version information and exit
-q, –quiet, –silent   do not print `checking…’ messages
–cache-file=FILE   cache test results in FILE [disabled]
-C, –config-cache      alias for `–cache-file=config.cache’
-n, –no-create         do not create output files
–srcdir=DIR        find the sources in DIR [configure dir or `..’]

Installation directories:
–prefix=PREFIX         install architecture-independent files in PREFIX
[/usr/local]
–exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
[PREFIX]

By default, `make install’ will install all the files in
`/usr/local/bin’, `/usr/local/lib’ etc.  You can specify
an installation prefix other than `/usr/local’ using `–prefix’,
for instance `–prefix=$HOME’.

For better control, use the options below.

Fine tuning of the installation directories:
–bindir=DIR            user executables [EPREFIX/bin]
–sbindir=DIR           system admin executables [EPREFIX/sbin]
–libexecdir=DIR        program executables [EPREFIX/libexec]
–sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
–sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
–localstatedir=DIR     modifiable single-machine data [PREFIX/var]
–libdir=DIR            object code libraries [EPREFIX/lib]
–includedir=DIR        C header files [PREFIX/include]
–oldincludedir=DIR     C header files for non-gcc [/usr/include]
–datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
–datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
–infodir=DIR           info documentation [DATAROOTDIR/info]
–localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
–mandir=DIR            man documentation [DATAROOTDIR/man]
–docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
–htmldir=DIR           html documentation [DOCDIR]
–dvidir=DIR            dvi documentation [DOCDIR]
–pdfdir=DIR            pdf documentation [DOCDIR]
–psdir=DIR             ps documentation [DOCDIR]

Program names:
–program-prefix=PREFIX            prepend PREFIX to installed program names
–program-suffix=SUFFIX            append SUFFIX to installed program names
–program-transform-name=PROGRAM   run sed PROGRAM on installed program names

System types:
–build=BUILD     configure for building on BUILD [guessed]
–host=HOST       cross-compile to build programs to run on HOST [BUILD]
–target=TARGET   configure for building compilers for TARGET [HOST]

Optional Features:
–disable-option-checking  ignore unrecognized –enable/–with options
–disable-FEATURE       do not include FEATURE (same as –enable-FEATURE=no)
–enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
–disable-dependency-tracking  speeds up one-time build
–enable-dependency-tracking   do not reject slow dependency extractors
–enable-shared[=PKGS]  build shared libraries [default=yes]
–enable-static[=PKGS]  build static libraries [default=yes]
–enable-fast-install[=PKGS]
optimize for fast installation [default=yes]
–disable-libtool-lock  avoid locking (might break parallel builds)
–disable-community-features
Disable additional features provided by the user
community.
–disable-thread-safe-client
Compile the client without threads.
–enable-assembler      Use assembler versions of some string
functions if available.
–enable-profiling      Build a version with query profiling code (req.
community-features)
–enable-local-infile   Enable LOAD DATA LOCAL INFILE (default: disabled)
–disable-grant-options Disables the use of –init-file, –skip-grant-tables and –bootstrap options
–disable-largefile     Omit support for large files

Optional Packages:
–with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
–without-PACKAGE       do not use PACKAGE (same as –with-PACKAGE=no)
–with-charset=CHARSET
Default character set, use one of:
binary
armscii8 ascii big5 cp1250 cp1251 cp1256 cp1257
cp850 cp852 cp866 cp932 dec8 eucjpms euckr gb2312 gbk geostd8
greek hebrew hp8 keybcs2 koi8r koi8u
latin1 latin2 latin5 latin7 macce macroman
sjis swe7 tis620 ucs2 ujis utf8
–with-collation=COLLATION
Default collation
–with-extra-charsets=CHARSET,CHARSET,…
Use charsets in addition to default (none, complex,
all, or a list selected from the above sets)
–without-uca           Skip building of the national Unicode collations.

–with-system-type      Set the system type, like “sun-solaris10”
–with-machine-type     Set the machine type, like “powerpc”
–with-darwin-mwcc      Use Metrowerks CodeWarrior wrappers on OS X/Darwin
–with-gnu-ld           assume the C compiler uses GNU ld [default=no]
–with-pic              try to use only PIC/non-PIC objects [default=use
both]
–with-tags[=TAGS]      include additional configurations [automatic]
–with-other-libc=DIR   Link against libc and other standard libraries
installed in the specified non-standard location
overriding default. Originally added to be able to
link against glibc 2.2 without making the user
upgrade the standard libc installation.
–with-server-suffix    Append value to the version string.
–with-pthread          Force use of pthread library.
–with-named-thread-libs=ARG
Use specified thread libraries instead of
those automatically found by configure.
–with-named-curses-libs=ARG
Use specified curses libraries instead of
those automatically found by configure.
–with-unix-socket-path=SOCKET
Where to put the unix-domain socket.  SOCKET must be
an absolute file name.
–with-tcp-port=port-number
Which port to use for MySQL services (default 3306)
–with-mysqld-user=username
What user the mysqld daemon shall be run as.
–with-zlib-dir=no|bundled|DIR
Provide MySQL with a custom location of compression
library. Given DIR, zlib binary is assumed to be in
$DIR/lib and header files in $DIR/include.
–with-libwrap=DIR      Compile in libwrap (tcp_wrappers) support
–with-pstack           Use the pstack backtrace library
–with-debug            Add debug code
–with-debug=full       Add debug code (adds memory checker, very slow)
–with-error-inject     Enable error injection in MySQL Server
–with-fast-mutexes     Compile with fast mutexes (default is disabled)
–with-atomic-ops=rwlocks|smp|up
Implement atomic operations using pthread rwlocks or
atomic CPU instructions for multi-processor
(default) or uniprocessor configuration
–with-mysqld-ldflags   Extra linking arguments for mysqld
–with-client-ldflags   Extra linking arguments for clients
–with-mysqld-libs   Extra libraries to link with for mysqld
–with-lib-ccflags      Extra CC options for libraries
–with-low-memory       Try to use less memory to compile to avoid
memory limitations.
–with-comment          Comment about compilation environment.
–with-big-tables       Support tables with more than 4 G rows even on 32
bit platforms
–with-max-indexes=N    Sets the maximum number of indexes per table,
default 64
–with-ssl=DIR    Include SSL support
–with-plugins=PLUGIN[[[,PLUGIN..]]]
Plugins to include in mysqld. (default is: none)
Must be a configuration name or a comma separated
list of plugins.
Available configurations are: none max max-no-ndb
all.
Available plugins are: partition daemon_example
ftexample archive blackhole csv example federated
heap innobase myisam myisammrg ndbcluster.
–without-plugin-PLUGIN Disable the named plugin from being built.
Otherwise, for plugins which are not selected for
inclusion in mysqld will be built dynamically (if
supported)
–with-plugin-PLUGIN    Forces the named plugin to be linked into mysqld
statically.
–with-ndb-sci=DIR      Provide MySQL with a custom location of sci library.
Given DIR, sci library is assumed to be in $DIR/lib
and header files in $DIR/include.

–with-ndb-test       Include the NDB Cluster ndbapi test programs

–with-ndb-docs       Include the NDB Cluster ndbapi and mgmapi documentation

–with-ndb-port       Port for NDB Cluster management server

–with-ndb-port-base  Base port for NDB Cluster transporters

–without-ndb-debug   Disable special ndb debug features
–with-ndb-ccflags=CFLAGS
Extra CFLAGS for ndb compile

–without-ndb-binlog       Disable ndb binlog
–without-server        Only build the client.
–with-embedded-server  Build the embedded server (libmysqld).
–without-query-cache   Do not build query cache.
–without-geometry      Do not build geometry-related parts.
–with-embedded-privilege-control
Build parts to check user’s privileges.
Only affects embedded library.
–with-mysqlmanager     Build the mysqlmanager binary: yes/no (default:
build if server is built.)
–without-docs          Skip building of the documentation.
–without-man          Skip building of the man pages.
–without-readline      Use system readline instead of bundled copy.
–without-libedit       Use system libedit instead of bundled copy.

Some influential environment variables:
CC          C compiler command
CFLAGS      C compiler flags
LDFLAGS     linker flags, e.g. -L if you have libraries in a
nonstandard directory    LIBS        libraries to pass to the linker, e.g. -l   CPPFLAGS    C/C++/Objective C preprocessor flags, e.g. -I if
you have headers in a nonstandard directory    CXX         C++ compiler command   CXXFLAGS    C++ compiler flags   CPP         C preprocessor   CXXCPP      C++ preprocessor   F77         Fortran 77 compiler command   FFLAGS      Fortran 77 compiler flags   CCAS        assembler compiler command (defaults to CC)   CCASFLAGS   assembler compiler flags (defaults to CFLAGS)  Use these variables to override the choices made by `configure’ or to help it to find libraries and programs with nonstandard names/locations.  Description of plugins:     === Partition Support ===   Plugin Name:      partition   Description:      MySQL Partitioning Support   Supports build:   static   Configurations:   max, max-no-ndb     === Daemon Example Plugin ===   Plugin Name:      daemon_example   Description:      This is an example plugin daemon.   Supports build:   dynamic     === Simple Parser ===   Plugin Name:      ftexample   Description:      Simple full-text parser plugin   Supports build:   dynamic     === Archive Storage Engine ===   Plugin Name:      archive   Description:      Archive Storage Engine   Supports build:   static and dynamic   Configurations:   max, max-no-ndb     === Blackhole Storage Engine ===   Plugin Name:      blackhole   Description:      Basic Write-only Read-never tables   Supports build:   static and dynamic   Configurations:   max, max-no-ndb     === CSV Storage Engine ===   Plugin Name:      csv   Description:      Stores tables in text CSV format   Supports build:   static   Status:           mandatory     === Example Storage Engine ===   Plugin Name:      example   Description:      Example for Storage Engines for developers   Supports build:   dynamic   Configurations:   max, max-no-ndb     === Federated Storage Engine ===   Plugin Name:      federated   Description:      Connects to tables on remote MySQL servers   Supports build:   static and dynamic   Configurations:   max, max-no-ndb     === Memory Storage Engine ===   Plugin Name:      heap   Description:      Volatile memory based tables   Supports build:   static   Status:           mandatory     === InnoDB Storage Engine ===   Plugin Name:      innobase   Description:      Transactional Tables using InnoDB   Supports build:   static and dynamic   Configurations:   max, max-no-ndb     === MyISAM Storage Engine ===   Plugin Name:      myisam   Description:      Traditional non-transactional MySQL tables   Supports build:   static   Status:           mandatory     === MyISAM MERGE Engine ===   Plugin Name:      myisammrg   Description:      Merge multiple MySQL tables into one   Supports build:   static   Status:           mandatory     === Cluster Storage Engine ===   Plugin Name:      ndbcluster   Description:      High Availability Clustered tables   Supports build:   static   Configurations:   max

Can’t open the mysql.plugin table. Please run mysql_upgrade to create it.

090517 13:34:15 [ERROR] Can’t open the mysql.plugin table. Please run mysql_upgrade to create it.
090517 13:34:15 [ERROR] Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist
090517 13:34:15 mysqld_safe mysqld from pid file /usr/local/mysql/var/mail.bmitwap.com.pid ended
090517 13:38:35 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var

解决办法 在运行初始化权限表的时候使用增加参数–datadir ,命令格式为:
shell> …./mysql_install_db –user=mysql –datadir=/usr/local/mysql/var
这样问题就解决了。

解决Can’t locate DBI.pm in @INC 问题-RedHat Linux环境-mysql-6.0.9-alpha

[root@localhost sql-bench]# ./test-insert

Can’t locate DBI.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at ./test-insert line 32.
BEGIN failed–compilation aborted at ./test-insert line 32.
原因:系统没有按安装DBI组件。
       DBI(Database Interface)是perl连接数据库的接口。其是perl连接数据库的最优秀方法,他支持包括Orcal,Sybase,mysql,db2等绝大多数的数据库
       解决办法:安装DBI、Data-ShowTable、DBD-mysql (假设你已安装完perl和mysql数据库)。具体如下:
ftp://ftp.funet.fi/pub/languages/perl/CPAN/modules/by-module下载三个文件DBI-1.601.tar.gz、Data-ShowTable-3.3.tar.gz、DBD-mysql-3.0007_1.tar.gz,分别处于DBI,DATA,BDB目录下。注意下载的DBI的版本不能太低,如之前作者下载过低版本DBI-1.20不能编译通过。下载后最好保存在目录:/usr/local/src下,并解压产生各模块的安装文件目录。如下
[root@localhost src]#tar zxvf DBI-1.601.tar.gz
[root@localhost src]#tar zxvf Data-ShowTable-3.3.tar.gz
[root@localhost src]#tar zxvf DBD-mysql-3.0007_1.tar.gz
安装DBI
[root@localhost src]# cd DBI-1.601
[root@localhost DBI-1.601]# perl Makefile.PL
[root@localhost DBI-1.601]# make
[root@localhost DBI-1.601]# make test
[root@localhost DBI-1.601]# make install
安装Data-ShowTable
[root@localhost src]# cd Data-ShowTable-3.3
[root@localhost Data-ShowTable-3.3]# perl Makefile.PL
[root@localhost Data-ShowTable-3.3]# make  (注:第一次make出错,再make多几次)
[root@localhost Data-ShowTable-3.3]# make install (注:无需make test)
安装DBD-mysql
[root@localhost src]# cd DBD-mysql-3.0007_1
[root@localhost DBD-mysql-3.0007_1]# perl Makefile.PL –libs=”-L/usr/local/mysql-6.0.9-alhpa/lib/mysql -lmysqlclient -lz -lrt -lcrypt -lnsl -lm”  –cflags=” -I/usr/local/mysql-6.0.9-alpha/include/mysql -g -DUNIV_LINUX” –testuser=root –testsocket=/home/cserken/mysql/tmp/mysql.sock
[root@localhost DBD-mysql-3.0007_1]# make
[root@localhost DBD-mysql-3.0007_1]# make test
[root@localhost DBD-mysql-3.0007_1]# make install
安装完毕
注意:make test之前mysql server要启动,并且要知道server的socket。本文在调试模式下启动mysql server,可获取到socket。
[root@localhost src]# cd /usr/local/mysql-6.0.9-alpha (mysql 安装路径)
[root@localhost mysql-6.0.9-alpha]# gdb libexec/mysqld
(gdb) r –user=root
The program being debugged has been started already.
Start it from the beginning? (y or n) y

Starting program: /usr/local/mysql-6.0.9-alpha/libexec/mysqld –user=root
[Thread debugging using libthread_db enabled]
[New Thread -1208408368 (LWP 3545)]
[New Thread -1208411248 (LWP 3546)]
[Thread -1208411248 (LWP 3546) exited]
[New Thread -1235683440 (LWP 3547)]
091012  8:47:30 [Note] Event Scheduler: Loaded 0 events
091012  8:47:30 [Note] /usr/local/mysql-6.0.9-alpha/libexec/mysqld: ready for connections.
Version: ‘6.0.9-alpha-debug-log’  socket: ‘/home/cserken/mysql/tmp/mysql.sock’ (这个就是socket)
另外,在启动测试脚本的时候,需要指定soket路径
[root@localhost sql-bench]# ./test-insert-using-btree-short –socket=’/home/cserken/mysql/tmp/mysql.sock’
Testing server ‘MySQL 6.0.9 alpha debug log’ at 2009-10-12  9:54:04
Testing the speed of inserting data into 1 table and do some selects on it.
The tests are done with a table that has 100000 rows.
Generating random keys
Creating tables
Inserting 100000 rows in order
Inserting 100000 rows in reverse order
Inserting 100000 rows in random order
Time for insert (300000): 180 wallclock secs (11.30 usr  8.12 sys +  0.00 cusr  0.00 csys = 19.42 CPU)

本机配置环境:RHL + Intel(8核) + mysql-6.0.9-alpha。以上过程在本机上配置通过。