安装了Mysql Perl模块并进行了双重检查(参见下面的#3),但在使用时仍然会出现错误(#1如下)。
如果我使用DBD::Mysql
,则连接语句[Mysql->connect('localhost')
]不起作用(下面的#2)
已经尝试了每个文档的所有语法组合,包括拼写的大小写等。
在Mac OS X 10.6上。
TIA, 加里
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.0 .)
Can't locate object method "connect" via package "mysql" (perhaps you forgot to load "mysql"?)
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).
答案 0 :(得分:3)
DBD::mysql
是数据库驱动程序。在正常情况下,您不应该直接使用它。相反,您应该将DBI
与MySQL特定的连接字符串一起使用。
示例:强>
#!/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;