来自另一个远程ip perl的远程db连接

lf5gs5x2  于 2021-06-20  发布在  Mysql
关注(0)|答案(3)|浏览(436)

我正在尝试连接一个安装了mysql的远程服务器,但它使用的是安装了mysql的localhost远程服务器:131.116.220.228需要连接db的远程服务器: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服务器。

ymdaylpp

ymdaylpp1#

解决了同样的问题。使用的代码是:


# !/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);
bvjxkvbb

bvjxkvbb2#

此语法 "DBI:mysql:database=$db;host=$host;port=$port" 在perl脚本中为我工作,从unix服务器连接到远程mysql数据库。

v09wglhw

v09wglhw3#

看起来需要允许用户shrulitest从运行脚本的ip连接,即。131.116.220.220
任何管理员都可以在mysql服务器上执行此操作:

GRANT ALL PRIVILEGES ON *.* TO 'ShrutiTest'@'131.116.220.220'

相关问题