简体   繁体   English

perl脚本连接到mysql服务器端口3307

[英]perl script to connect to mysql server port 3307

I am trying to connect to a mysql server which is running at port 3307. How do I connect to the server? 我正在尝试连接到在端口3307上运行的mysql服务器。如何连接到该服务器? I do not see any other way to specify port. 我看不到其他指定端口的方法。 I am using like this: 我正在这样使用:

#!/usr/bin/perl
use Mysql;

$host = "localhost";
$database = "abc";
$tablename = "def";
$user = "uuu";
$pw = "ppp";


$connect = Mysql->connect($host, $database, $user, $pw) or die "Cannot connect to MySQL server\n";

I want to use MySQL package and not DBI. 我想使用MySQL软件包而不是DBI。

Thank you. 谢谢。

You are mistaken. 你误会了。 You want to use DBI and not Mysql. 您要使用DBI,而不要使用Mysql。 The Mysql module became obsolete 12 years ago, when it was replaced with a compatibility module that's just a wrapper around DBI. Mysql模块在12年前就已过时,当时它被兼容模块替换,该模块只是DBI的包装。 Even the compatibility module has been removed from the current distribution; 甚至兼容性模块也已从当前发行版中删除; you have to install an old DBD::mysql just to get it (it last shipped in DBD-mysql 3.0008 , released back in 2006). 您只需要安装一个旧的DBD :: mysql即可(它最后一次发布于2006年发布的DBD-mysql 3.0008中)。

#!/usr/bin/perl

use strict;
use DBI;

my $host = "localhost";
my $database = "abc";
my $port = 3307;
my $tablename = "def";
my $user = "uuu";
my $pw = "ppp";

my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host;port=$port",
                       $user, $pw)
  or die "Cannot connect to MySQL server\n";

尝试指定类似localhost:3307主机

For me...Following seems to be working ... 对我来说...以下内容似乎很有效...

#!/usr/bin/perl

use strict;
use DBI;

my $host = "rajeshk-W7";
my $database = "rajesh";
my $port = 3307;
my $tablename = "def";
my $user = "rajesh";
my $pw = "rajesh123";
#my $dbh = DBI->connect("DBI:mysql:rajesh:rajeshk-W7","rajesh","rajesh123") or die "Cannot connect to MySQL server\n";

my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host",$user, $pw) or die "Cannot connect to MySQL server\n";

where i dint mentioned port. 我在提到港口的地方。 When i add port, its unable to connect. 当我添加端口时,其无法连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM