Ask Your Question

Revision history [back]

To establish a connection to MySQL in Laravel/Sail while operating in WSL2, you need to follow these steps:

  1. First, make sure that you have Docker Desktop installed and running on your Windows machine.

  2. Open up your WSL2 terminal and navigate to your Laravel project directory.

  3. Next, run the following command to install Laravel Sail:

composer require laravel/sail --dev

  1. Once the installation is complete, run the following command to start the Sail containers:

./vendor/bin/sail up

  1. Once the Sail containers are running, you can connect to MySQL by running the following command:

./vendor/bin/sail mysql

  1. This will open up the MySQL command prompt, where you can enter your SQL commands.

Note: Make sure to update your database configuration in the .env file to connect to the database using the following credentials:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=sail
DB_PASSWORD=password