So I'm having troubles getting my Laravel app to connect to my MySQL container. With the following docker-compose I get the error:
Connection refused (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations)
database:
image: mysql:5.7
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=root"
- "MYSQL_PASS=secret"
ports:
- "33061:3306"
If I change my image to mysql I get the error:
The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations)
The server requested authentication method unknown to the client [caching_sha2_password]
My laravel .env looks like this:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=root
DB_PASSWORD=secret
I tried DB_HOST=database as well.
Any help would be great. Thanks!
OS: OSX
I guess you have some old data in dbdata
folder and they are causing a problem. If you don't need old DB, then just delete the content of this folder and start mysql container from the scratch. Another problem is a port. You are publishing MySQL on the port 33061, so Laravel should be configured with DB_PORT=33061
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.