我在RHEL 5.5 64 bit
机器上。Perl DBD无法连接到64位机器上的MySQL
我安装了ActivePerl 5.10 64位在机器上,升级了以前内置的Perl 5.8 64位。我有MySQL并运行,我的PHP项目能够访问它。我的Perl文件需要使用DBD访问同一个数据库,但它无法做到这一点。我已经验证:
- 我的MySQL服务已启动并正在运行。
- 我的用户存在,数据库和数据一起存在。
- 我能够通过shell MySQL客户端从数据库访问数据。
以下是我的Perl脚本。
#!/usr/bin/perl
use DBI;
$dbh = DBI->connect("DBI:mysql:go:super218:3306","root","NEWPASSWORD") or die "Couldn't connect to database: " . DBI->errstr;
my $sth = $dbh->prepare("SELECT * FROM phones")
or die "Can't prepare SQL statement: $DBI::errstr\n";
$sth->execute or die "executing: $stmtA ", $dbh->errstr;
my @row;
while (@row = $sth->fetchrow_array()) {
print "Row: @row\n";
}
我正在用正确的用户名和密码以下错误:
DBI connect('go:super218:3306','root',...) failed: (no error string) at testdb.pl line 6
Couldn't connect to database: at testdb.pl line 6.
我得到不正确的用户名或密码以下错误:
DBI connect('go:super218:3306','root1',...) failed: Access denied for user 'root1'@'localhost' (using password: YES) at testdb.pl line 6
Couldn't connect to database: Access denied for user 'root1'@'localhost' (using password: YES) at testdb.pl line 6.
如何解决这个问题?我想这个问题是在MySQL的最后。
你可以更改'DBI:mysql:go:super218:3306'这个'DBI:mysql:go; host = super218'。另外加上'use strict;使用警告;'给你的脚本+ – 2012-03-20 08:56:59
@Devendra:请你详细说明使用严格;并使用警告;我如何使用它们? #'/ usr/bin/perl'后面加' – user1263746 2012-03-20 09:03:37
'即在'use DBI'的下一行;''use strict;'参考[link](http://learnperl.scratchcomputing.com/tutorials/getting_started/)并使用警告; – 2012-03-20 09:39:12