Level 73
Sounds to me like you need to check your env file and make sure you have the correct address and port for your MariaDB container.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I start to develop with a MySQL-DB and now i we wanna switch to MariaDB. So far as I know, there should be no problem but as I start with sail up and run sail artisan migrate there rise some confusing errors in the cli.
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for locahost failed: Name or service not known (Connection: mysql, SQL: select table_name as `name`, (data_length + index_length) as `size`, table_comment as `comment`, engine as `engine`, table_collation as `collation` from information_schema.tables where table_schema = '<OUR PROJECT NAME>' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)
A part of docker-compose.yml File
mariadb:
image: 'mariadb:latest'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
MARIADB_AUTO_UPGRADE: true
volumes:
- 'sail-<OUR PROJECT NAME>-mariadb:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
test:
- CMD
- mysqladmin
- ping
- '-p${DB_PASSWORD}'
retries: 3
timeout: 5s
A part of database.php:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_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'),
]) : [],
],
With Usernamen and password i can connect to the database by MySQL-Workbench.
Is there something wrong iin my config, or is there any additional setting to do?
Please or to participate in this conversation.