I’m learning full stack development by creating a project with a MySQL database/express API. My application was working “properly”, then I tried to dockerize it. I wrote a docker-compose file:
services:
db:
image: mysql:latest
command: --bind-address='0.0.0.0'
container_name: mysql_db
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: housesdb
MYSQL_PASSWORD: password
volumes:
- app-data:/var/lib/mysql
networks:
- my-network
version: '3'
services:
db:
image: mysql:latest
command: --bind-address='0.0.0.0'
container_name: mysql_db
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: housesdb
MYSQL_PASSWORD: password
volumes:
- app-data:/var/lib/mysql
networks:
- my-network
api:
build: ./Backend
container_name: node_api
ports:
- "3005:3005"
environment:
DB_HOST: db
DB_PORT: 3306
DB_USER: root
DB_PASSWORD: password
DB_NAME: housesdb
depends_on:
- db
networks:
- my-network
web:
build: ./frontend-jm
container_name: react_app
ports:
- "3000:3000"
depends_on:
- db
- api
networks:
- my-network
networks:
my-network:
driver: bridge
volumes:
app-data:
The problem is that my node.js API has an “ECONNREFUSED” error while trying to get a connection with the MySQL container. I can connect to the MySQL database with MySQL Workbench from my host.
At first, I thought that MySQL was blocking access from app when the app address wasn’t localhost. To verify it, I started a MySQL container like this: docker run -it --rm mysql:tag --verbose --help
, but I can see that the value “bind-address” from the configuration file of MySQL is “*” in the terminal.
After I made some research, I tried this command:
alter user 'root'@'%' identified with mysql_native_password by 'password'
And I then had this error:
Error Code: 1524. Plugin ‘mysql_native_password’ is not loaded
How can I fix this?
Drose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2