Pablo
Pablo

Reputation: 1435

Connection refused docker, laravel and mysql server

So I have this docker illustration

enter image description here

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

enter image description here

The laravel gives me an error like this

Connection refused mysql

Upvotes: 4

Views: 431

Answers (2)

Suvin94
Suvin94

Reputation: 240

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

Upvotes: 2

Udhav Sarvaiya
Udhav Sarvaiya

Reputation: 10111

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

Upvotes: 0

Related Questions