node-mysql

Trouble Connecting to MySQL via SSH

无人久伴 提交于 2020-01-13 13:08:44
问题 I am running a node Express website on my OS X machine locally. I need to ssh to a remote mysql database so I can start writing queries against it. Now I'm able to ssh to our remote server (running the mysql database) in the cloud when I do it via my OS X Yosemite terminal. But I haven't been successful trying to do it in code using the node-mysql and tunnel-ssh node middleware. My code runs but doesn't really error out except for my GET when debugging my express app in Webstorm. Some facts :

How to use one Mysql pool connection in many files in a NodeJS Express App

梦想与她 提交于 2020-01-06 06:25:33
问题 I've been scratching my head at this. I wanted to know if there was an efficient way of creating one Mysql connection and sharing it between different modules in an application served by Express. So far I have the following code at the top in all my JS files that require a database connection of sorts: const db = require('mysql2') pool = db.createPool(<config details>) // Below pool.execute(.. ) // etc I feel like this is an overkill. Is there a way to create one connection, say in express

Aborted connections when using node.js/mysql connectionPool

扶醉桌前 提交于 2020-01-05 09:03:33
问题 var mysql = require('mysql'); var mysqlPool = mysql.createPool({ host : 'localhost', user : 'nodejs', password: '', database: 'nodejs' }); // somewhere inside a method: mysqlPool.getConnection(function(err, connection) { // do some queries connection.release(); }); I don't see any warnings in the output, but on the MySQL server I see aborted connections since testing with this node.js code. Do I have to close the connection pool when I stop the node.js app? If yes, how? 回答1: If you're closing

Updating multiple rows with node-mysql, NodeJS and Q

大憨熊 提交于 2019-12-30 04:47:07
问题 I am using node-mysql, node-js, and Q promises. I have successfully updated, deleted, and inserted single rows using the above. As well as inserted multiple rows in a single statement in my test case scenario. However, I need to update multiple rows with different values (batch mode) either in a single query or in a for loop. The information on how to use prepared statements in mysql2 (supposed to improve on node-mysql) is very sparse and there are no examples, although that should be the

Node.js mysql transaction

元气小坏坏 提交于 2019-12-30 00:44:07
问题 Can anyone provide an example of how I could achieve MySQL transactions in Node.js. I am trying to get my head around using the node-mysql driver and node-mysql-queue. As far are I can tell, using node-mysql-queue greatly reduces the asynchronous nature of Node.js as new queries have to wait until existing ones have completed. To get around this, has anyone attempted to combine node-mysql-queue with node-mysql's connection-pooling capabilities. i.e starting a new mysql connection for each new

Connecting to MariaDB with nodejs over ssl with clear text password

好久不见. 提交于 2019-12-24 03:27:59
问题 I am trying to connect to mariadb instance over ssl, var mysql = require('mysql'); var conn = mysql.createConnection({ user: 'user', password: 'password', debug: true, port: '3306', host: "host", ssl: { "ca": ca } }); conn.connect(); the ca is an array of cerificates. I am getting the following error. Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MariaDB client I am able to connect to the db using python with mysql

Node-mysql insert query with two values?

限于喜欢 提交于 2019-12-23 17:59:00
问题 This is my current javascript. var connection = mysql.createConnection({ host: 'localhost', user: 'root', password: 'root', database: 'codify', port: '8889' }) connection.connect(); //var querydata = +"'"+data.RegUsername + "','"+data.RegPassword+"'" connection.query("INSERT INTO Codify (UsernameDB , PasswordDB) VALUES ?", data.RegUsername,+","+ data.Regpassword , function(err,rows,fields){ if (err) throw err; }) });*/ This query causes an error, what am I doing wrong? 回答1: What you're doing

How to store time greater than 24 Hours in Mysql?

怎甘沉沦 提交于 2019-12-23 04:00:46
问题 I need to create a column (say idletime ) that will store time value having hours smaller or bigger than 24. When i try to insert such values bigger than 24 (For example '80:00:00', '129:23:12', etc) , am getting the following error code: java.sql.SQLException: Illegal hour value '80' for java.sql.Time type in value '80:00:00. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) ..... I have searched over the Internet and found that the TIME datatype ranges from 00:00:00 to 23:59

Push partial result data in array and send

家住魔仙堡 提交于 2019-12-23 02:34:48
问题 I have a MySQL table in which a column name is tags and type is VARCHAR . I'm inserting the data with comma separated: tag1, tag2, tag3, tag4, tag5, tag6 My query from node is: app.get('/tagtest', (req, res) => { var tags = []; // <= Not sure if I need this or how to push tags here. connection.query("SELECT * FROM tagtestpost", (err, rows)=>{ res.send(rows) }); }); Response from above query is: [{"id":1,"tags":"tag1, tag2, tag3"},{"id":2,"tags":"tag2, tag4"}] I want to return the tags in an

Combining node-mysql result rows into single JSON return for node.js

风流意气都作罢 提交于 2019-12-21 21:37:16
问题 I want to know the best way to return a bunch of JSON that is the result of some dependent mysql queries. app.get('/viewing/:id', function (req, res){ if(!req.cookies.user) { res.end('Requires Authenticated User'); } else { connection.query('SELECT blah blah where userId='+req.params.id, function (error, rows, fields) { Now we have a bunch of rows -- lets say 5. I need to go through each one and make another mysql query based on the data I just got. So I end up needing to repeat call (do I