简体   繁体   中英

Can't connect to MySQL server on 'localhost' (10055)

I am running three perl scripts sequentially. Each of them connects to a Mysql database multiple times, and either selects or updates the information contained in the database. After running these three scripts about 20~ times (& connecting/disconnecting from database many more times than this), I get the message 'Can't connect to MySQL server on 'localhost' (10055).

I have read elsewhere that I could get it to reconnect to the database using mysql_auto_reconnect=1, however I'm not entirely sure that that is the problem. The Mysql server on my computer is still connected when the program crashes - I don't have to restart it. I wanted to understand why it is doing this, and also I'm not entirely sure how I put in '"mysql_auto_reconnect=1", as when I do this it tells me DBI->connect using old style syntax is deprecated.

my $dbh_m= DBI->connect("dbi:mysql:XXX","root","XXX","mysql_auto_reconnect=1")

or die("Error at select Trans: $DBI::errstr");

Do I also need to write this in every time I connect to the database? (Putting that into one of the connections doesn't solve the problem, I still get error messages from all the others - it doesn't begin to run again and then re-crash later). Is this a problem with me connecting/disconnecting to the database to many times?

Thank you!

DBI->connect("dbi:mysql:XXX", "root", "XXX", { mysql_auto_reconnect => 1 })

What error message do you get?

You should probably do something like:

my $dbh;
{
    local $@;
    do {
        eval { 
            $dbh = DBI->connect("dbi:mysql:XXX", "root", "XXX", { mysql_auto_reconnect => 1 })
        };
        if ( $@ ) {
            warn "Error: $DBI::errstr\n";
            warn "Trying to reconnect in 5 sec.\n";
            sleep 5;
        }
    } while ($@);
}

Just in case that the database is not responding or there are too many connections.

Maybe you are not disconnecting from the mysql when your script finishes?

It is eat up resources in mysql. Please, check mysql logs for clue.

Regards,

How to Fix MySQL Error 10055 To fix the problem you need to increase the number of dynamic ports. Running the following Commands will give give you 50000 ports for dynamic use.

On Windows Server 2008 R2 Open command Prompt

Type the following
netsh int ipv4 set dynamicport tcp start=10000 num=50000
Press Enter

Type the following
netsh int ipv4 set dynamicport udp start=10000 num=50000
Press Enter

Type the following
netsh int ipv6 set dynamicport tcp start=10000 num=50000
Press Enter

Type the following
netsh int ipv6 set dynamicport udp start=10000 num=50000
Press Enter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM