perl + mysql + apache on windows

Discussion in 'Perl Misc' started by RB, Aug 12, 2003.

  1. RB

    RB Guest

    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
     
    RB, Aug 12, 2003
    #1
    1. Advertising

  2. RB

    Mothra Guest

    Hello,

    "RB" <> wrote in message
    news:Usb_a.175998$...
    >

    [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
     
    Mothra, Aug 12, 2003
    #2
    1. Advertising

  3. RB wrote:
    >
    > my $dsn = 'dbi:mysql:mydatabase';


    <snip>

    > 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';

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Aug 12, 2003
    #3
  4. RB

    RB Guest

    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" <> wrote in message
    news:3f37f83e$...
    > Hello,
    >
    > "RB" <> wrote in message
    > news:Usb_a.175998$...
    > >

    > [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
    >
    >
     
    RB, Aug 12, 2003
    #4
  5. RB

    RB Guest

    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,

    "Gunnar Hjalmarsson" <> wrote in message
    news:bhbhcb$10b5a5$-berlin.de...
    > RB wrote:
    > >
    > > my $dsn = 'dbi:mysql:mydatabase';

    >
    > <snip>
    >
    > > 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';
    >
    > --
    > Gunnar Hjalmarsson
    > Email: http://www.gunnar.cc/cgi-bin/contact.pl
    >
     
    RB, Aug 12, 2003
    #5
  6. RB

    Mothra Guest

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

    "RB" <> wrote in message
    news:NVb_a.176187$...
    > "Mothra" <> wrote in message
    > news:3f37f83e$...
    > > Hello,
    > >
    > > "RB" <> wrote in message
    > > news:Usb_a.175998$...
    > > >

    > > [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 :)
    > >

    >"RB" <> wrote
    > 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
     
    Mothra, Aug 12, 2003
    #6
  7. RB

    Guest

    "RB" <> wrote:
    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service New Rate! $9.95/Month 50GB
     
    , Aug 12, 2003
    #7
  8. RB

    raja babu Guest

    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

    (raja babu) wrote in message news:<>...
    > well, I login to the machine as Administrator. The Apache config file
    > ( httpd.conf ) has no mention of any user under which it is running -
    > so it could be running under the Admnistrator account. When I do it
    > from the command line I am running as Administrator. I do not know who
    > has permissions on the named pipe - how do I find out?
    >
    > rb
    >
    > wrote in message news:<20030812170712.414$>...
    >
    > > 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
     
    raja babu, Aug 13, 2003
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. The Poor
    Replies:
    2
    Views:
    244
    Gregory Toomey
    Sep 27, 2003
  2. Kostas Hatzikokolakis

    Use perl in apache without #!/path/to/perl

    Kostas Hatzikokolakis, Oct 18, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    171
    Ron Savage
    Oct 19, 2003
  3. joe
    Replies:
    8
    Views:
    208
    Matthias Weckman
    Nov 14, 2003
  4. wana
    Replies:
    0
    Views:
    184
  5. PGPS
    Replies:
    10
    Views:
    643
Loading...

Share This Page