Docker, node.js, mysql: Unhandled rejection SequelizeAccessDeniedError

kuppi

I try to dockerize a project which consists of a node.js app which connects to a mysql database.

Both containers start, but the node container always gets an "SequelizeAccessDeniedError"

> [email protected] start
> node app.js

Use no environment variables
{
  username: 'scrumboard',
  password: 'scrumboard',
  database: 'scrumboard',
  host: 'mysql',
  dialect: 'mysql',
  port: 3306,
  operatorsAliases: false
}
(node:20) [SEQUELIZE0004] DeprecationWarning: A boolean value was passed to options.operatorsAliases. This is a no-op with v5 and should be removed.
(Use `node --trace-deprecation ...` to show where the warning was created)
server is running on port 3000
Unhandled rejection SequelizeAccessDeniedError: Access denied for user 'scrumboard'@'172.23.0.3' (using password: YES)
    at /scrumboard-app/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:125:19
    at tryCatcher (/scrumboard-app/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/scrumboard-app/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/scrumboard-app/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/scrumboard-app/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/scrumboard-app/node_modules/bluebird/js/release/promise.js:725:18)
    at _drainQueueStep (/scrumboard-app/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/scrumboard-app/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/scrumboard-app/node_modules/bluebird/js/release/async.js:102:5)
    at Async.drainQueues [as _onImmediate] (/scrumboard-app/node_modules/bluebird/js/release/async.js:15:14)
    at process.processImmediate (node:internal/timers:471:21)

a user is connected

The mysql container says the same:

2022-11-29T15:11:59.491328Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2022-11-29T15:11:59.491368Z 0 [Note] IPv6 is available.
2022-11-29T15:11:59.491377Z 0 [Note]   - '::' resolves to '::';
2022-11-29T15:11:59.491389Z 0 [Note] Server socket created on IP: '::'.
2022-11-29T15:11:59.495079Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2022-11-29T15:11:59.499174Z 0 [Note] Event Scheduler: Loaded 0 events
2022-11-29T15:11:59.499449Z 0 [Note] mysqld: ready for connections.
Version: '5.7.40'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
2022-11-29T15:12:00.101178Z 2 [Note] Access denied for user 'scrumboard'@'172.23.0.3' (using password: YES)

So it looks like the communication between them is working.

This is my docker-compose file:

version: '3.8'

services: 
  mysql:
    image: mysql:5.7
    restart: unless-stopped
    env_file: ./.env
    environment:
      - MYSQL_ROOT_PASSWORD=scrumboard
      - MYSQL_PASSWORD=scrumboard
      - MYSQL_DATABASE=scrumboard
      - MYSQL_USER=scrumboard
    ports:
      - 3306:3306
      # [HOST:]CONTAINER

    volumes:
      - db:/var/lib/mysql

  app:
    depends_on:
      - mysql
    build: ./scrumboard-app
    restart: unless-stopped
    env_file: ./.env
    ports:
     - 3000:3000
    stdin_open: true
    tty: true

volumes:
  db:

And this is the config file which is used by sequelize:

  "development": {
    "username": "scrumboard",
    "password": "scrumboard",
    "database": "scrumboard",
    "host": "mysql",
    "dialect": "mysql",
    "port": 3306,
    "operatorsAliases": false
  }

This is the code where the connection to the DB is established:

const config = require(__dirname + '/../config/config.json')[env];

let sequelize;

 console.info('Use no environment variables');
 console.info(config);
 sequelize = new Sequelize(config.database, config.username, config.password, config);

I have no idea what's wrong here because I tripple checked the username, password, etc. Any ideas what the problem could be?

Salketer

My guess is that the user is not allowed to connect from outside?

Could you check the result of

SELECT user, host, account_locked, password_expired FROM user

You should see your user there and it should not be locked or expired.

Also, host should either match the IP 172.23.0.3 or a wildcard that would fit the IP.

To allow connection from anywhere to your user, you can do:

GRANT ALL PRIVILEGES
ON *.*
TO 'scrumboard'@'%';

Note that this query will grant ALL privileges on EVERYTHING. This is good to test first, so we can troubleshoot your connection, but appropriate privileges should be put in place afterwards.

If you still cannot connect, check that you can connect from inside the mysql container directly, if you can this will mean at least that the credentials are valid. If not, you'll need to try and reset the password, double check username etc.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Jest mockRejectedValue throws unhandled promise rejection in node

caching promises leads to Unhandled promise rejection in Node.js

Bluebird.js Unhandled Rejection Error using request

How to Handle Unhandled promise rejection in async object method in Node.js expressjs?

Node.js Unhandled promise rejection

Node.js Unhandled Rejection Error

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1) in Node.JS

How to connect Node.js to existing Postgres? error: Unhandled promise rejection

Unhandled Rejection (Error): Given action returned undefined React JS

(node:32032) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: Authentication failed

What determines that a promise rejection is unhandled in node.js (console/script)?

(node:8592) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): MongoParseError: Invalid connection string

Unhandled promise rejection error value is not defined in Node.js

Unhandled Rejection - passport login app node js

Unhandled promise rejection in Node server, only on Heroku, works locally

Unhandled rejection Error: Can't set headers after they are sent. Node.js

Knex MySQL Migration "Unhandled rejection Error: Transaction query already complete"

Unhandled Promise Rejection Warning - Node.js

Node Js (Sequelize) - Unhandled rejection SequelizeDatabaseError: Unknown column 'id' in 'field list'

Promises and async await is not working -Unhandled Rejection at: Promise Promise { <rejected> 'noData' } reason: undefined - node.js

`UnhandledPromiseRejectionWarning: Unhandled promise rejection` in my node application

Node Js Migration issue (Unhandled rejection SequelizeDatabaseError Specified key was too long )

Express.js UnhandledPromiseRejectionWarning: Unhandled promise rejection

UnhandledPromiseRejectionWarning: Unhandled promise rejection - Node.js

UnhandledPromiseRejectionWarning: Unhandled promise rejection from Node JS, Preflight response in React

React JS Unhandled Rejection (TypeError): item.persistVariablesLimit.trim is not a function

jest error on node.16: ERR_UNHANDLED_REJECTION

Node-Fetch unhandled promise rejection (can't catch it)

polyfills.js:3056 Unhandled Promise rejection: _xxx is not a function in Angular

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive