mysql远程访问次数限制问题???

duangexin521 2009-12-09 10:59:08
在本地插入数据库中,我运行5000次插入中间不会出现问题,但是如果是换成远程控制插入数据库,则只能运行到1316次的时候就提示不能建立连接了。请问是什么原因?怎么设置mysql???请老师指点一下。
...全文
165 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
duangexin521 2009-12-12
  • 打赏
  • 举报
回复
谢谢老师指点,我找到原因所在了。
ACMAIN_CHM 2009-12-09
  • 打赏
  • 举报
回复
| Connections | 22624 |
| Max_used_connections | 4 |

非常奇怪的数字!

你的实际的最大并发访问只有 4 个!
应该你是用的连接池。你连接不成功应该不是MYSQL的限制,而是你这个连接池的限制。
duangexin521 2009-12-09
  • 打赏
  • 举报
回复
老师 弱弱的问一下:我在本机插入数据库不会出错,但是远程访问就出错,是不是跟远程设置有关系?
duangexin521 2009-12-09
  • 打赏
  • 举报
回复
bool wxDbFreeConnection(wxDb *pDb)

Remarks

Searches the list of cached database connections connection for one matching the passed in wxDb instance. If found, that cached connection is freed.

Freeing a connection means that it is marked as available (free) in the cache of connections, so that a call to wxDbGetConnection is able to return a pointer to the wxDb instance for use. Freeing a connection does NOT close the connection, it only makes the connection available again.

duangexin521 2009-12-09
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 acmain_chm 的回复:]
贴出你的 wxDbFreeConnection() 的实现代码。

另外你的 show status like '%conn%'; 也贴出来。
[/Quote]

Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22623
Server version: 5.1.32-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show status like '%conn%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| Aborted_connects | 0 |
| Connections | 22624 |
| Max_used_connections | 4 |
| Ssl_client_connects | 0 |
| Ssl_connect_renegotiates | 0 |
| Ssl_finished_connects | 0 |
| Threads_connected | 2 |
+--------------------------+-------+
7 rows in set (0.06 sec)

mysql>
ACMAIN_CHM 2009-12-09
  • 打赏
  • 举报
回复
贴出你的 wxDbFreeConnection() 的实现代码。

另外你的 show status like '%conn%'; 也贴出来。
duangexin521 2009-12-09
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 acmain_chm 的回复:]
估计你线程开得太快,当你 wxDbFreeConnection(Conn); (这中间的代码是什么?) 也是需要时间通知MYSQL来释放这个connection的。
[/Quote]

老师 这中间没有代码啊?这个意思就是直接释放内存。不做其他任何操作。
duangexin521 2009-12-09
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 acmain_chm 的回复:]
max_connections          | 100
max_user_connections    | 0

检查一下这两个变量

然后再看一下状态。
show status like '%conn%';

SQL codemysql> show statuslike'%conn%';+--------------------------+-------+| Variable_name| Value|+--------------------------+-------+| Aborted_connects|0|| Connections|3|| Max_used_connections|2|| Ssl_client_connects|0|| Ssl_connect_renegotiates|0|| Ssl_finished_connects|0|| Threads_connected|2|+--------------------------+-------+7 rowsinset (0.00 sec)
[/Quote]

老师这个max_connections | 100
max_user_connections | 0

mysql> show variables like '%connect%';
+--------------------------+-------------------+
| Variable_name | Value |
+--------------------------+-------------------+
| character_set_connection | gb2312 |
| collation_connection | gb2312_chinese_ci |
| connect_timeout | 10 |
| init_connect | |
| max_connect_errors | 10 |
| max_connections | 100 |
| max_user_connections | 0 |
+--------------------------+-------------------+
7 rows in set (0.08 sec)

ACMAIN_CHM 2009-12-09
  • 打赏
  • 举报
回复
估计你线程开得太快,当你 wxDbFreeConnection(Conn); (这中间的代码是什么?) 也是需要时间通知MYSQL来释放这个connection的。
ACMAIN_CHM 2009-12-09
  • 打赏
  • 举报
回复
max_connections | 100
max_user_connections | 0

检查一下这两个变量

