我正在尝试连接一台已安装MySQL的远程服务器,但该服务器正在使用localhost 安装了mySQL的远程服务器:131.116.220.228 需要连接数据库的远程服务器:131.116.220.220('ov046hanpgate01.ddc.teliasonera.net')
use DBI;
print "Testing 1\n";
$DSN="DATABASE=MySQL80;port=3306;host=131.116.220.228";
print "Testing 2\n";
my $dbh = DBI->connect("dbi:mysql:$DSN", "ShrutiTest", "Shruti@92", {PrintError => 0})
or die "Couldn't connect to database: " . DBI->errstr;
print "Testing 3\n";
$dbh->disconnect;
错误:无法连接到数据库:主机'ov046hanpgate01.ddc.teliasonera.net'不允许通过D:\ Integrations \ OWF \ Scripts \ test27july.pl第6行连接到该MySQL服务器。
答案 0 :(得分:1)
看起来您需要允许用户ShrutiTest从运行脚本的ip处连接,即。 131.116.220.220
这可以由任何管理员在MySQL服务器上完成:
GRANT ALL PRIVILEGES ON *.* TO 'ShrutiTest'@'131.116.220.220'
答案 1 :(得分:0)
此语法"DBI:mysql:database=$db;host=$host;port=$port"
在perl脚本中对我有用,可以从Unix服务器连接到远程MySQL数据库。
答案 2 :(得分:-1)
解决了相同的问题。使用的代码是:
#!/usr/bin/perl -w
use DBI;
## mysql user database name
$db ="Buffering";
## mysql database user name
$user = "ShrutiBuffer";
## mysql database password
$pass = "Shruti1234";
## user hostname : This should be "localhost" but it can be diffrent too
$host="131.116.220.228";
$port="3306";
## SQL query
$query = "select * from buffering.insert_data";
my $dbh = DBI->connect("DBI:mysql:database=$db;host=$host;port=$port",$user, $pass);
$sqlQuery = $dbh->prepare($query)
or die "Can't prepare $query: $dbh->errstr\n";
$sqlQuery->execute
or die "can't execute the query: $sqlQuery->errstr";
print "values are:: ";
while (@row= $sqlQuery->fetchrow_array()) {
print join(", ", @row), "\n";
}
$sqlQuery->finish;
exit(0);