Questions tagged [node-mysql2]
131 questions
1
vote
0 answers
Export resolved promise from module using top level await
I'm using mysql2 and trying to create a module I can import through my app to access the connection pool. What I currently have returns a promise that I have to resolve every time I import it, but I'd prefer to resolve the promise before exporting.…

NicholasJohn16
- 2,390
- 2
- 21
- 45
1
vote
1 answer
How to return data from SQL with Node.js (mysql2)
I rewrite my code from Python to Node.js
I need to get some data from SQL and then use it in the code after. So it is easy with python, you just get it, return and you can use it.
The code in Python
def sql_get_new_id(connection):
with…

VR BOX TULA
- 21
- 2
1
vote
1 answer
im trying to insert data to mysql from puppeteer (async) but I getting "connection.query is not a function"
I just want to store the data I collected in the database but I getting "connection.query is not a function"
I've checked a lot of options to solve the issue and I can not find anything that works.
In some of the ways the variables I collected were…
1
vote
0 answers
Warning: got packets out of order. Expected 2 but received 0
I have made as realtime Node.js application.I am using mysql2 database.
Server start with:- pm2 start app
The next day, my server is not responding. And I got this error
Warning: got packets out of order. Expected 2 but received 0
Error: Can't add…

Manish Rai
- 21
- 1
- 5
1
vote
1 answer
MySQL Can not open connection after call connection.end() => Error: Pool is closed
config.js
const mysql = require('mysql2');
const config = {
host: 'localhost',
port: '3306',
user: 'root',
password: 'root',
database: 'krometal',
charset: "utf8mb4_bin",
multipleStatements: true
};
const connection =…

Hussein Mohamed
- 157
- 9
1
vote
2 answers
MYSQL2 PROBLEM: TypeError: Bind parameters must not contain undefined. To pass SQL NULL specify JS null
I've just written a simple http api server using nodejs and express. It wraps the mysql database, and return its data.
However, for each every query I do, my server crashs.
I create the pool connection in a file called "db_manager":
const mysql =…

Luca Brini
- 11
- 1
- 2
1
vote
0 answers
Knex.js + mysql2: Get number of inserted and updated rows
I'm using Knex.js and mysql2. Is there a way to figure out how many rows were inserted and how many were updated in this function?
await this.knex("tableName")
.insert(arrayOfObjects)
.onConflict(["primaryKey1", "primaryKey2"])
.merge()

cwallenwein
- 538
- 7
- 20
1
vote
1 answer
Using mysql2.ping to check if server is up or down
I am trying to include the status of my MySQL server in the Response of my router.
health.js:
var express = require('express');
var router = express.Router();
const db = require('../database');
/* GET home page. */
router.get('/', async…

Fabian
- 541
- 9
- 30
1
vote
1 answer
why do mysql query show ColumnDefinition
I am using mysql2 package. I am doing simple sql query in node. so why does it tur
public async getTests(req: Request, res: Response): Promise {
const pool = await connect();
const stmt = 'SELECT test, test2 FROM…

wil
- 853
- 2
- 10
- 24
1
vote
0 answers
Can't add new command when connection is in closed state (knex.js with mysql2 + mysql8 + node.js 16)
I have an issue after few hours of work with this setup:
knex.js (mysql2)
mysql8
node.js 16 (docker FROM node:16)
"Can't add new command when connection is in closed state"
With this setup:
config: {
client: 'mysql2',
…

Nedudi
- 5,639
- 2
- 42
- 37
1
vote
0 answers
I cannot find what might be the reason for this ? Maybe an open connection ? please resolve
events.js:291
throw er; // Unhandled 'error' event
^
Error: Unexpected packet while no commands in the queue
at Connection.protocolError (/home/param/Desktop/HRMSFIRST-HOv5.0/node_modules/mysql2/lib/connection.js:354:17)
at…

Param Shah
- 11
- 2
1
vote
1 answer
Bind problem in SQL query in Node, Express, Mysql2 app
I have been following a tutorial on setting up REST APIs in Node, using Express for an app that accesses an existing MariaDB database. My version only needs to read data and I have the DB co-located with the Node application (same host).
My goal for…

Greg
- 195
- 1
- 13
1
vote
1 answer
node mysql2 Incorrect arguments statement
this is my function. If I remove the ? and enter the info manually it executes, I would assume this is how you pass in parameters. is this correct? If i console log the params they all work, I am assuming the way the params are been passed…

chewie
- 529
- 4
- 17
1
vote
1 answer
insert a json array in a mysql table
Using mysql2 I am parsing a json response from an endpoint and inserting some of its values in a mysql database.
What I now want to do is to log this response in a table of my database. The json I receive is in a variable called data and I properly…

Lelio Faieta
- 6,457
- 7
- 40
- 74
1
vote
1 answer
Is it possible to see full compiled query with Node mysql / mysql2 libraries?
For example I have a code like this:
conn.query('INSERT INTO events_log SET ?', [record]);
If there is an error, the library just displays an error itself, without the query was made by the library. Is it possible to see it?
P.S. I mean the query…

Eugene
- 905
- 1
- 10
- 22