【问题标题】:Perl codes always connecting to same MySQL database although it is configured to connect to different serverPerl 代码总是连接到同一个 MySQL 数据库,尽管它被配置为连接到不同的服务器
【发布时间】:2017-02-02 22:58:24
【问题描述】:

Perl 代码总是连接到同一个 MySQL(本地但错误地显示服务器的 FQDN)数据库,尽管它被配置为连接到不同的服务器。 请查看代码。

$datasetname="DBI:mysql:database=applications;host=entdb"

$$dbobject = DBI -> connect ($datasetname, $username, $password,
                           {RaiseError => 0, PrintError => 0})
                  or $errflg2 = 1;
print TT ("                   : ".time()."\n");
close (TT);
if ($errflg2 > 0)
{
 $errmsg  = "ERROR opening up the database: $datasetname\n";
 $errmsg .= "  Error number: " . $DBI::err . "\n";
 $errmsg .= "  Error text  : " . $DBI::errstr . "\n";
 print "$errmsg";
 ilog ($ifile, $errmsg);
 mail_it ($errmsg);
 if ($debug != 0) { close (DB); }
 exit (1);
}
else
{ print "Opened the '" . $datasetname . "' database.\n"; }**
enter code here

错误 打开数据库时出错:DBI:mysql:database=applications;host=entdb 错误号:1045 错误文本:用户 'entdb'@'vpl121' 的访问被拒绝(使用密码:YES)

在我提到 entdb 的代码中看到,但 Perl 连接到 VPL121。 Perl 代码在 vpl121 上运行。

【问题讨论】:

  • 您的代码有一些语法错误。你确定这是你实际运行的真实代码吗?

标签: mysql perl


【解决方案1】:

在 mysql 中,所有用户帐户都通过username@hostname format 标识,其中主机名是代码连接到 mysql 数据库的计算机的主机名或 IP 地址。

您确实写过 perl 代码在vpl121 上运行,因此这是 mysql 使用的主机名。显然,您没有任何与 'entdb'@'vpl121' 匹配的用户帐户,或者密码不正确或给定用户无权访问 entdb 数据库。

我的猜测是您没有任何匹配的用户帐户。考虑创建一个 'entdb'@'%' 用户帐户,其中 % 作为主机名代表任何主机名或 IP 地址。

【讨论】:

  • 谢谢。但我正在连接到 entdb 服务器。使用用户名 entdb。 $datasetname="DBI:mysql:database=applications;host=entdb"。不要到 vpl121 服务器。在我提到 vpl121 的代码中没有。仅供参考的代码正在 VPL121 服务器上运行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-26
  • 1970-01-01
  • 1970-01-01
  • 2013-01-04
  • 2011-04-15
相关资源
最近更新 更多