Questions tagged [node-mysql2]
131 questions
3
votes
1 answer
Create Knex instance with existing (mysql2) connection
I would like to first create a connection to my database (with mysql2) and then after that create a new Knex instance. I cannot find anything in the documentation about this. Is this even possible?
So, idealy I would like to do something like this…

Terrabythia
- 2,031
- 3
- 19
- 29
3
votes
2 answers
Node with Mysql2 timezone issue
When I am trying to set the timezone with mysql2 getting the bellow message.
With MySQL working fine.
But I have to use mysql2 only
var mysql2 = require('mysql2');
var con = mysql2.createPool({
connectionLimit : 10,
host:…

Sujeet Kumar
- 1,822
- 22
- 25
3
votes
0 answers
Updating MySQL returns rows affected, but doesn't actually update the Database [ nodejs mysql2 ]
I have a function to run mysql2 nodejs with promise and update query
Here is the output:
{
"fieldCount": 0,
"affectedRows": 1,
"insertId": 0,
"info": "Rows matched: 1 Changed: 1 Warnings: 0",
"serverStatus":…

Aminudin
- 109
- 2
- 8
3
votes
1 answer
max_prepared_stmt_count error, how to recycle prepared statements?
I'm getting the below error from mysql:
Can\'t create more than max_prepared_stmt_count statements (current value: 16382)
I've increased the value to the max (1 million) for now.
I am using node-mysql2 but I'm thinking that no matter what my…

Terence Chow
- 10,755
- 24
- 78
- 141
2
votes
0 answers
Node.JS/Express MYSQL2 Promise API- How to properly open a connection
I want to use the MYSQL2 promise API, and am struggling with the proper way to connect to the database.
Hoping for someone to weigh in on the correct way.
Edit for clarity: The issue is that mysql.createConnection() returns a promise, so when…

northendben
- 31
- 3
2
votes
0 answers
TypeError: Cannot read properties of undefined (reading 'constructor') How can I handle this error correctly
please help.
I'm making use of the node mysql2 and telegraf-mysql-session to store sessions and execute queries in my telegram bot.
I have SQL queries and whenever a query is run and some variables are null in that query it triggers this error.…

sb_thedev
- 87
- 11
2
votes
1 answer
How can I update mysql2 query to not return undefined for return?
I am using nodejs and mysql2. I am storing all my queries inside a class. When I console.log the results I am able to view the data correctly, however when I use a return statment to return the data, I am getting undefined. I believe I need to…

dev_in_training
- 333
- 5
- 16
2
votes
1 answer
Array length inconsistently reported
i developed a MS Access desktop database app a decade ago that im attempting to rebuild using node, electron and mysql now that im a recovering windows user.
ive started by recreating the simplest form in the app after importing the necessary parts…

Antioch Technologies
- 57
- 1
- 6
2
votes
0 answers
Node.js mysql2 on AWS Lambda ERR_STREAM_WRITE_AFTER_END
I have encountered a bizarre error using Node.js mysql2 library on AWS Lambda.
I am making a connection to a mysql database on AWS Aurora in my AWS Lambda function.
const conn = mysql.createConnection({
host: '',
port: 3306,
user: '',
…

Alex Rablau
- 355
- 2
- 13
2
votes
3 answers
How to make a function to query MySQL in NodeJS?
I made this:
const mysql = require('mysql2/promise')
const pool = mysql.createPool({
host: 'localhost',
user: 'root',
password: '',
database: 'nodejs',
waitForConnections: true,
connectionLimit: 10,
queueLimit:…

zS1L3NT
- 461
- 5
- 14
2
votes
0 answers
MySQL query super slow when using nodejs/mysql2 but fast using other clients
I have the following query:
SELECT
`Job`.`id`,
`Job`.`serviceId`,
`Job`.`externalId`,
`Job`.`createdAt`,
`Job`.`updatedAt`,
`logs`.`id` AS `logs.id`,
`logs`.`statusId` AS `logs.statusId`,
`logs`.`createdAt` AS…

Philipp Kyeck
- 18,402
- 15
- 86
- 123
2
votes
0 answers
Catching exception from event listener in express route
I am using nodejs, express and node-mysql2 for my application. I want timezone for each connection to use UTC so that my time_created and time_modified (MYSQL: On update CURRENT_TIMESTAMP) column will have timestamp in UTC only. I don't have…

AnSh
- 147
- 1
- 6
2
votes
2 answers
The correct way to invoke an async function main?
I have some nodejs scripts - i.e. processes which do a job and complete, rather than run continuously.
I use async functions, for example:
const mysql = require('mysql2/promise');
...
async function main() {
var conn = await…

fadedbee
- 42,671
- 44
- 178
- 308
2
votes
1 answer
async await mysql2/promise and ending connection
Trying to developing REST API in Node.Js by using MySQL Database. Could you please help me to write some better code?
Two most important questions here,
1 - How we can take the createConnection logic out of userModel.js?
2 - Shall I end the…

Yun
- 25
- 1
- 4
1
vote
2 answers
TypeError: Cannot read properties of undefined (reading 'constructor')
please help.
I'm making use of the node-mysql2 library
I have SQL queries and whenever a query is run and some variables are null in that query it triggers this error. This is usually when the session variables are null. AgentID=Null or…

sb_thedev
- 87
- 11