我不知道 why,在 Mac 安装 DBI::mysql 总会报错
我为了给 cgi-bin 添加 mysql-perl 数据库支持,也是够麻烦的
- make sure that mysql and mydql_config is in your PATH
也就是命令行
which mysql
和which mysql_config
都可以得到路径
- edit mysql_config
sudo vi $(which mysql_config)
要修改几个地方,确保几处环境设置正确
- line95: pkgincludedir='/Applications/XAMPP/xamppfiles/include'
- line113: include="$include -I/usr/include/php/ext/mysqlnd"
- install DBD::mysql using XAMPP cpan
sudo /Applications/XAMPP/xamppfiles/bin/cpaninstall DBD::mysql
- test if success install
/Applications/XAMPP/xamppfiles/bin/perl -MDBD::mysql -e1
如果没有输出表示成功了
第一个依赖错误
Can't load '/Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle' for module DBD::mysql: dlopen(/Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle, 1): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Perl/5.18/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
Reason: image not found at /System/Library/Perl/5.18/darwin-thread-multi-2level/DynaLoader.pm line 194.
at -e line 0.
Compilation failed in require.
BEGIN failed--compilation aborted.
- locate libmysqlclient
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.a
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.dylib
/Applications/XAMPP/xamppfiles/lib/libmysqlclient_r.18.dylib
/Applications/XAMPP/xamppfiles/lib/libmysqlclient_r.a
/Applications/XAMPP/xamppfiles/lib/libmysqlclient_r.dylib
-
build linkage
sudo ln -s /Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
sudo ln -s /Applications/XAMPP/xamppfiles/lib/libmysqlclient.a /usr/lib/libmysqlclient.a
-
check again
/Applications/XAMPP/xamppfiles/bin/perl -MDBD::mysql -e1
-
test online
1 #!/usr/bin/perl
2
3 use utf8;
4 use v5.16;
5 use warnings;
6 use DBI;
7 print "Content-type: text/plain; charset=utf-8
";
8 print "$_
" for (DBI->available_drivers);
9 # mysql SQLite File DBM are supported
10 print "----------
Installed
";
11 my %ins = DBI->installed_drivers();
12 print "$_ $ins{$_}
" foreach (sort keys %ins);
13
14 my $mydbh = DBI->connect('DBI:mysql:test;host=localhost','root','imac@mysql') or die "connect failed";
15 my $sth = $mydbh->prepare("select * from test;");
16 $sth->execute();
17 #$result = $sth->fetchrow_hashref();
18 while( $result = $sth->fetchrow_hashref ){
19 for (keys $result){
20 print "$_ $result->{$_}
";
21 }}
22 $mydbh->disconnect();
how to make CGI-Perl to work with Apache
• edit /Applications/XAMPP/xamppfiles/etc/httpd.conf
375 <Directory "/Applications/XAMPP/xamppfiles/cgi-bin">
376 AllowOverride all
377 Options ExecCGI Includes Indexes
378 # +/- no need
379 #AddHandler cgi-script .cgi .pl .py .sh
380 Order deny,allow
381 Allow from all
382 Require all granted
383 # allow and require are must
384 </Directory>
- 419 AddHandler cgi-script .cgi .pl .py .sh
- sudo chmod -R 0755 /Applications/XAMPP/xamppfiles/cgi-bin
- restart apache