perl connection string for DBI (mysql)

Problems with the Windows version of XAMPP, questions, comments, and anything related.

perl connection string for DBI (mysql)

Postby japh2 » 28. November 2007 21:49

I was getting a this error: Failed to connect to mySQL server: Can't connect to local MySQL server through socket '/tmp/mysql.sock'

I hadn't realized two things:
A) for windows the connection is through tcp/ip and not a socket (I could see this by using "C:\xampp\mysql\bin>mysql -u root" from the windows command line and entering the command "status")
B) "localhost" will not work for a tcp/ip connection, you have to use "127.0.0.1".

The problem is fixed, this is my code:
Code: Select all
use DBI;
my $username = "root";
my $auth = "";
my $driver = "DBI:mysql";
my $database = "dbname";
my $hostname = "127.0.0.1";
my $port = 3306;
my $dsn  = "DBI:mysql:host=$hostname:port=$port;database=$database";

my $dbh = DBI->connect($dsn, $username, $auth);
die "Failed to connect to mySQL server: $DBI::errstr\n" unless defined $dbh;
japh2
 
Posts: 5
Joined: 28. November 2007 21:32

Postby pain » 29. October 2008 14:12

Hi!
I got the same error message and it was really annoying. But thanks to your code i now get another error message. :)

I use the following code:
Code: Select all
use strict;
use DBI;

my $username = "root";
my $auth = "qwerty";
my $driver = "DBI:mysql";
my $database = "test";
my $hostname = "localhost";
my $port = 3306;
my $dsn = "dbi:mysql:$hostname:$port:$database";

my $dbh = DBI->connect($dsn, $username, $auth);
die "Failed to connect to mySQL server: $DBI::errstr\n" unless defined $dbh;


But all i get is:
DBI connect('localhost:3306:test','root',...) failed: Can't connect to MySQL server on '3306' (116) at ./insert.pl line 13
Failed to connect to mySQL server: Can't connect to MySQL server on '3306' (116)


I can connect to the database using phpmyadmin or the MySQL-monitor.
I'm running on windows xp, using cygwin-perl to execute the code.

Any ideas?
Please help.

Regards
Joppe
pain
 
Posts: 1
Joined: 29. October 2008 13:36


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 130 guests