doupu1949 2015-12-08 17:49
浏览 43

Laravel 5.1:PDOException:已超出'max_user_connections'资源

I am running functional tests in Laravel 5.1 against a MySQL database on a staging server and get the following error:

PDOException: SQLSTATE[HY000] [1226] User 'username' has exceeded the 'max_user_connections' resource (current value: 20)

The TestCase class looks like:

<?php

use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class TestCase extends Illuminate\Foundation\Testing\TestCase
{

    /**
     * Rollback and execute migrations for each test.
     */
    use DatabaseTransactions;

    /**
     * The base URL to use while testing the application.
     *
     * @var string
     */
    protected $baseUrl = 'http://localhost';

    /**
     * Is this the first test.
     *
     * @var bool
     */
    protected static $isInitialTest = true;

    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = require __DIR__.'/../bootstrap/app.php';

        $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

        return $app;
    }

    /**
     * If this is the first test of the actual test suite:
     * Delete all test table records and run migrations.
     *
     * @return void
     */
    public function setUp()
    {
        parent::setUp();

        if(self::$isInitialTest){

            self::$isInitialTest = false;

            Artisan::call('migrate');
        }
    }

}

And a failing test (after a lot of other tests ran successfully) looks like

use Illuminate\Foundation\Testing\WithoutMiddleware;

class AreasTest extends TestCase
{
    /**
     * Add a new area to a tenant.
     */
    public function testAddArea()
    {
        $tenant = factory('XXX\Tenant', 'xxx')->create();

        $this->visit("admin/tenants/{$tenant->id}")
            ->click('…')
            ->click('N…')
            ->type('…', 'name')
            ->press('…')
            ->see('…');
    }
…
}

I am running the tests like this vendor/phpunit/phpunit/phpunit --bootstrap ./bootstrap/autoload.php ./tests/

Is there anything beside raising max_user_connections I can do to control how much parallel db connections are open? If possible I do not want to slow down the tests :)

On my local dev machine max_user_connections is set to 0 so there is no limitation and no error.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答