【发布时间】:2012-04-04 15:21:18
【问题描述】:
我在RHEL 5.5 64 bit 机器上。
我在机器上安装了ActivePerl5.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; use warnings;添加到您的脚本中。+ -
@Devendra :请您详细说明使用严格;并使用警告;我该如何使用它们?
-
在
#!/usr/bin/perl之后添加,即在下一行。在use DBI;之前参考link 以获得use strict;和use warnings;
标签: mysql database linux perl rhel