[Laravel系列] 配置mysql数据库读写分离

项目为了提升性能

需要select查询的时候,读取从库mysql数据

插入修改的时候,操作主库mysql数据

 

在laravel中只需要配置一下就可以实现

read就是从库的连接信息,write就是主库的连接信息,在.env里可以进行配置

        'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_OA_URL'),
            //配置数据库读写分离
            'read' => [
                'host' => env('DB_OA_READ_HOST', '127.0.0.1'),
                'port' => env('DB_OA_READ_PORT', '3306'),
                'database' => env('DB_OA_READ_DATABASE', 'forge'),
                'username' => env('DB_OA_READ_USERNAME', 'forge'),
                'password' => env('DB_OA_READ_PASSWORD', ''),
            ],
            'write' => [
                'host' => env('DB_OA_HOST', '127.0.0.1'),
                'port' => env('DB_OA_PORT', '3306'),
                'database' => env('DB_OA_DATABASE', 'forge'),
                'username' => env('DB_OA_USERNAME', 'forge'),
                'password' => env('DB_OA_PASSWORD', ''),
            ],
            'unix_socket' => env('DB_OA_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

 

上一篇:ob混淆


下一篇:model.eval()和with torch.no_grad()的区别