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:
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
5条答案
按热度按时间neekobn81#
You should define
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
0yg35tkg2#
I found I had to delete my docker volume as I had the wrong username/password, which can be done with:
sail down -v
sail up -d
sail artisan config:cache
sail artisan migrate
wooyq4lh3#
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=
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):oyxsuwqo4#
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.yeotifhr5#
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.