1

I have this relative simple Perl code:

use DBI;
use strict;

my $database = "mydb";
my $hostname = "123.45.6.7";
my $port     = "3306";
my $user     = "user";
my $password = "mypasss";
my $dsn      = "DBI:mysql:database=$database;host=$hostname;port=$port";

my $dbh = DBI->connect( $dsn, $user, $password )
        or die "Can't connect to database: ", $DBI::errstr, "\n";

All the parameters seem to be OK, however when I try to execute it on my CentOS I get this error:

DBI connect('database=mydb;host=123.45.6.7;port=3306','user',...) failed: Can't connect to MySQL server on '123.45.6.7' (110) at connection.pl line 17.

What am I doing wrong?

Borodin
  • 126,100
  • 9
  • 70
  • 144
prgrm
  • 3,734
  • 14
  • 40
  • 80
  • 2
    Can you connect from the command line with the same credentials? – simbabque Jul 26 '16 at 09:07
  • Related: http://stackoverflow.com/q/15576521/1331451, http://stackoverflow.com/q/5713808/1331451 – simbabque Jul 26 '16 at 09:08
  • No I can't with mysql either, but I can access it from mysql workbench in windows. – prgrm Jul 26 '16 at 09:12
  • 2
    @prgrm — So the problem is that your database server isn't available on the ip address + port you are trying to connect to. That's not a Perl issue. – Quentin Jul 26 '16 at 09:14
  • See the questions I linked. One of them has a bunch of debugging help. – simbabque Jul 26 '16 at 09:14
  • 2
    "but I can access it from mysql workbench in windows" — what is different about that? Is it on the same machine as the MySQL server? Are you using a different address to connect to? – Quentin Jul 26 '16 at 09:14
  • The mysql server is in a windows server. I can connect to that mysql server from a remote windows computer using mysql workbench, however CentOS cannot connect to it at all, so I assumed the problem had something to do with my PERL code/syntaxis and not with my server. – prgrm Jul 26 '16 at 09:18
  • Is the CentOS on the same machine or on a different computer? It sounds like a network issue. Maybe firewall. Maybe the mysql is not configured to accept connections from the CentOS box with the user you are using. Or there is simply no route. Can you `ping` the Windows box from the CentOS? – simbabque Jul 26 '16 at 09:21
  • 1
    You are right. It was a network issue. – prgrm Jul 26 '16 at 09:27
  • 1
    You can write your own answer for future readers and accept it. – simbabque Jul 26 '16 at 09:29

1 Answers1

0

Answering myself:

The code works and is correct

The problem is that the VPN I am using right now is not properly configured to work with the MySQL, however, since I was able to connect myself from a properly configured VPN somewhere else, I wrongly assumed that it was the PERL code.

prgrm
  • 3,734
  • 14
  • 40
  • 80