22

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

1
  • thanks! that was a mysql@5.7 instance running on my case May 16, 2021 at 14:36

6 Answers 6

15

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

11

I found I had to delete my docker volume as I had the wrong username/password, which can be done with:

  1. Remove volumes with sail down -v
  2. Then back up again with sail up -d
  3. Re-cache the .env variables with sail artisan config:cache
  4. Then re-migrating the db with sail artisan migrate
7

I have mysql installed on my laptop outside of sail, so this is what worked for me (after you add this to your .env, you'll need to restart sail so it can take affect in docker):

.env: FORWARD_DB_PORT=3307

For TablePlus, you really just need the Name, Host, the modified port, and user/pass (sail defaults to root and no password). Enter the same database name as .env:DB_DATABASE=

enter image description here

If you look at your docker-compose.yml, you'll see the default is set to 3306 and this overrides it (nothing you need to do here, just an FYI):

mysql:
    image: 'mysql:8.0'
    ports:
        - '${FORWARD_DB_PORT:-3306}:3306'
    environment:
        MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
        MYSQL_DATABASE: '${DB_DATABASE}'
    (...etc...)
1
  • 1
    I made FORWARD_DB_PORT=33066, sail down, sail up as you said but still could not connect. Dec 16, 2022 at 2:41
2

I had mysql running through homebrew as well, which I found out was the issue. Stopping it (brew services stop mysql) and then attempting to connect solved the issue.

1

Probably, you already have a bank installed on port 3306, change the tags below in the .env to another port: (example 3307)

DB_PORT=3307
FORWARD_DB_PORT=3307

I think it works.

1
  • fuck fuck fuck fucking fuck fuck fuck... Thank you friend Jun 9 at 16:45
1

For me it was something simple, I don't know why but when I tried 127.0.0.1 instead of localhost, it worked.

1
  • That is because "localhost" will use a local socket connection, "127.0.0.1" will go through the network.
    – René Roth
    Jul 5 at 10:24

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.