asd
danielroman11
HOBBYOP

2 years ago

I'm getting an error when I try to connect my backend app to MySQL db in railway. The funny thing is that I have access to the database when I used another method to get access, something like MYSQL_WORKBENCH or extions on VS Code let me get in and modify the database. It only fails in my NestJs App when it tries to connect to MySQL.

This is the error:

nestjs-api | [Nest] 77 - 03/14/2024, 5:33:38 AM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)…
nestjs-api | Error: ERNOTSUPPORTEDAUTHMODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
nestjs-api | at Handshake.Sequence.packetToError (/usr/src/app/nodemodules/.pnpm/mysql@2.18.1/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
nestjs-api | at Handshake.ErrorPacket …

As you can see I'm using a NestJs app with Docker. I have a Docker MySql database running on my PC that haves literally the same configuration of railway's MySQL template and its run perfectly fine.

Obviously I am sure that my environment variables are the same as the ones in railway and I am sure that my app can access to the env variables.

I know my app tries to connect to the database, because in each try that nestjs do when im trying to run the app, on the logs always appears the message: "mysqldefaultauth is deprecated use caching instead" or something like that.

This is my database.module.ts:
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'mysql',
host: 'process.env.DBHOST', port: Number(process.env.DBPORT) || 3007,
username: process.env.DBUSER, password: process.env.DBPASS,
database: process.env.DBNAME, entities: [Event, Attendee, Profile, User], synchronize: process.env.NODEENV !== undefined,
dropSchema: Boolean(process.env.NODE_ENV === 'e2e' && false),
}),
],
})

And this is my docker compose file:
version: "3.8"

services:
mysqldb: image: mysql containername: "eventosdb"
command: --default-authentication-plugin=mysqlnativepassword
restart: always
ports:
- '3307:3307'
environment:
MYSQLROOTPASSWORD: password
MYSQLDATABASE: example MYSQLUSER: user
MYSQLPASSWORD: secret MYSQLTCP_PORT: 3307

nestjsapi: image: nestjs-docker containername: nestjs-api
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "3000:3000"
environment:
- PORT=3000
- JWTSECRET=ThisIsMySecret - NODEENV=dev
# - DBHOST=mysqldb --> This is for testing the connection on dev env
# - DBPORT=3307 # - DBUSER=example
# - DBPASS=secret # - DBNAME=name

volumes:
  - ./src:/usr/src/app/src
depends_on:
  - mysql_db

This is not the Dockerfile for prod this is only an example just trying to connect my app to MySQL database in railway

4 Replies

2 years ago

ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

danielroman11
HOBBYOP

2 years ago

This is my Custom Start Command:

"docker-entrypoint.sh mysqld --innodb-use-native-aio=0 --disable-log-bin --performanceschema=0 --default-authentication-plugin=cachingsha2_password"


2 years ago

This is an issue with the SQL client you're using. Try googling for "ERNOTSUPPORTEDAUTHMODE typeorm"


2 years ago

furthermore, the default authentication method in use by the version of mysql that railway deploys is alreadycaching_sha2_password


Loading...