Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to database Laravel Sail

I'm trying to create a simple laravel project and I'm following a laracast to set up the project with Sail. The project is running fine and I was able to migrate with vendor/bin/sail artisan migrate.

The next step in the laracast is to connect to the database with tableplus. But i can't get past this step. I get this error in tableplus: enter image description here

This is my .env:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=csv
DB_USERNAME=root
DB_PASSWORD=

I didn't change any settings in the docker-compose file, in docker desktop i can see that mysql is running on port 3306 and that there's no password set.

Any idea how i can fix this and connect to the database?

EDIT: found the issue. When I ran brew services list, is saw that an older version mysql was still running. Stopped it with brew services stop mysql and now i can connect

like image 887
FonsVC Avatar asked Jan 17 '21 13:01

FonsVC


People also ask

What is Laravel sail and how do I use it?

When using Laravel Sail, your application is executing within a Docker container and is isolated from your local computer. However, Sail provides a convenient way to run various commands against your application such as arbitrary PHP commands, Artisan commands, Composer commands, and Node / NPM commands.

What does the--devcontainer option do in Laravel?

The --devcontainer option will instruct the sail:install command to publish a default .devcontainer/devcontainer.json file to the root of your application: By default, Sail commands are invoked using the vendor/bin/sail script that is included with all new Laravel applications:

How do I test a Minio file system in Laravel?

For example, when using MinIO, your filesystem environment variable configuration should be defined as follows: Laravel provides amazing testing support out of the box, and you may use Sail's test command to run your applications feature and unit tests. Any CLI options that are accepted by PHPUnit may also be passed to the test command:

What is artisan serve in Laravel sail?

Laravel Sail relies on artisan serve to serve your application. The artisan serve command only accepts the XDEBUG_CONFIG and XDEBUG_MODE variables as of Laravel version 8.53.0. Older versions of Laravel (8.52.0 and below) do not support these variables and will not accept debug connections.


1 Answers

You should define

FORWARD_DB_PORT=3306

in your .env this will expose mysql on that port for development connections. I would recommend to not expose this port on production.

https://github.com/laravel/sail/blob/e3d601598e735407070dd50e09ab6e0c68ab32ae/stubs/mysql.stub#L4

like image 109
online Thomas Avatar answered Oct 26 '22 21:10

online Thomas