我在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