n8udd
n8udd

Reputation: 711

Can't workout why TablePlus refuses to connect to db with Sail 0n 3307

I am running using Sail for my side project, and use Homestead for work. I get conflicts with port 3306, so I moved Sail to 3307, but now for some reason I can't get TablePlus to connect to the DB. Just to be clear, the site loads in the browser and sail tinker, sail artisan:migrate both work fine, it's JUST TablePlus that isn't working?! It worked fine last weekend when I was using it, but after getting the issue with something using 3306 I decided to change the port to 3307 I've run docker-compose down -v to delete the volume including the db, and brought it back up, and the site works after a migration, but still nothing with TP. The following is my .env:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=tall_events
DB_USERNAME=sail
DB_PASSWORD=password
FORWARD_DB_PORT=3307

And my docker-compose.yml file:

mysql:
 image: "mysql:8.0"
 ports:
      - "${FORWARD_DB_PORT:-3307}:3307"
 environment:
 MYSQL_ROOT_PASSWORD: "${DB_PASSWORD}"
 MYSQL_DATABASE: "${DB_DATABASE}"
 MYSQL_USER: "${DB_USERNAME}"
 MYSQL_PASSWORD: "${DB_PASSWORD}"
 MYSQL_ALLOW_EMPTY_PASSWORD: "no"
 volumes:
      - "sailmysql:/var/lib/mysql"

It's showing as port 3307 on Docker Desktop: enter image description here

But when I try to connect with TablePlus on 3307 I get the following: enter image description here

And when I try 3306 I get enter image description here

Upvotes: 1

Views: 3554

Answers (2)

Matt
Matt

Reputation: 360

When you run sail up -d docker-compose creates a virtual network. With your existing config, mysql is still listening on port 3306 on that virtual network, but in the docker-compose.yml you're mapping port 3307 on you machine to 3307 on the mysql container.

What you need to do is map port 3307 on your machine to port 3306 on the mysql container. To do that, you can update the ports section of your docker-compose.yml like so:

mysql:
 ports:
   - "3307:3306"

This means you can connect to localhost:3307 with TablePlus, but your Laravel app, which is running in a docker container connected to the virtual network, can still connect to mysql:3306 on that virtual network.

Upvotes: 1

Bug Hunter
Bug Hunter

Reputation: 26

Check your host in TablePlus.

In your .env file, the DB_HOST is "mysql". The host in TablePlus looks like it's set to "127.0.0.1"

Also, check the database name. It looks like it's set to "da"-something, when it should be "tall_events"

Upvotes: 0

Related Questions