MySQL Forums
Forum List  »  Perl

Can't connect to mysql
Posted by: Paul Eckert
Date: March 26, 2006 03:01PM

Hi, all:
I'm trying to access a 3.23 MySQL server at work that works fine from there, but fails remotely.

I've tested end-to-end remote access to MySQL by telnetting to my mysql host from the remote machine:

telnet <host ip> 3306

and I get:

Connected to <host ip> (<host ip>).
Escape character is '^]'.
4.1.11KUBy\Ao+'~,jx>ix@tHIt.(Connection closed by foreign host.

so it looks like MySQL is listening OK. Just to be sure, I tried:

mysql -h <host ip> -P 3306 -p <database>

and got on just fine after entering a password.

I try connecting using the following little program to get on:

#!/usr/bin/perl -w
#

use Mysql;
use DBI;
use strict;

# global SQL vars
my $dbh = undef;

my $dbg = 1;

# open the database
$dbh = dbOpen('mysql') or die "Couldn't open standard db for mySQL: $!";

1;

sub dbOpen {
my $where = shift @_;

return $dbh if $dbh;

my $dbname = '<dbname>';
my $dbuser = '<dbuser>';
my $dbpass = '<dbpass>';
my $dsn = 'mysql';
my $hostnm = "<host ip>";
my $port = "3306";
print "dbi:$dsn:$dbname\@$hostnm:$port,$dbuser, $dbpass\n" if $dbg;

$dbh = DBI->connect("dbi:$dsn:$dbname\@$hostnm:$port", $dbuser, $dbpass)
or die "Can't connect to dbi:$dsn:$dbname\@$hostnm:$port";
}

and get the following failure:


DBI connect('<dbname>@<host ip>:3306','<dbuser>',...) failed: Can't connect to MySQL server on '3306' (22) at x.pl line 32
at /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi/DBI.pm line 611
DBI::__ANON__[/usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi/DBI.pm:664]('undef', 'undef') called at /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi/DBI.pm line 666
DBI::connect('DBI', 'dbi:mysql:<dbname>@<host ip>:3306', '<dbuser>', '<dbpass>') called at x.pl line 32
main::dbOpen('mysql') called at x.pl line 14

I've anonymized things, but you get the idea.

Can anybody show me what I'm doing wrong?

Thanks!

Options: ReplyQuote


Subject
Written By
Posted
Can't connect to mysql
March 26, 2006 03:01PM
March 27, 2006 05:28AM
March 27, 2006 06:43AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.