'NestJS - [TypeOrmModule] Unable to connect to the database. Retrying ER_PARSE_ERROR
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
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)`
Solution 1:[1]
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 {}
Solution 2:[2]
I was faced with a similar issue and the verified response did not help me. I was able to solve my issue using the mysql2
module instead of mysql
.
$ npm install mysql2 --save
I also had to uninstall mysql
module to connect to my database
$ npm uninstall mysql --save
Hope this response helped others with stuck in the same issue.
Solution 3:[3]
Check if you have synchronize connection option set to true in database configuration. Make it to false. It worked for me.
Solution 4:[4]
First, i solved my problem by using as following: 1/ synchronize :false in the app.module 2/nmp uninstall mysql 3/npm install mysql2 --> when i run >>npm run start:dev everything is ok
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Stackoverfall |
Solution 2 | Ayaan Siddiqui |
Solution 3 | Vaddadi Pranathi |
Solution 4 | Sa_IS |