================ Creating a link pool =====================
var mysql = require (' mysql ');
var pool = Mysql.createpool ({
Connectionlimit:10,
Host: ' Example.org ',
User: ' Bob ',
Password: ' Secret ',
Database: ' my_db '
});
Pool.query (' SELECT 1 + 1 as solution ', function (Error, results, fields) {
if (error) throw error;
Console.log (' The solution is: ', rows[0].solution);
});
Pool.end (function (err) {
All connections in the pool has ended
});
================= Create a single link ======================
var mysql = require (' mysql ');
var connection = Mysql.createconnection ({
Host: ' localhost ',
User: ' Me ',
Password: ' Secret ',
Database: ' my_db '
});
Connection.connect (); This line of code does not write, and you can implicitly establish a connection by invoking the query:
Connection.query (' SELECT 1 + 1 as solution ', function (Error, results, fields) {
if (error) throw error;
Console.log (' The solution is: ', results[0].solution);
});
Connection.end ();
node. js Connection MySQL