Questions tagged [node-mysql]

A pure node.js JavaScript Client implementing the MySql protocol. This is about the node package `mysql`, not `node-mysql` which is much less popular.

node-mysql
Filter by
Sorted by
Tagged with
1 vote
2 answers
656 views

NodeJS and MySQL Promise: Why am I getting ReferenceError: DataBase is not defined?

I'm just learning to use promises for MySQL in NodeJS. I'm using the following code to wrap my MySQL queries in Promises. const mysql = require( 'mysql' ); let config = { host : 'localhost', ...
Meggy's user avatar
  • 1,591
0 votes
0 answers
547 views

Where to place the Commit block of a complex NodeJS MySQL Transaction?

I have the following code in NodeJS which works well to; Begin a MySQL transaction; Create an audiopost; Update an audiopost. Check to see if tag1 exists and if not, create it and insert into a tag ...
Meggy's user avatar
  • 1,591
0 votes
1 answer
367 views

Why do I get ReferenceError: insertId is not defined on my 4th MySQL Query in NodeJS?

Why am I able to get the insertId from the first MySQL query but not further on in the code on the fourth query? The query is somewhat complex, but I don't know why something which works the first ...
Meggy's user avatar
  • 1,591
2 votes
2 answers
5k views

Typeorm eager loading not working on one to one relationship

Can we eagerly load a one-to-one related entity in typeORM? I am using TypeOrm in nestjs. The two One-to_One related entities are driver and job: in Driver Entity: @OneToOne(() => JobEntity, job =...
Hussain Wali's user avatar
1 vote
1 answer
2k views

How do I insert a JS Object into a mysql row (in nodeJS)?

Right now I use this cumbersome approach when I want to add a row whose data is in a JS Object Adding a row to a table: const mysql = require('mysql') var db = mysql.createConnection(DBInfo) var ...
João Pimentel Ferreira's user avatar
0 votes
1 answer
211 views

nodejs mysql not using full config

First of all, I can't find any answers here and Google. I may search the wrong direction and appreciate any help. Node: 10.24.1/12.22.1/14.17.0/16.3.0 (These are the versions I tried) Mysql for node: ...
noob's user avatar
  • 480
1 vote
0 answers
1k views

Node application crashes due to mysql error 'PROTOCOL_PACKETS_OUT_OF_ORDER'

I am running a node.js application (web service using express) on RHEL v8, using node v16.1.0. I recently upgraded the version of mysql used to MySQL Community Server v8.0.24, and ever since have ...
nick_j_white's user avatar
0 votes
3 answers
45 views

Not able to figure out sql query

i am new to sql and need help with a query. I have two tables user and user_family which contains data like USER ID Date-Of-birth User_Id 1 2021-05-21 28371 2 2021-04-17 28372 USER_FAMILY ID ...
Rahul Gupta's user avatar
0 votes
0 answers
392 views

PROTOCOL_CONNECTION_LOST Node-MySQL

I have made a simple node express server using my-sql. The server runs for few minutes but then crashes with the following message. I have tried to handle the error, but the app just throws the erro ...
anubhavvs's user avatar
0 votes
1 answer
142 views

await and async don't work in the recursive function

I'm trying to connect the code to MySQL. When the connection fails in first attempt, I want it to reattempt to connect. So, This code is used recursive function. This code contains DB connect process. ...
makigon's user avatar
0 votes
1 answer
353 views

Proper way to execute sequence of mysql queries with javascipt mysql client

Simply put : I have a table 'a', a table 'b' and a many to many table 'a_b'. I need to insert a row in table 'b', and then if it was inserted properly, use the id of this one to insert it into 'a_b' ...
UmbrellaCorpAgent's user avatar
0 votes
1 answer
499 views

Subquery in node.js sometimes works and sometimes not

i have created a node.js query where it works fine sometimes , it is an insert of a club and then insert the players in a second query , there is a subquery that takes the last inserted id of the Auto ...
Fares Ben Slama's user avatar
0 votes
1 answer
190 views

Express async route logging undefined after await

I am writing an Express endpoint in Typescript to update a user's password in the database, but having some trouble with multiple queries/synchronous code. My problem is right now I am trying to await ...
jhf2's user avatar
  • 135
0 votes
1 answer
79 views

Is it possible to make unified insert function

So I have this piece of code, but I can't know how many arguments the function will take before I actually use it function insert(...args) { return new Promise((resolve, reject) => { // ...
soda's user avatar
  • 3
1 vote
1 answer
565 views

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. ...
Eugene's user avatar
  • 1,024
-1 votes
1 answer
346 views

Using MySQL functions with Node mysql2 library

This is my current request to insert data: let record = { ip : '127.0.0.1', ... }; conn.query('INSERT INTO events_log SET ?', [record]); Is it possible to apply INET6_ATON function to the IP ...
Eugene's user avatar
  • 1,024
-1 votes
1 answer
221 views

I am learning MYSQL and what am i doing wrong in this code

I have tried to execute the code below and I get an error message var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "root", ...
JoshNomso's user avatar
0 votes
1 answer
583 views

Is there a workaround for pinging a database every few minutes?

So, I have a NodeJS MySql system, which pings the database every 10 Minutes (might set that to one Minute) to not lose the connection, but that is not the code quality I like to write. So, now I am ...
GamingKlex's user avatar
1 vote
2 answers
4k views

TypeORM throws an error after insert with the queryBuilder in Nest.js

I have an entity and service defined as follows. user.entity.js @Entity({ name: 'users' }) export class User { @Column({ type: 'binary', length: 16, select: false, primary: true, ...
Mnengwa's user avatar
  • 277
0 votes
1 answer
951 views

NodeJS (Express) with MySQL - How to handle connection resets?

I'm running my website with NodeJS, I'm using the Express framework. Since MySQL is the only database type at my hosting, I went with it. I created a db.js file: const mysql = require('mysql'); const ...
South3492's user avatar
  • 101
0 votes
0 answers
238 views

Safety of database connection pools - releasing a connection back to the pool with bad settings

How safe is connection pooling with regard to connection settings? When a connection is released back to the pool, does the pool issue some sort of reset command to restore the connection to a known ...
SystemParadox's user avatar
0 votes
1 answer
2k views

better solution for sequelize decrement

I'm new to sequelize & trying to do decrement. I've two models products & order, in product there is productStock column & in order there is quantity column. What I'm trying to do is when ...
Muhammad Haekal's user avatar
2 votes
0 answers
325 views

How can I get all inserted ids in mysql using node module in node.js?

I have table users id name 1 One 2 two I want to insert multiple data in this table with const query = `INSERT INTO users (`name`) VALUES("three"), ("four")`; now I used this ...
Dhaval's user avatar
  • 938
0 votes
0 answers
75 views

Node.js get mysql data and append to object [duplicate]

I am trying to get data from a MySQL database using node.js. Then I want to append that data to an object so I can later use it to make an HTML table. This is my module code: var mysql = require("...
user avatar
0 votes
1 answer
157 views

Cannot log into any account on mysql from terminal

Ever since running as suggested: https://stackoverflow.com/a/50131831/3310334 alter user 'root'@'localhost' identified with mysql_native_password by 'Gzbz1H!fZ@#LyF33IqP$rAS8H#0iNc4lK8l2Md@...
minseong's user avatar
  • 11.6k
0 votes
0 answers
38 views

How to fetch data from db using mysql-crud NodeJS module

I have been developing in node for quite sometime and began to get frustrated with writing just abou the same queries for different projects. I came of a CodeIgnitor/Laravel Background where ORM rules ...
CliffTheCoder's user avatar
0 votes
1 answer
943 views

How to avoid too many connections error in mode mysql2

pool.js import mysql from 'mysql2' import { dbusername, dbpassword, dbname, host } from './config' const pool = mysql.createPool({ host: host, user: dbusername, password: dbpassword, ...
angry kiwi's user avatar
  • 11.1k
0 votes
1 answer
67 views

Cannot use bindNodeCallback with node-mysql connection.query

I'm trying to use bindNodeCallback to convert connection.query into a function that returns observable. const mysql = require('mysql2'); const { bindNodeCallback } = require("rxjs"); const ...
Marinos An's user avatar
  • 10.2k
1 vote
1 answer
275 views

correctly handle async/await on a mysql query

I am trying to perform a mysql query asyncronously assigning a value to a const to be later used in my code. What I have so far is: const plan_free = await con1.promise().query("SELECT ...
Lelio Faieta's user avatar
  • 6,537
1 vote
0 answers
299 views

Node/MySQL (mysql2) Connection Pools

I have a high-level question about how connection pools work in a Node application using node/mysql2. Let's say there are two simultaneous https calls making API requests. The API (Express/Node app) ...
Marc's user avatar
  • 1,590
0 votes
1 answer
213 views

Runing nested mysql queries in node.js

I'm trying to construct an array of objects and render them using ejs. The objects array is coming from the database from a table called products. I was able to run a query and get the products data ...
Ram Alsaifi's user avatar
0 votes
2 answers
111 views

multiple string replace function not working in nodejs

Here I need to replace #tenant_id# in multiple files the input is coming from an json object as 1. This is the first file to replace #tenant_id#: INSERT INTO mst_designation (designation_name,...
Rahman Haroon's user avatar
0 votes
1 answer
439 views

How to insert into mysql, then return JSON back to websocket client, using AWS Lambda node function

I have an AWS WebSocket API using $connect, which calls a Lambda function to insert a connectionId string into a database. If using DynamoDB, I would use a process like this: const AWS = require('aws-...
Darren Gates's user avatar
1 vote
1 answer
6k views

knex.js: combination of orWhere followed by multiple where

I am writing a query with knex.js and i got stuck with orWhere. I need a query like this: select count(*) from `Project` where `Project`.`createdAt` >= '2019-11-12' and `...
Javohir Mirzo Fazliddinov's user avatar
0 votes
1 answer
284 views

db connection error node-mysql docker container

I've 2 container one of webapp(node) second of db(mysql) are in same docker network. But when running both container via docker compose, my app is not able to connect to database. Getting below error, ...
Shubham Arya's user avatar
0 votes
1 answer
514 views

retrieve value from a select query

I am trying to retrieve a value from a mysql table to use it in another query but I keep getting an error because on the second query the value is not passed. var id_customer=''; con1.query("...
Lelio Faieta's user avatar
  • 6,537
0 votes
0 answers
24 views

trigger code execution based on query results on node server

In a node server I run a query that can produce three different results: return a row of data with status='A' return a row of data with status='B' return no rows based on what the query returns, I ...
Lelio Faieta's user avatar
  • 6,537
0 votes
1 answer
1k views

How to insert multiple rows from JSON structure to MySQL column

I need to insert multiple json value into a mysql column. Here I have a table named client query = ' INSERT INTO client (user_id,client_id,tenant_id) values ?' let queryClient = [] queryClient.push(...
Rahman Haroon's user avatar
0 votes
1 answer
221 views

How to handle database delay on node-mysql when calling method from another js script

I'm doing a sample API using routes and controllers (with mysql as backend) for courses but one of my methods doesn't work as expected but I'm not sure why... this is my code so far. This is routes/...
mgXD-2's user avatar
  • 102
0 votes
1 answer
1k views

multiple connection to the mysql database from a node server, how to fix

var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "***", password: "***", database: "***" }); case ...
Lelio Faieta's user avatar
  • 6,537
0 votes
1 answer
59 views

MYSQL - How to correct SUBSELECT?

How to correct do an subselect Query in Node.js mysql? Example: TABLE1 |ID: (AI) |title: | content: | image_id | |1 | some | something| 1 | TABLE 2 |ID: (AI) |title: | src: | |1 ...
Patrick's user avatar
  • 81
0 votes
0 answers
74 views

Would multiple connection.query()-s slow the connection in node.js/mysql?

I have this website that uses the same queries over and over. I thought of creating small functions, passing the connection and other arguments to it, and reusing the functions. For example, here's a ...
Cedric Hadjian's user avatar
0 votes
0 answers
325 views

Error: socket hang up in Nodejs while inserting bulk records in mysql

enter image description hereGetting error Error: socket hang up while executing my script about migrate data from mongo to MySQL via NodeJs. Although, I'm inserting 1000 of records in chunks. Somehow ...
Mitesh Vasava's user avatar
0 votes
1 answer
147 views

Having trouble with MySQL and fs.writeFile (Node JS)

I'm having some trouble with Node JS MySQL and fs. What I'm trying to do, is extracting data from my database to a local txt file. For each ID in the database, I want it to go a line down like \n My ...
Gustav Singh's user avatar
0 votes
1 answer
519 views

DB Error: connection lost: server Closed the connection

I'm facing this error when the there are no requests to mysql it goes to idles state and we face this db error. I'm working with node, mysql deployed onto openshift cluster. How do I keep the db ...
Tested's user avatar
  • 769
2 votes
0 answers
46 views

MySql query optimised in console, but not optimised in Node/Python clients

I have a rather complex query, using many joins and a not in clause. I've tailored this query using the MySql console to be optimised, and I'm sure there is no DEPENDEND SUBQUERY in the execution plan....
gahag's user avatar
  • 93
1 vote
1 answer
237 views

Escaping query values in MySQL Query (node-mysql)

I am trying to use node-mysql Escaping query values but when I try and insert it into my MySQL query I am getting errors and can't seem to find the problem. I have tried laying out the code in ...
user13862056's user avatar
0 votes
0 answers
171 views

Any MySQL Node Package: `USE index` with SELECT Statement

I am using a node module sql and finding support of running SQL with given Index: SELECT * FROM table1 **USE INDEX (col_index)** WHERE col1=1 AND col2=2 AND col3=3; But I am not able to find this ...
Aman Kaushal's user avatar
1 vote
1 answer
2k views

How to pass multiple MySQL Queries in AWS Lambda Function at once

I have a multiple MySQL queries created in Workbench. This query runs by one trigger only in Workbench. I would like this query to be embedded to my AWS Lambda Function but to no avail. I suspect that ...
RickyBelmont's user avatar
0 votes
0 answers
148 views

Why is there a delay in my electron app's mysql connection queries?

Whenever I load the electron app, it performs the queries right away on some occasions, but on other times it has a delay. The whole html page, on the other hand, loads without delay. I tested it out ...
mat00's user avatar
  • 13

1
2
3 4 5
14