zoukankan      html  css  js  c++  java
  • Install DBD::mysql for Perl in XAMPP in Mac , solving errors

    我不知道 why,在 Mac 安装 DBI::mysql 总会报错
    我为了给 cgi-bin 添加 mysql-perl 数据库支持,也是够麻烦的

    1. make sure that mysql and mydql_config is in your PATH

    也就是命令行 which mysqlwhich mysql_config 都可以得到路径

    1. edit mysql_config

    sudo vi $(which mysql_config) 要修改几个地方,确保几处环境设置正确

    • line95: pkgincludedir='/Applications/XAMPP/xamppfiles/include'
    • line113: include="$include -I/usr/include/php/ext/mysqlnd"
    1. install DBD::mysql using XAMPP cpan

    sudo /Applications/XAMPP/xamppfiles/bin/cpan install DBD::mysql

    1. 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.
    

    1. 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

    1. 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

    2. check again
      /Applications/XAMPP/xamppfiles/bin/perl -MDBD::mysql -e1

    3. 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
    天和地是灰色的,砖和瓦也是灰色的。临街的墙几经风化,几经修补,刷过黑灰、白灰,涂过红漆,书写过不同内容的标语,又终于被覆盖;风雨再把覆盖层胡乱地揭下来,形成一片斑驳的杂色,融汇于灰色的笼罩之中。路旁的树木苍黑,瓦楞中芳草青青。 远处,炊烟缭绕。迷蒙的曙色中,矗立着...
  • 相关阅读:
    sed
    UCOSIII(二)
    UCOSIII(一)
    IIC
    SPI
    vii
    find
    grep
    Scrum项目4.0
    Scrum项目3.0
  • 原文地址:https://www.cnblogs.com/raybiolee/p/5551069.html
Copyright © 2011-2022 走看看