简体   繁体   中英

Connection refused docker, laravel and mysql server

So I have this docker illustration

在此处输入图像描述

As you can see my laravel app is trying to do a database connection in the container where the MySQL server is being installed and setup.

The instance of laravel app is accessible using this port

192.168.0.XX:3021

and the container is accessible using this IP

192.168.0.61

and the MySQL Server credential is:

USER3021 I just tried to create this user account with '%' wild card capability and with

GRANT ALL PRIVILEGES ON *.* TO 'USER3021' IDENTIFIED BY 'xxxxxxx';

and when I try to connect the laravel app and MySQL server with this .env file

 DB_CONNECTION=mysql
 DB_HOST=192.168.0.XX
 DB_PORT=3306
 DB_DATABASE=myTable
 DB_USERNAME=USER3021
 DB_PASSWORD=xxxxxxx

在此处输入图像描述

The laravel gives me an error like this

Connection refused mysql

You are trying to access Mysql through port 3021 but you defined port 3306 Try changing them in.env file

 DB_CONNECTION=mysql
 DB_HOST=192.168.0.XX
 DB_PORT=3021
 DB_DATABASE=myTable
 DB_USERNAME=USER3021
 DB_PASSWORD=xxxxxxx

Open your .env file and change port: DB_PORT=3021 instead of DB_PORT=3306

DB_CONNECTION=mysql 
DB_HOST=192.168.0.XX 
DB_PORT=3021 
DB_DATABASE=myTable     // Your Database Name 
DB_USERNAME=USER3021   // Yout Database Username
DB_PASSWORD=xxxxxxx   // Your Database Password 

After completion of .env edit please enter this command in your terminal to clear cache:

php artisan config:clear

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM