this article illustrates the way nodejs simply access and operate the MySQL database. Share to you for your reference, as follows:

 var MySQL = require ('mysql'); / / call the MySQL module of Mysql to install NPM install $MySQL / / create a connection connection = var mysql.createConnection ({host:'127.0.0.1', user:'root', //MySQL / / host authentication user name password:', //MySQL user password authentication port:'3306'/ / database:'' / / port number database name}); / / create a connection connection.connect (function (ERR) {if (ERR) {console.log ('[query]: '+ ERR); return;} console.log ('[connection connect] succeed!');}); / / execute SQL statements ('SELECT 1 + 1 connection.query AS solution', function (err, rows, fields) {if (ERR) {console.log ('[query]:'+err); return; Console.log ('The solution is:} ', rows[0].solution);}); / / connection.end close connection (function (ERR) if (ERR) {{return}; console.log ('[connection end] succeed!');}); 

strong> note: nodejs in the operation of the database without setting up database the set names utf8

encoding format hope to help the nodejs programming.

This paper fixed link:http://www.script-home.com/nodejs-example-of-simple-access-to-and-operation-of-a-mysql-database.html | Script Home | +Copy Link

Article reprint please specify:Nodejs example of simple access to and operation of a MySQL database | Script Home

You may also be interested in these articles!