I'm trying to spool up an existing project locally using Laravel Sail. I'm continually getting the 1049 unknown database error. I've tried the following:
sail php artisan config:clear
sail php artisan config:cache
I've also tried replacing mysql as the host to using 127.1.1.0 like the .env.example file, but no luck.
I've also tried to rebuild the container but nothing seems to resolve the problem.
Here is my .env file (when I try with a user other than root I get a 1045 error saying access denied, wondering if these are related):
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
Here's my docker-compose.yml file:
mysql:
image: 'mysql:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
database config:
'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' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
UPDATE:
I installed a fresh install of laravel in an adjacent directory on the the same WSL installation and verified the docker-compose.yml, .env, and database.php config files are all the same. The new install booted up fine and I can connect to the DB, the existing project still doesn't work. Really confused..