然后再看一下状态。
show status like '%conn%';

mysql> show status like '%conn%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| Aborted_connects | 0 |
| Connections | 3 |
| Max_used_connections | 2 |
| Ssl_client_connects | 0 |
| Ssl_connect_renegotiates | 0 |
| Ssl_finished_connects | 0 |
| Threads_connected | 2 |
+--------------------------+-------+
7 rows in set (0.00 sec)
duangexin521 2009-12-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wwwwb 的回复:]
提示什么错误信息
[/Quote]

if(!Conn->Open(wxT("driver={mysql odbc 5.1 driver};server=192.168.100.13;DSN=icdata_db;charset=gb2312;database=icdata_db;uid=root;pwd=duangexin;port=3306;"),DBfailOnDataTypeUnsupported))//使用驱动程序的方式打开数据库
{
wxMessageBox("不能建立连接","DB CONNECTION ERROR", wxOK | wxICON_EXCLAMATION);
}

也就是运行到一定数量的时候 就无法打开连接了?弹出对话框 不能建立连接。
duangexin521 2009-12-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 acmain_chm 的回复:]
你的程序中是否及时关闭了连接? mysql 中是有最大并发连接数限制的。
[/Quote]
老师 我都关闭了啊。只要new了的变量都全部释放了。
void DBDialog::Test()
{
m_comboBox3->Append( wxT("TXT.txt") );
m_comboBox3->SetSelection(0);
wxDbConnectInf *DbConnectInf = NULL; // 定义数据库连接信息指针DB connection information
wxDb *Conn = NULL; // 定义数据库连接指针Database connection
wxDbTable *table = NULL; // 定义数据表指针Data table to mysql

DbConnectInf = new wxDbConnectInf(0, wxT(""), wxT(""), wxT(""));//这里定义的内容基本没用,但不定义会报错

Conn = new wxDb(DbConnectInf->GetHenv());

bool DBfailOnDataTypeUnsupported=!true;//

if(!Conn->Open(wxT("driver={mysql odbc 5.1 driver};server=192.168.100.13;DSN=icdata_db;charset=gb2312;database=icdata_db;uid=root;pwd=duangexin;port=3306;"),DBfailOnDataTypeUnsupported))//使用驱动程序的方式打开数据库
{
wxMessageBox("不能建立连接!","DB CONNECTION ERROR", wxOK | wxICON_EXCLAMATION);
wxDbFreeConnection(Conn);
DbConnectInf->FreeHenv();
return ;
}

table = new wxDbTable(Conn, wxT("ictable"),10,wxT(""),!wxDB_QUERY_ONLY, wxT(""));

//定义保存列内容的变量
wxString sst;
wxChar ChipNumbers[100];
wxChar ChipCounts[100];
wxChar ChipTypes[100];
wxChar InspectorNumbers[100];
wxChar CheckTimes[100];
wxChar BugTypes[100];
wxChar CheckItems[100];
wxChar CheckResults[100];
wxChar ErrorCounts[100];
wxChar ErrorPercents[100];

//有几列就定义几列
table->SetColDefs(0, wxT("ChipNumber"), DB_DATA_TYPE_VARCHAR,ChipNumbers, SQL_C_WXCHAR, sizeof(ChipNumbers), true, true);
table->SetColDefs(1, wxT("ChipCount"), DB_DATA_TYPE_VARCHAR, ChipCounts,SQL_C_WXCHAR, sizeof(ChipCounts), true, true);
table->SetColDefs(2,wxT("ChipType"),DB_DATA_TYPE_VARCHAR,ChipTypes,SQL_C_WXCHAR,sizeof(ChipTypes),true,true);
table->SetColDefs(3, wxT("InspectorNumber"), DB_DATA_TYPE_VARCHAR,InspectorNumbers, SQL_C_WXCHAR, sizeof(InspectorNumbers), true, true);
table->SetColDefs(4, wxT("CheckTime"), DB_DATA_TYPE_VARCHAR, CheckTimes,SQL_C_WXCHAR, sizeof(CheckTimes), true, true);
table->SetColDefs(5,wxT("BugType"),DB_DATA_TYPE_VARCHAR,BugTypes,SQL_C_WXCHAR,sizeof(BugTypes),true,true);
table->SetColDefs(6, wxT("CheckItem"), DB_DATA_TYPE_VARCHAR,CheckItems, SQL_C_WXCHAR, sizeof(CheckItems), true, true);
table->SetColDefs(7, wxT("CheckResult"), DB_DATA_TYPE_VARCHAR, CheckResults,SQL_C_WXCHAR, sizeof(CheckResults), true, true);
table->SetColDefs(8,wxT("ErrorCount"),DB_DATA_TYPE_VARCHAR,ErrorCounts,SQL_C_WXCHAR,sizeof(ErrorCounts),true,true);
table->SetColDefs(9, wxT("ErrorPercent"), DB_DATA_TYPE_VARCHAR,ErrorPercents, SQL_C_WXCHAR, sizeof(ErrorPercents), true, true);

//打开DbTable对象
if( !table->Open())
{
wxMessageBox("不能打开数据库结构表!");
wxDELETE(table);
table = 0;
Conn->Close();
wxDbFreeConnection(Conn);
Conn = 0;
DbConnectInf->FreeHenv();
return;
}

//添加新记录
wxStrcpy(ChipNumbers, wxT("ccc")); //ChipNumbers所绑定的字段将添加一条记录
wxStrcpy(ChipCounts,wxT("aa"));
wxStrcpy(ChipTypes,wxT("aa"));
wxStrcpy(InspectorNumbers,wxT("aa"));
wxStrcpy(CheckTimes,wxT("2009-11-09"));
wxStrcpy(BugTypes,wxT("aa"));
wxStrcpy(CheckItems,wxT("32"));
wxStrcpy(CheckResults,wxT("false"));
wxStrcpy(ErrorCounts,wxT("32"));
wxStrcpy(ErrorPercents,wxT("32"));

if(!table->Insert())

{

//判断添加是否成功
wxMessageBox("添加失败!");

wxDELETE(table);
table = 0;
Conn->Close();
wxDbFreeConnection(Conn);
Conn = 0;
DbConnectInf->FreeHenv();
return;

}

//提交更新数据库

table->GetDb()->CommitTrans();

//关闭DbTable对象
if(table)
{
wxDELETE(table);
table = 0;
}

//关闭连接
if(Conn)
{
Conn->Close();
wxDbFreeConnection(Conn);
Conn = NULL;
//wxDbCloseConnections();
}

//释放环境
wxDELETE(DbConnectInf);
//DbConnectInf->FreeHenv();
}
duangexin521 2009-12-09
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wwwwb 的回复:]
MY。INI中的内容
[/Quote]

