How to use the mysql2.createServer function in mysql2

To help you get started, we’ve selected a few mysql2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sidorares / node-mysql2 / examples / server.js View on Github external
const doubleSha = auth.doubleSha1('pass123');
  const isValid = auth.verifyToken(
    params.authPluginData1,
    params.authPluginData2,
    params.authToken,
    doubleSha
  );
  if (isValid) {
    cb(null);
  } else {
    // for list of codes lib/constants/errors.js
    cb(null, { message: 'wrong password dude', code: 1045 });
  }
}

const server = mysql.createServer();
server.listen(3333);
server.on('connection', conn => {
  // we can deny connection here:
  // conn.writeError({ message: 'secret', code: 123 });
  // conn.close();
  conn.serverHandshake({
    protocolVersion: 10,
    serverVersion: '5.6.10', // 'node.js rocks',
    connectionId: 1234,
    statusFlags: 2,
    characterSet: 8,
    // capabilityFlags: 0xffffff,
    // capabilityFlags: -2113931265,
    capabilityFlags: 2181036031,
    authCallback: authenticate
  });
github sidorares / node-mysql2 / examples / mysqlproxy.js View on Github external
'use strict';

const mysql = require('mysql2');
const ClientFlags = require('mysql2/lib/constants/client.js');

const server = mysql.createServer();
server.listen(3307);

server.on('connection', conn => {
  console.log('connection');

  conn.serverHandshake({
    protocolVersion: 10,
    serverVersion: 'node.js rocks',
    connectionId: 1234,
    statusFlags: 2,
    characterSet: 8,
    capabilityFlags: 0xffffff ^ ClientFlags.COMPRESS
  });

  conn.on('field_list', (table, fields) => {
    console.log('field list:', table, fields);
github sidorares / mysql-osquery-proxy / proxy.js View on Github external
columns.forEach(function(c) {
    result.push(obj[c.name]);
  });
  return result;
}

function osqueryClient() {
  var thrift = require('thrift');
  var ExtensionManager = require('./gen-nodejs/ExtensionManager.js');
  var conn = thrift.createConnection(0, '/var/osquery/osquery.em');
  var client = thrift.createClient(ExtensionManager, conn);
  return client;
}

var id = 0;
var server = mysql.createServer();
server.on('connection', function(conn) {
  conn.serverHandshake({
    protocolVersion: 10,
    serverVersion: 'osquery mysql interface',
    connectionId: id++,
    statusFlags: 2,
    characterSet: 8,
    capabilityFlags: 0xffffff
  });
  var client = osqueryClient();
  conn.on('query', function(sql) {
    client.query(sql, function(err, result) {
      //console.log(result);
      if (result.status.code !== 0)
        return conn.writeError({ code: 1064, message: result.status.message});
github sidorares / mysqlite.js / proxy.js View on Github external
function respondWith(conn, result) {
        if (result.length === 0)
          return conn.writeEof();
        conn.writeColumns(columnsFor(result[0]));
        result.forEach(function(row) {
          var arrayRow = [];
          for(var name in row) {
            arrayRow.push(row[name]);
          }
          conn.writeTextRow(arrayRow);
        });
        conn.writeEof();
}

var id = 0;
var server = mysql.createServer();
server.on('connection', function(conn) {
  sqlite.open(dbPath, {}, function(err, db) {
    conn.serverHandshake({
      protocolVersion: 10,
      serverVersion: 'node.js rocks',
      connectionId: id++,
      statusFlags: 2,
      characterSet: 8,
      capabilityFlags: 0xffffff - 32
    });
    conn.on('query', function(sql) {
      console.log(sql);
      var staticResult = fixtures[sql.toLowerCase()];
      if (staticResult) {
        return respondWith(conn, staticResult);
      }
github implydata / plyql / src / mysql-gateway.ts View on Github external
export function createMySQLGateway(port: number, queryProcessor: MySQLQueryProcessor) {
  var server = mysql.createServer();
  server.listen(port);
  console.log(`MySQL Gateway listening on port: ${port}`);

  var connectionId = 0;
  server.on('connection', function(conn) {
    connectionId++;
    console.log(`New connection ${connectionId}`);

    conn.serverHandshake({
      protocolVersion: 10,
      serverVersion: '5.7.11',
      connectionId,
      statusFlags: 2,
      characterSet: CHARSETS['UTF8MB4_UNICODE_CI'],
      capabilityFlags
    });
github eugeneware / sql-engine / lib / sql-driver.js View on Github external
function createServer(db, port, host, backlog, cb) {

  var server = mysql.createServer();
  server.listen(port, undefined, undefined, cb);
  server.on('connection', function(conn) {
    conn.serverHandshake({
      protocolVersion: 10,
      serverVersion: 'node.js rocks',
      connectionId: 1234,
      statusFlags: 2,
      characterSet: 8,
      capabilityFlags: 0xffffff
    });

    conn.on('query', function(sql) {
      var jsq = sqlTransform(sql);
      if (jsq.select.length && jsq.tables.length) {
        console.log(util.inspect(jsq, { depth: null }));
      }
github skale-me / skale / bin / mysql-server.js View on Github external
#!/usr/local/bin/node --harmony

'use strict';

var mysql = require('mysql2');
var server = mysql.createServer();

server.listen(3307);
server.on('connection', function(conn) {
    console.log('New client connected to mysql server');

    conn.serverHandshake({
        protocolVersion: 10,
        serverVersion: 'node.js rocks',
        connectionId: 1234,
        statusFlags: 2,
        characterSet: 8,
        capabilityFlags: 0xffffff
    });

    conn.on('field_list', function(table, fields) {
        console.log('field list:', table, fields);
github gajus / seeql / src / index.js View on Github external
interactive: true,
    keys: true,
    label: null,
    selectedBg: 'blue',
    selectedFg: 'white',
    width: '80%'
  });

  table.focus();

  screen.append(table);

  screen.render();
}

const server = mysql.createServer();

const drawTable = (drawQueries) => {
  table.setData({
    data: drawQueries.map((query) => {
      return [
        query.connectionId,
        query.queryId,
        formatSql(query.sql).slice(0, 50),
        query.rows.length,
        prettyHrtime(query.executionTime)
      ];
    }),
    headers: [
      'Connection ID',
      'Query ID',
      'SQL',