Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function mysql2Query(sql) {
// recreate connection on fatal error
if (mysql2Con._fatalError) {
console.log('========== Reconnecting mysql2');
mysql2Con = mysql2.createConnection({
host: 'localhost',
user: 'root',
password: 'mysqlrootpassword',
port: 23306,
connectTimeout: 500,
debug: true,
});
mysql2Con.on('error', (err) => {
console.log('- STATS Mysql2 connection died:', err);
});
}
console.log('================ MYSQL2 Running query ======');
const res = await stdMysqlQuery(mysql2Con, sql);
console.log('====================== done ================');
return res;
}
'use strict';
const fs = require('fs');
const mysql = require('mysql2');
const conn = mysql.createConnection({
user: 'root',
password: '',
database: 'test',
host: '127.0.0.1',
port: '3306',
ssl: {
// key: fs.readFileSync('./certs/client-key.pem'),
// cert: fs.readFileSync('./certs/client-cert.pem')
ca: fs.readFileSync('./certs/ca-cert.pem')
}
});
conn.query('select 1+1 as test', function(err, res) {
console.log(res);
conn.query('select repeat("a", 100) as test', function(err, res) {
console.log(res);
before(function() {
connection = mysql.createConnection({
host: config.db.host,
user: config.db.username,
password: config.db.password,
database: config.db.database,
multipleStatements: true
});
connection.connect();
});
function initBenchmark(results, callback, cfg) {
var start_hrtime;
start_hrtime = process.hrtime();
conn = mysql.createConnection({
host: cfg.host,
port: cfg.port,
user: cfg.user,
password: cfg.password,
database: cfg.database,
typeCast: benchmark.typeCast
});
conn.query("DROP TABLE IF EXISTS " + cfg.test_table)
.on('error', function(err) {
console.error(err);
process.exit();
});
conn.query(cfg.create_table_query)
.on('error', function(err) {
console.error(err);
process.exit();
var dsn = DSN.parse(process.argv[2]);
if (!dsn) {
console.error('Could not parse your DSN');
process.exit(1);
}
var filename = process.argv[3];
var start = process.argv[4] ? process.argv[4] : 0;
var dialect;
var connection;
switch (dsn.protocol) {
case 'mysql':
dialect = require('../mysql.js');
connection = require('mysql2').createConnection(dsn);
break;
default:
console.error('Unsupported SQL engine: '+dsn.protocol);
process.exit(1);
}
var output = new dialect.Lex();
output.pipe(new dialect.Colorize)
.pipe(process.stdout);
var todo = Promisable.fulfill();
var chunknum = 0;
fs.createReadStream(filename)
.pipe(new dialect.Lex())
.pipe(new dialect.BufferTokensByCommand())
'use strict';
const mysql = require('mysql2').createConnection({
host: 'localhost',
user: 'root',
database: 'test',
passwordSha1: Buffer.from('8bb6118f8fd6935ad0876a3be34a717d32708ffd', 'hex')
});
mysql.execute(
'select ?+1 as qqq, ? as rrr, ? as yyy',
[1, null, 3],
(err, rows, fields) => {
console.log(err, rows, fields);
}
);
static mysql2Connection(config) {
const { default: Mysql2Adapter } = require('./adapters/Mysql2Adapter');
const mysql = require('mysql2');
const connection = mysql.createConnection(config);
return new Mysql2Adapter(connection, this.logger, null, config);
}
create: async () => {
const conn = mysql.createConnection(this.config);
const connect = promisify(conn.connect.bind(conn));
if (conn.on) {
conn.on('error', () => {
conn.destroy();
});
}
conn.execute = promisify(conn.query.bind(conn));
await connect();
return conn;
},
destroy: (connection) => promisify(connection.end.bind(connection))(),
#!/usr/local/bin/node --harmony
'use strict';
var mysql = require('mysql2');
var connection = mysql.createConnection({
host: '127.0.0.1',
port: 3307,
user: 'cedric',
database: 'test',
debug: true
});
connection.query('SHOW DATABASES', function(err, rows) {
connection.end();
});