怎么修改?
wwwwb 2009-12-09
  • 打赏
  • 举报
回复
MY。INI中的内容
ACMAIN_CHM 2009-12-09
  • 打赏
  • 举报
回复
你的程序中是否及时关闭了连接? mysql 中是有最大并发连接数限制的。
wwwwb 2009-12-09
  • 打赏
  • 举报
回复
提示什么错误信息
ACMAIN_CHM 2009-12-09
  • 打赏
  • 举报
回复
[Quote]老师为什么你用这个语句出来的跟我不一样???[/Quote]

这个语句是显示你当前MYSQL数据库服务的状态,当然每台机都会有差别了。
duangexin521 2009-12-09
  • 打赏
  • 举报
回复
show status like '%conn%'
老师为什么你用这个语句出来的跟我不一样???
我在本机插入数据库不会出错,但是远程访问就出错,是不是跟远程设置有关系?还是??
ACMAIN_CHM 2009-12-09
  • 打赏
  • 举报
回复
这方面我也没试过,建议到VC之类的版块去问一下。
duangexin521 2009-12-09
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 acmain_chm 的回复:]
| Connections        | 22624 |
| Max_used_connections  | 4  |

非常奇怪的数字!

你的实际的最大并发访问只有 4 个!
应该你是用的连接池。你连接不成功应该不是MYSQL的限制,而是你这个连接池的限制。

[/Quote]

老师这个链接池的限制怎么更改???哪里修改?

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