I add a read and write database connection in the current laravel application, like this:
'mysql' => [
'read' => [
'host' => [
env('DB_HOST_READONLY', '127.0.0.1'),
],
],
'write' => [
'host' => [
env('DB_HOST', '127.0.0.1'),
],
],
'sticky' => true,
'driver' => 'mysql',
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
...
Because I have CI/CD setup on Gitlab I get this error:
cp .env.example .env
php artisan migrate:refresh --seed
In Connection.php line 692:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = oauth_test and table_name = migrations and table_type = 'BASE TABLE')
In Connector.php line 70:
SQLSTATE[HY000] [2002] Connection refused
I also add in .env.example file DB_HOST_READONLY parameter which is also 127.0.0.1, the same as DB_HOST parameter. Without this change, I have this in .env.example:
DB_HOST=127.0.0.1
and in database.php file:
'host' => env('DB_HOST', '127.0.0.1'),
and all was woked well. Variables in CI/CD on Gitlab are:
variables:
MYSQL_USER: root
MYSQL_ALLOW_EMPTY_PASSWORD: 1
MYSQL_DATABASE: oauth_test
DB_HOST: mysql
Can you help me or have some idea? Be free to ask if you need something more.
I find out how it works and maybe someone uses this information and helps him also: into .env.testing needs to change:
DB_HOST=127.0.0.1
DB_HOST_READONLY=127.0.0.1
into:
DB_HOST=mariadb
DB_HOST_READONLY=mariadb
and into gitlab-ci.yml file from this:
variables:
MYSQL_USER: root
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
DB_HOST: mysql
into this:
variables:
MYSQL_USER: root
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
DB_HOST: mariadb