« 反向域名解析 Reverse DNS | 首 页 | [ZT] 动态 iptables 防火墙 »

2005 年 09 月 26 日

DBD::mysql 模块的安装和MySQL的Client

| 分类: 服务器技术 Server Tech. |

如果想把 MT 和 MySQL 联合起来的话,必须安装 perl 的 DBD:mysql 模块(The DBD::mysql module is the "MySQL client" in this case)。

一直以为安装了binaries版本的Linux tar包(例如 Linux(x86, glibc-2.2, static (Standard only), gcc) Standard 4.1.14 29.5M )就可以了。其实这只是一个 MySQL Server ,而往往很多 linux 系统上面没有安装 MySQL 的 Client。所以下载了 source 版本的 MySQL, 使用参数 configure --without-server 来进行编译,即可安装相应的 client 版本。与此同时,也要确认MySQL的 library 和 header是否有安装(Linux x86 RPM downloads 中的Libraries and header files)。

当然你也可以使用 mysql-client,mysql-devel,perl-DBI 等相应的 rpm 包来解决问题。(perl-DBI, perl-DBD-Pg, postgresql-libs)

安装 perl 的模块时,可以使用以下方法:

perl -MCPAN -e shell
install DBD::mysql
这里注意一下perl的路径。如果你有两个perl:/usr/bin/perl /usr/local/bin/perl,那么选择 perl的路径将会决定你升级的是 rpm 的 perl 还是 tar 的 perl。我的做法是禁用了 rpm 的 perl , 直接将 ln -s /usr/local/bin/perl /usr/bin/perl 连接即可。

参考文档:INSTALL - DBD::mysqlのインストールと構成設定の方法

必要条件

MySQL
実際のMySQLデータベース・サーバーをインストールする必要はありません。クライアント・ファイルと開発ファイルで十分です。例えば Red Hat LinuxディストリビューションではRPMファイル mysql-clientとmysql-develがついてきます。 MySQLサーバーが他のマシンにあれば、これらで十分です。 MySQLソース・ディストリビューションからコンパイルし、以下のコマンドを使うことによりクライアント・ファイルを作成することもできます。

configure --without-server
Windowsを使っていて、ソースからコンパイルする必要があるならば(これはActivePerlを使っていない場合に限ります)、ヘッダとライブラリ・ファイルがインストールされていることを確認してください。これはMySQLセットアップ・プログラムを実行するときに、"Custom installation"を選び、適切なオプションを選ぶことが必要になるかもしれません。

以下介绍一下 DBD::mysql 的 troubleshooting.

首先下载DBD-mysql-3.0002 > DBD::mysql
解压DBD-mysql-3.0002.tar.gz后用默认的configure命令 perl Makefile.PL
会得到以下结果。


I will use the following settings for compiling and testing:

cflags (mysql_config) = -I/usr/local/include/mysql
embedded (mysql_config) =
libs (mysql_config) = -L/usr/local/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm
mysql_config (guessed ) = mysql_config
nocatchstderr (default ) = 0
nofoundrows (default ) = 0
ssl (guessed ) = 0
testdb (default ) = test
testhost (default ) =
testpassword (default ) =
testsocket (default ) =
testuser (default ) =

To change these settings, see 'perl Makefile.PL --help' and
'perldoc INSTALL'.


其实这之中的一部分结果使用 mysql_config 命令得到的。这个命令保存在你使用的mysql的/bin/下面,通过这个命令可以得到需要的参数。

使用'perl Makefile.PL --help' 查询

Possible options are:

--cflags= Use for running the C compiler; defaults
to the value of "mysql_config --cflags" or a gussed
value
--libs= Use for running the linker; defaults
to the value of "mysql_config --libs" or a guessed
value
--embedded= Build embedded version of DBD and use for this;
defaults to the value of "mysql_config --embedded"
(default: off)
--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
--mysql_config= Specify for mysql_config script
(Not supported on Win32)
--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
--ps-protocol Toggle the use of server-side prepare, requires
MySQL server version 4.1.3 if set to 1
--force-embedded Force to build embedded version of driver
--ssl Enable SSL support
--help Print this message and exit

这之中最重要的是 --mysql_config= ,同时你也需要指定 testdb 等信息,所以最终的 configure 命令可能会很复杂。例如:
perl Makefile.PL --libs="-L/usr/local/mysql/lib -lmysqlclient -lz -lcrypt -lnsl -lm -lc -lnss_files -lnss_dns -lresolv -lc -lnss
_files -lnss_dns -lresolv" --testdb="mt" -testuser="root" -testpassword="tenten1" --testhost="localhost" --cflags="-I/usr/local/mysql/include -mcpu=pentiumpro
"

这之中的值都是由 mysql_config 生成的!
Good Luck!

(END)

评论 (1 条)

Kreny
2007年04月28日 23:02

http://www.brandonhutchinson.com/perl_inc.html

Appending to Perl's @INC array
The @INC array is a list of directories Perl searches when attempting to load modules. To display the current contents of the @INC array:

perl -e "print join(\"\n\", @INC);"

The following two methods may be used to append to Perl's @INC array:

1. Add the directory to the PERL5LIB environment variable.
2. Add use lib 'directory'; in your Perl script.

Sample:
$ setenv PERL5LIB=/home/user/lib
For more information, read the perlrun manpage or type perldoc lib.

或者在程序的前面加上类似于:
push(@INC,"/usr/lib/perl5/vendor_perl/perl5.8.0);
push(@INC,"/usr/lib/perl5/perl5.8.0");

发表评论

(如果您还为在此成功留言,也许是因为需要管理员逐一审核留言内容后放可看到您的评论。请稍后并感谢您的耐心等待。)

阅览更多文章请访问 首页过去的存档