perl + mysql + apache on windows

R

RB

I am running mySQL 3.23.57 on windows 2000. I configured it to run on named
pipes ( enable-named-pipe ), and the server starts nicely. I have a perl
script which tries to establish a connection to mySQL server:

use DBI;

my $dsn = 'dbi:mysql:mydatabase';

# set the user and password
my $user = 'root';
my $pass = 'xxxxxxxxx';

# now connect and get a database handle
my $dbh = DBI->connect($dsn, $user, $pass);
# or die "Can't connect to the DB: $DBI::errstr\n";
print "done"

When I run this from the command line, the output is a string "done".

When I run the same perl script under cgi-bin using Apache(2.0.47), I can
see the following in the error_log:

[Mon Aug 11 14:42:23 2003] [error] [client w.x.y.z] DBI
connect('mydatabase','root',...) failed: Can't connect to MySQL server on
'localhost' (10061) at E:/Program
Files/ApacheGroup/Apache2/cgi-bin/testdb.pl line 17
[Mon Aug 11 14:42:23 2003] [error] [client w.x.y.z] Can't connect to the DB:
Can't connect to MySQL server on localhost' (10061)

I can of course do this from a shell prompt:

mysql -u root -p mydatabase

mysqld-nt is not listening on port 3306 ( netstat -a shows this )....

What am I missing here? Why do I get the 10061 error ( which seems to be a
Winsock error code - connection refused ).

thanks,
rb
 
M

Mothra

Hello,

RB said:
[snipped]

use DBI;

my $dsn = 'dbi:mysql:mydatabase';
[more snippage]

for my $dsn I use
$dsn = "DBI:mysql:database=seating;host=cypci748";
It has the hostname, just a though :)

Hope this helps

Mothra
 
G

Gunnar Hjalmarsson

RB said:
my $dsn = 'dbi:mysql:mydatabase';

What am I missing here? Why do I get the 10061 error ( which seems to be a
Winsock error code - connection refused ).

Without really knowing the answer to your question, when playing with
MySQL on my local Windows 98 box, I have experienced that I need to
explicitly state 'localhost'. Doing so might be worth a try:

my $dsn = 'dbi:mysql:mydatabase:localhost';
 
R

RB

Hi,

I tried what you suggested - changing the dsn to
'dbi:mysql:database=mydatabase:host=localhost' - it had no effect - I still
get the connect error...

thanks,
rb

Mothra said:
Hello,

RB said:
[snipped]

use DBI;

my $dsn = 'dbi:mysql:mydatabase';
[more snippage]

for my $dsn I use
$dsn = "DBI:mysql:database=seating;host=cypci748";
It has the hostname, just a though :)

Hope this helps

Mothra
 
R

RB

I tried what you suggested - i modifed the dsn to be something like:

my $dsn = 'dbi:mysql:database=mydatabase:host=localhost'

it had no effect - I still get the connect error...

thanks,
 
M

Mothra

Please do not top post. It anoys the regulars here
[text rearranged]

RB said:
Mothra said:
Hello,

RB said:
[snipped]

use DBI;

my $dsn = 'dbi:mysql:mydatabase';
[more snippage]

for my $dsn I use
$dsn = "DBI:mysql:database=seating;host=cypci748";
It has the hostname, just a though :)
Hi,

I tried what you suggested - changing the dsn to
'dbi:mysql:database=mydatabase:host=localhost' - it had no effect - I still
get the connect error...
you might want to try:

telnet localhost 3306
and see if you can get a connection. then troubleshoot from there

Mothra
 
C

ctcgag

RB said:
I am running mySQL 3.23.57 on windows 2000. I configured it to run on
named pipes ( enable-named-pipe ), and the server starts nicely. I have a
perl script which tries to establish a connection to mySQL server:

use DBI;

my $dsn = 'dbi:mysql:mydatabase';

# set the user and password
my $user = 'root';
my $pass = 'xxxxxxxxx';

# now connect and get a database handle
my $dbh = DBI->connect($dsn, $user, $pass);
# or die "Can't connect to the DB: $DBI::errstr\n";
print "done"

When I run this from the command line, the output is a string "done".

When I run the same perl script under cgi-bin using Apache(2.0.47), I can
see the following in the error_log:

[Mon Aug 11 14:42:23 2003] [error] [client w.x.y.z] DBI
connect('mydatabase','root',...) failed: Can't connect to MySQL server on
'localhost' (10061) at E:/Program
Files/ApacheGroup/Apache2/cgi-bin/testdb.pl line 17
[Mon Aug 11 14:42:23 2003] [error] [client w.x.y.z] Can't connect to the
DB: Can't connect to MySQL server on localhost' (10061)


Pardon if this question doesn't make sense on Windows, but who is apache
running as? Who are you running as when you do it from the command
line? Who has permissions on the named pipe?

Xho
 
R

raja babu

OK - I finally got it to work. And the culprit is Apache on win32.
Somehow it does always tries to connect to mySQL using TCP ( which
explains the earlier error log entry : Can't connect to MySQL server
on 'localhost' (10061) ). So, I configured mySQL to use TCP/IP and
provide the host name in the dsn variable as suggested here : my $dsn
= "dbi:mysql:database=mydatabase:host=myhostname"; - and it worked
this time.

thanks for all the replies...

rb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top