I am new writing Perl code and I need a help to figure out why I am not getting to connect from my linux desktop to a remote MySQL server using DBI in a Perl code. I have connection from my desktop to the remote MySQL server, I have identified the remove MySQL server using name or IP address in the DBI connect line, but, base on the error message below, it seems the DBI is trying to connect to a local database (that does not exist), not the remote one:
!/usr/bin/perl -w
use DBI;
use DBD::mysql;
use MySQL;
$DBHOST = "mysqlserver.example.com";
$DBNAME = "anydb";
$DBUSER = "userdb";
$DBPASS = "userdbpwd";
$dsn = "dbi:mysql:database=$DBNAME,host=$DBHOST, port=3306";
my $dbh = DBI->connect("DBI:mysql:database=$DBNAME,host=$DBHOST, port=3306", "$DBUSER", "$DBPASS", \%attr);
Running the code above I am getting the error:
DBI connect failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock
I have the following DBI drivers installed:
DBM ExampleP File Gofer Proxy SQLite Sponge mysql
MySQLmodule??? - Matt Jacobuse warningsanduse strictat the top of every Perl file you write. - Matt Jacob%attrwhich you passed toconnectin your code ? - Ashraf Bashir"$DBUSER", you can simply remove" "- Ashraf Bashir