简体   繁体   English

无法连接到“本地主机”上的MySQL服务器(10055)

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

I am running three perl scripts sequentially. 我正在依次运行三个perl脚本。 Each of them connects to a Mysql database multiple times, and either selects or updates the information contained in the database. 它们每个都多次连接到Mysql数据库,并选择或更新数据库中包含的信息。 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). 在运行这三个脚本大约20次之后(与数据库连接/断开连接的次数超过此次数),我收到消息“无法连接到'localhost'上的MySQL服务器(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. 我在其他地方读过我可以使用mysql_auto_reconnect = 1将其重新连接到数据库,但是我不完全确定那是问题所在。 The Mysql server on my computer is still connected when the program crashes - I don't have to restart it. 程序崩溃时,我计算机上的Mysql服务器仍处于连接状态-我不必重新启动它。 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. 我想了解为什么这样做,而且我也不完全确定如何输入'“ mysql_auto_reconnect = 1”,因为当我这样做时,它告诉我使用旧式语法的DBI-> connect已过时。

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

or die("Error at select Trans: $DBI::errstr"); 或死(“选择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? 脚本完成后,您是否未断开与mysql的连接?

It is eat up resources in mysql. 它消耗了mysql中的资源。 Please, check mysql logs for clue. 请检查mysql日志以获取线索。

Regards, 问候,

How to Fix MySQL Error 10055 To fix the problem you need to increase the number of dynamic ports. 如何解决MySQL错误10055要解决此问题,您需要增加动态端口的数量。 Running the following Commands will give give you 50000 ports for dynamic use. 运行以下命令将为您提供50000个端口以供动态使用。

On Windows Server 2008 R2 Open command Prompt 在Windows Server 2008 R2上打开命令提示符

Type the following 输入以下内容
netsh int ipv4 set dynamicport tcp start=10000 num=50000
Press Enter 按Enter

Type the following 输入以下内容
netsh int ipv4 set dynamicport udp start=10000 num=50000
Press Enter 按Enter

Type the following 输入以下内容
netsh int ipv6 set dynamicport tcp start=10000 num=50000
Press Enter 按Enter

Type the following 输入以下内容
netsh int ipv6 set dynamicport udp start=10000 num=50000
Press Enter 按Enter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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