MySQL:用户有超过 'max_user_connections' 个活动连接
MySQL: user has more than 'max_user_connections' active connections
我知道这是一个很好讨论的话题,但我的情况有点不同。我有一个 SaaS 服务,每个订阅都有自己的数据库。
通过在我的 25 个数据库中查询 SHOW PROCESSLIST
,我在每个数据库中得到相同的结果:
所有数据库似乎都没有任何连接,但我仍然收到错误:
User already has more than 'max_user_connections' active connections
我正在使用共享主机 CPanel,限制 max_connections
是 150。
怎么可能max_connections
已经到了processlist
却显示什么都没有查询呢?另外,如何在没有主机帮助的情况下重置连接?
这是一个 PHP 带有 CodeIgniter 框架的项目。
已解决.
联系主机后,他们将 max_user_connections
增加到 20,但问题仍然存在。项目已经运行一年多没出问题,搞得我一头雾水
我使用这个钩子 https://github.com/ozanmora/ci_log_query 来打印所有正在完成的查询,很明显我正在连接到多个未被使用的模型。
例如,在我所有的 类(和控制器)中,我在构造函数中加载了所有模型,其中一些模型仅在特定功能中使用,因此它们在未被使用的情况下消耗资源。
示例:
public function _construct()
{
$this->load->model('a_model');
$this->load->model('b_model');
$this->load->model('c_model');
$this->load->model('d_model');
$this->load->model('e_model');
}
而且我只在某些函数中调用它们,例如:
public function test()
{
$this->a_model->doSometing();
$this->b_model->doSometing();
}
public function test2()
{
$this->c_model->doSometing();
}
public function test3()
{
$this->d_model->doSometing();
}
避免加载不必要的 models/connections 的解决方案是仅在需要时加载模型。虽然这以前没有任何问题,但我最终修复了我所有的 controllers/classes(相当多)。连接大大减少,现在可以正常工作了。
public function _construct()
{
}
public function test()
{
$this->load->model('a_model');
$this->load->model('b_model');
$this->a_model->doSometing();
$this->b_model->doSometing();
}
public function test2()
{
$this->load->model('c_model');
$this->c_model->doSometing();
}
public function test3()
{
$this->load->model('d_model');
$this->d_model->doSometing();
}
我知道这是一个很好讨论的话题,但我的情况有点不同。我有一个 SaaS 服务,每个订阅都有自己的数据库。
通过在我的 25 个数据库中查询 SHOW PROCESSLIST
,我在每个数据库中得到相同的结果:
所有数据库似乎都没有任何连接,但我仍然收到错误:
User already has more than 'max_user_connections' active connections
我正在使用共享主机 CPanel,限制 max_connections
是 150。
怎么可能max_connections
已经到了processlist
却显示什么都没有查询呢?另外,如何在没有主机帮助的情况下重置连接?
这是一个 PHP 带有 CodeIgniter 框架的项目。
已解决.
联系主机后,他们将 max_user_connections
增加到 20,但问题仍然存在。项目已经运行一年多没出问题,搞得我一头雾水
我使用这个钩子 https://github.com/ozanmora/ci_log_query 来打印所有正在完成的查询,很明显我正在连接到多个未被使用的模型。
例如,在我所有的 类(和控制器)中,我在构造函数中加载了所有模型,其中一些模型仅在特定功能中使用,因此它们在未被使用的情况下消耗资源。
示例:
public function _construct()
{
$this->load->model('a_model');
$this->load->model('b_model');
$this->load->model('c_model');
$this->load->model('d_model');
$this->load->model('e_model');
}
而且我只在某些函数中调用它们,例如:
public function test()
{
$this->a_model->doSometing();
$this->b_model->doSometing();
}
public function test2()
{
$this->c_model->doSometing();
}
public function test3()
{
$this->d_model->doSometing();
}
避免加载不必要的 models/connections 的解决方案是仅在需要时加载模型。虽然这以前没有任何问题,但我最终修复了我所有的 controllers/classes(相当多)。连接大大减少,现在可以正常工作了。
public function _construct()
{
}
public function test()
{
$this->load->model('a_model');
$this->load->model('b_model');
$this->a_model->doSometing();
$this->b_model->doSometing();
}
public function test2()
{
$this->load->model('c_model');
$this->c_model->doSometing();
}
public function test3()
{
$this->load->model('d_model');
$this->d_model->doSometing();
}