Trubo Linux 10下为Perl安装DBD::Mysql模块
by jondy(jondy@tom.com)
用到以前写的Windows下的perl连mysql的脚本才发现
没有安DBI模块,在Windows下安装模块用PPM就可以了,很方便
而在linux没有ppm这个文件
linux下使用perl -MCPAN来安装模块,具体用法查看帮助
perl -MCPAN -h
perl -MCPAN 初次使用时提示设置,基本上一路回车到选择区域和国家
设置保存在
/usr/lib/perl5/5.8.0/CPAN/Config.pm
设置可以修改此文件或干脆删除它再运行perl -MCAPN -e shell重新设置
下边开始安装
perl -MCPAN -e shell
首先要安装DBI模块,这个在trubolinux10下没问题,
cpan> install DBI
然后安装DBD::mysql模块
cpan> install DBD::mysql
提示出错退出:
t/mysql2.t 255 65280 ?? ?? % ??
1 test skipped.
Failed 16/18 test scripts, 11.11% okay. 723/730 subtests failed, 0.96% okay.
make: *** [test_dynamic] 错误 2
/usr/bin/make test -- NOT OK
Running make install
make test had returned bad status, won't install without force
向上找发现
Can't exec "mysql_config": 没有那个文件或目录 at Makefile.PL line 174.
readline() on closed filehandle PIPE at Makefile.PL line 176.
cpan> q
退出
[root@localhost sources]#vim /root/.cpan/build/DBD-mysql-2.9004/Makefile.PL
输入/mysql_config查找发现
open(PIPE, "mysql_config --$param |");
open(PIPE, "/usr/local/mysql/bin/mysql_config --$param |"); #修改此处,
运行
[root@localhost sources]#cd /root/.cpan/build/DBD-mysql-2.9004
[root@localhost sources]#perl Makefile.PL --h
Usage: perl /root/.cpan/build/DBD-mysql-2.9004/Makefile.PL [options]
Possible options are:
--cflags= Use for running the C compiler; defaults
to the value of "mysql_config --cflags"
--libs= Use for running the linker; defaults
to the value of "mysql_config --libs"
--testdb= Use the database for running the test suite;
defaults to test
--testuser= Use the username for running the test suite;
defaults to no username
--testpassword= Use the password for running the test suite;
defaults to no password
--testhost= Use as a database server for running the
test suite; defaults to localhost.
--testport= Use as the port number of the database;
by default the port number is choosen from the
mysqlclient library
--nocatchstderr Supress using the "myld" script that redirects
STDERR while running the linker.
--nofoundrows Change the behavoiur of $sth->rows() so that it
returns the number of rows physically modified
instead of the rows matched
--ssl Enable SSL support
--help Print this message and exit
All options may be configured on the command line. If they are
not present on the command line, then mysql_config is called:
mysql_config --cflags
mysql_config --libs
mysql_config --testdb
and so on. See the INSTALL.html file for details.
按提示输入
[root@localhost sources]#perl Makefile.PL --testuser=root --testpassword=password
输入数据库的用户名和密码
这次没有提示错误,然后输入
[root@localhost sources]#make
[root@localhost sources]#make test
[root@localhost sources]#make install
完成安装;
下边是安装时出现错误的完整信息
Running install for module DBD::mysql
Running make for R/RU/RUDY/DBD-mysql-2.9004.tar.gz
CPAN: Digest::MD5 loaded ok
CPAN: Compress::Zlib loaded ok
Checksum for /root/.cpan/sources/authors/id/R/RU/RUDY/DBD-mysql-2.9004.tar.gz ok
Scanning cache /root/.cpan/build for sizes
Deleting from cache: /root/.cpan/build/Msql-Mysql-modules-1.2219 (11.4>10.0 MB)
Deleting from cache: /root/.cpan/build/Data-Dumper-2.121 (10.7>10.0 MB)
Deleting from cache: /root/.cpan/build/Net-Telnet-3.03 (10.2>10.0 MB)
DBD-mysql-2.9004/
DBD-mysql-2.9004/t/
DBD-mysql-2.9004/t/mysql2.t
DBD-mysql-2.9004/t/akmisc.t
DBD-mysql-2.9004/t/60leaks.t
DBD-mysql-2.9004/t/10dsnlist.t
DBD-mysql-2.9004/t/ak-dbd.t
DBD-mysql-2.9004/t/50chopblanks.t
DBD-mysql-2.9004/t/mysql.t
DBD-mysql-2.9004/t/lib.pl
DBD-mysql-2.9004/t/40blobs.t
DBD-mysql-2.9004/t/40nulls.t
DBD-mysql-2.9004/t/insertid.t
DBD-mysql-2.9004/t/40listfields.t
DBD-mysql-2.9004/t/40bindpar