简体   繁体   English

通过matlab使用mysql时找不到空闲句柄

[英]Can't find free handle when using mysql via matlab

I'm accessing a mysql database via matlab on a fedora13 box. 我在fedora13盒子上通过matlab访问mysql数据库。

Problem: I can successfully open a connection, read from tables and close a connection to a database. 问题:我可以成功打开连接,从表中读取并关闭与数据库的连接。 I can repeat this for multiple different tables. 我可以为多个不同的表重复这个。 However, after some time (2-5 queries) I hit a wall and the next mysql open call throws the exception "Can't find free handle". 但是,经过一段时间(2-5次查询)后,我碰壁并且下一个mysql打开调用抛出异常“无法找到自由句柄”。 The only way to reconnect to any database after this is to restart matlab. 重新连接到任何数据库的唯一方法是重新启动matlab。 I've checked variables in memory (via whos) and checked for processes running on the database (show processlist;) but have not been able to find whats blocking my attempts to open connections. 我已经检查了内存中的变量(通过whos),并检查了数据库中正在运行的进程(显示进程列表;),但是找不到阻止我尝试打开连接的内容。

Looking at mysql.cpp , it seems to be the case that MAXCONN might be too low, or my mysql close might not be handled correctly, but I have already eliminated those possibilities. 查看mysql.cpp ,似乎是MAXCONN可能太低,或者我的mysql关闭可能无法正确处理的情况,但是我已经消除了这些可能性。

I would like to be able to open/close connections as my application needs without having to restart matlab in between to free database handles. 我希望能够在我的应用程序需要时打开/关闭连接,而无需重新启动matlab以释放数据库句柄。 Could someone offer some clarity as to how this process works? 有人可以提供一些关于这个过程如何工作的清晰度吗?

maybe consider writing a function that holds the connection and only opens a new connection when the old one has gone away. 也许考虑写一个函数来保存连接,并且仅在旧连接消失后才打开新连接。 That way you can reuse it. 这样你就可以重复使用它。

In outline it looks 概述它看起来

function conn = hold_connection_a
persistent local_connection
try
  test_connection(local_connection);
catch
  local_connection=establish_connection;
end
conn = local_connection;

establish connection then should be the function you use to connect and return your handle. establish connection然后应该是您用来连接和返回句柄的功能。 test_connection should send a simple query - like SELECT 1 and produce an error if it fails. test_connection应该发送一个简单的查询-类似于SELECT 1 ,如果失败则产生一个错误。

By the way - if you use more than one databases it would make sense to either have multiple of this hold_connections or make sure your statements always contain the database name. 顺便说一句 - 如果你使用多个数据库,那么拥有多个hold_connections或确保你的语句总是包含数据库名称是有意义的。

Unrelated: personally I use mYm since I find it quicker. 不相关:我个人使用mYm,因为我发现它更快。

Use close(conn) to free the connection made by database(...) when you don't need it anymore. 当您不再需要时,使用close(conn)释放数据库(...)建立的连接。 Changing MAXCONN to a higher value will just address the symptom, not the cause. 将MAXCONN更改为更高的值只会解决症状,而不是原因。

You can see the connections with 你可以看到与他们的联系

mysql

with no parameters. 没有参数。

mysql('close')

must solve such a problem. 必须解决这样的问题。

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

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