How to use the mysql.createConnection function in mysql

To help you get started, we’ve selected a few mysql 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 apla / dataflo.ws / task / sphinx.js View on Github external
self.connection.on('error', function (err) {
			if (!err.fatal) {
			  self.failed('Fatal error while connecting to server');
			  return;
			}
			if (err.code !== 'PROTOCOL_CONNECTION_LOST') {
			  throw err;
			}
			if (self.verbose) console.log('Re-connecting lost connection'/* + err.stack*/);
			self.connection = sphinxQLClient.createConnection(sphinxConfig);
		});
github fulup-bzh / GeoGate / server / backends / GeoToBe-backend.js View on Github external
var CreateConnection =function (backend) {

    backend.Debug (4, "MySQL creating connection [%s]", backend.uid);
    backend.base = mysql.createConnection(backend.opts);
    backend.count ++;
      
    // register event for asynchronous server errors
    backend.base.on('error', function(err) {
        backend.Debug (1, "MySQL server error=[%s]", err);
        // Sever was restarted or network connection was lost let restart connection
        if(err.code === 'PROTOCOL_CONNECTION_LOST') {
             backend.Debug (4, "MySQL connection lost [%s/%d] automatic connect retry in 10s]", backend.uid, backend.count);
             setTimeout(function () {CreateConnection (backend);}, MYSQL_RECONNECT_TIMER);  
             
        } else { 
            throw err;  // server variable configures this)
        };
    });
    
    // force an initial connectiion at object construction time
github ukon1990 / wow-auction-helper / server / src / util / item.util.ts View on Github external
return new Promise((resolve, reject) => {
      const db = mysql.createConnection(DATABASE_CREDENTIALS);
      // select * from item_name_locale where en_GB = 'undefined';
      // select id from items where id not in (select id from item_name_locale);
      db.query(`
        select id from items where id not in (select id from item_name_locale);`,
        async (err, rows, fields) => {
          if (!err) {
            const promiseThrottle = new PromiseThrottle({
              requestsPerSecond: 1,
              promiseImplementation: Promise
            });

            const list = [];
            const itemIDs = [];
            rows.forEach(row => {
              itemIDs.push(
                promiseThrottle.add(() => {
github DoSomething / DS-Realtime-Feed / services / data.js View on Github external
/*
 * Data service. Used for performing queries agaisnt
 * DS data.
 */

var mysql = require('mysql');
var connection = mysql.createConnection({
  host: process.env.SQL_HOST,
  user: process.env.SQL_USER,
  password: process.env.SQL_PASSWORD
});

/*
 * Performs the query given and sends the rows back to the callback.
 */
this.performQuery = function(query, callback) {
  connection.query(query, function(err, rows, fields) {
    if(err) {
      console.log(err);
    }
    callback(rows);
  });
}
github thekiur / cryptoexchange / lib / ExpressServer.js View on Github external
function handleDisconnect() {
	db = MySQL.createConnection(db_config);
	db.connect(function(err) {
	  if(err) {
	    console.log('Error when connecting to db:', err);
	    setTimeout(handleDisconnect, 3000);
	  }
	});
	db.on('error', function(err) {
	  console.log('DB error', err);
	  if(err.code === 'PROTOCOL_CONNECTION_LOST') {
	    handleDisconnect();
	  } else {
	    throw err;
	  }
	});
}
github lukemurray / data-atom / lib / data-managers / mysql-manager.js View on Github external
return new Promise((resolve, reject) => {
      let query = `show databases`;

      let connection = mysql.createConnection({
        host: this.dbConfig.server,
        user: this.dbConfig.user,
        password: this.dbConfig.password,
        port: this.dbConfig.port
      });

      if (!connection) {
        console.error(err);
        return reject(err);
      }

      connection.query('SHOW DATABASES', (err, rows) => {
        if (err) {
          console.error(err);
          return reject(err);
        }
github soomtong / blititor / module / reservation / lib / database.js View on Github external
function createScheme(databaseConfiguration, callback, done) {
    const connection = mysql.createConnection({
        host: databaseConfiguration.dbHost,
        port: databaseConfiguration.dbPort || databaseDefault.port,
        database: databaseConfiguration.dbName || databaseDefault.database,
        user: databaseConfiguration.dbUserID,
        password: databaseConfiguration.dbUserPassword
    });

    const charSet = 'utf8mb4';

    const sql_reservation_list = 'CREATE TABLE IF NOT EXISTS ?? ' +
        '(`id` int unsigned not null AUTO_INCREMENT PRIMARY KEY, ' +
        '`category` tinyint default 0, ' +
        '`name` varchar(16) not null, ' +
        '`email` varchar(256), ' +
        '`phone` varchar(16), ' +
        '`info` tinytext, ' +
github ironbane / IronbaneServerLegacy / tasks / builddetailmeshes.js View on Github external
grunt.registerMultiTask('builddetailmeshes', 'Create a full-detail level mesh', function() {
        var task = this,
            taskDone = this.async();

        var options = this.options({
            host: 'localhost',
            port: 3306,
            user: 'root',
            password: 'root',
            assetDir: "./IronbaneAssets/"
        });

        var mysql = require('mysql').createConnection({
            host: options.host,
            port: options.port,
            user: options.user,
            password: options.password,
            multipleStatements: true
        });

        var deferredQuery = function(query) {
            var deferred = Q.defer();

            mysql.query(query, function(err, results) {
                if (err) {
                    deferred.reject('error with query: ' + err);
                    return;
                }
github b00giZm / docker-compose-nodejs-examples / blueprints / mysql / database / index.js View on Github external
const init = ({ host, port, user, password, database } = {
  host: dbHost,
  port: dbPort,
  user: dbUser,
  password: dbPass,
  database: dbName
}) => {
  connection = mysql.createConnection({
    host,
    port,
    user,
    password,
    database
  });
  
  return createTable();
};