![](/img/trans.png)
[英]Can I connect to a 64 bit mysql server from a 32 bit machine with 32 bit mysql client lib?
[英]Perl DBD can't connect to MySQL on a 64-bit machine
我在RHEL 5.5 64 bit
機器上。
我在機器上安裝了ActivePerl 5.10 64位,升級了之前內置的Perl 5.8 64位。 我已啟動並運行MySQL,我的PHP項目可以訪問它。 我的Perl文件需要使用DBD訪問同一個數據庫,但它無法做到這一點。 我已經證實:
以下是我的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的末尾。
通常在數據庫連接字符串,密碼字符串和SQL查詢中使用單引號,因為這些可能會給出雙引號錯誤。因為雙引號用於插值 。
這就是我認為你應該寫的方式。
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use DBD::mysql;
my $dbh = DBI->connect( 'DBI:mysql:go;host=super218','root','NEWPASSWORD' ,{ RaiseError => 1 } )or die "Couldn't connect to database";
my $sth = $dbh->prepare( 'SELECT * FROM phones');
$sth->execute;
while ( my @row = $sth->fetchrow_array() ) {
print "Row: @row\n";
}
這是我的猜測。
你從mysql正確安裝了mysql連接器lib嗎?
你指定了主持人嗎?
試試這個:
my $db = 'database_name';
my $srv = 'localhost';
my $user = '***************';
my $pass = '***************';
my $port = '3306';
my $dbh = DBI->connect("DBI:mysql:$db:$srv", $user, $pass, {'RaiseError' => 1, 'PrintError' => 1, 'AutoCommit' => 1 }) or die "Connection Failed: $db DB on $srv\n\t$DBI::errstr\n";
如果這不起作用,請嘗試為您的服務器安裝ODBC驅動程序並使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.