开发者

Mysql Perl module issues on Mac

Have installed the Mysql Perl module and double checked(see #3 below), but still get error(#1 below) when using.

If I use the DBD::Mysql, then the connect statement [Mysql->connect('localhost')] doesn't work (#2 below)

Have tried all syntax combos per documentation including capitalization of spelling, etc.

On Mac OS X 10.6.

TIA, Gary

1.

Can't locate Mysql.pm in @INC (@INC contains: /Library/Perl/Updates/5.10.0/darwin-thread-multi-2level /Library/Perl/Updates/5.10.0 /System/Library/Perl/5.10.0/darwin-thread-multi-2level /System/Library/Perl/5.10.0 /Library/Perl/5.10.0/darwin-thread-multi-2level /Library/Perl/5.10.0 /Network/Library/Perl/5.10.0/darwin-thread-multi-2level /Network/Library/Perl/5.10.0 /Network/Library/Perl /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level /System/Library/Perl/Extras/5.10开发者_如何学C.0 .)

2:

Can't locate object method "connect" via package "mysql" (perhaps you forgot to load "mysql"?)

3:

cpan[1]> install DBD::mysql
CPAN: Storable loaded ok (v2.18)
Going to read '/private/var/root/Library/Application Support/.cpan/Metadata'
  Database was generated on Sat, 04 Dec 2010 00:31:51 GMT
DBD::mysql is up to date (4.018).


DBD::mysql is the database driver. You should not be using it directly in normal cases. Instead, you should use DBI with a MySQL specific connection string.

Example:

#!/usr/bin/env perl

use strict;
use warnings;

use DBI;

my %db = (
    'database' => 'leaking_wiki',
    'host'     => 'localhost',
    'port'     => '3306',
    'username' => 'root',
    'password' => 't0p_53cr3t',
);

my $dbh = DBI->connect(                                                                                                                                      
    "DBI:mysql:database=$db{database};host=$db{host};port=$db{port}",                                                                                        
    $db{username}, $db{password} )                                                                                                                           
  or die $DBI::errstr;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