Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a piece of code that worked fine all the time, but suddenly it stopped working, very nasty. The relevent part of the code is here:

use LWP::UserAgent; use DBI; use Data::Dumper; use strict; use warnings; my $db = DBI->connect('DBI:mysql:test', 'root', '', {RaiseError => 1}) +; my $ini = $db->prepare('update books set out = 0'); my $ins = $db->prepare('insert into books(name, person, duedate,barcod +e) values(?,?,?, ?)'); my $upd = $db->prepare('update books set duedate = ?, out = 1 where ba +rcode = ?'); my $any = $db->prepare('select count(*) from books where barcode = ?') +;

ANd here is the error:

DBI connect('test','root',...) failed: Can't connect to MySQL server o +n 'localho st' (10061) at a.pl line 8

Replies are listed 'Best First'.
Re: Suddenly cannot connect to MySQL any more
by fauria (Deacon) on Jul 04, 2005 at 00:12 UTC
    It seems that mysqld is not running on localhost. Try '/etc/init.d/mysqld start' or whatever needed to launch the service.

      This is windows XP, so I ran "mysqld start" from the bin directory of mysql, but I got this:

      Can't start server: Bind on TCP/IP port: No error 050703 17:20:34 Do you already have another mysqld server running on p +ort: 3306 ? 050703 17:20:34 Aborting 050703 17:20:34 mysqld: Shutdown Complete

      But when I check the processes, there was no mysqld running. Also when I do a netstat -a, no process is listening at 3306. This really troubles me.

        This of course has nothing to do with perl, so if you want better help you should probably ask someplace specific. However, possibly your mysql had an "unclean shutdown", and left some kind of marker file in a temporary directory that makes it think it's still running when it isn't.