node. js MySQL Package usage instructions

Source: Internet
Author: User

  Zhanhailiang Date: 2014.11.16

This article explains how to rely on the MySQL package on the node. JS platform for MySQL access.

1. Installation:

[ root@  ~/ Wade/ nodejs/  nodebeginner/ mysql_test"  # NPM Install MySQL  

2. mysql-based package for MySQL connection and query:

[Root@~/Wade/Nodejs/Nodebeginner/mysql_test]# cat Mysqltest.jsvar mysql = require(' MySQL '); var connection = Mysql.createconnection({Host:' localhost ', User:' ****** ', Password:' ****** '}); Connection.connect(); Connection.query(' SELECT * from Test.test ', function(err, rows, fields) {    if (Err) {throw err; }Console.log(rows); Console.log( Fields);}); Connection.end(); // register the end processor without worrying about query async connection Close

3. Implementation steps:

It is no different from other languages-first configure the parameters to connect the db to connect, how to connect, with which account connection, the connection is successful after the corresponding SQL operation, and finally close the connection.

4. Complete code:

Https://github.com/billfeller/nodebeginner/tree/master/mysql_test

5. Official documents:

Https://www.npmjs.org/package/mysql

node. js MySQL Package usage instructions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.