NestJS – [TypeOrmModule] Unable to connect to the database. Retrying ER_PARSE_ERROR

nestjstypeorm

Cannot able to connect database with correct connection info, followed documentation to connect database from https://docs.nestjs.com/techniques/database

Database connected on SQLYog

enter image description here

Following same database information in app.module.ts

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: null,
      database: 'the_local_db',
      entities: [
        Table_one,
      ],
      // entities: ['../typeorm/entities/*.ts'],

      synchronize: true,
    }),
    StaffModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Error Details

`[Nest] 5528 – 06/30/2020, 1:39:51 AM [ExceptionHandler] ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''"'' at line 1 +18m
QueryFailedError: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''"'' at line 1

at new QueryFailedError (C:\Users\UserName\ProjectName\nrwl\src\error\QueryFailedError.ts:9:9)
at Query. (C:\Users\UserName\ProjectName\nrwl\src\driver\mysql\MysqlQueryRunner.ts:167:37)
at Query. (C:\Users\UserName\ProjectName\nrwl\node_modules\mysql\lib\Connection.js:526:10)
at Query._callback (C:\Users\UserName\ProjectName\nrwl\node_modules\mysql\lib\Connection.js:488:16)
at Query.Sequence.end (C:\Users\UserName\ProjectName\nrwl\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24)
at Query.ErrorPacket (C:\Users\UserName\ProjectName\nrwl\node_modules\mysql\lib\protocol\sequences\Query.js:92:8)
at Protocol._parsePacket (C:\Users\UserName\ProjectName\nrwl\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (C:\Users\UserName\ProjectName\nrwl\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (C:\Users\UserName\ProjectName\nrwl\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (C:\Users\UserName\ProjectName\nrwl\node_modules\mysql\lib\protocol\Protocol.js:38:16)`

Best Answer

I have just removed the port:3306, now it's working.

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      username: 'root',
      password: null,
      database: 'the_local_db',
      entities: [
        Table_one,
      ],
      // entities: ['../typeorm/entities/*.ts'],

      synchronize: true,
    }),
    StaffModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
Related Topic