Node. js mysql package instructions, node. jsmysql

Source: Internet
Author: User

Node. js mysql package instructions, node. jsmysql

Author: zhanhailiang Date: 2014.11.16

This article explains how to rely on the mysql package on the node. js platform to access mysql.

1. installation:

[root@~/wade/nodejs/nodebeginner/mysql_test]# npm install mysql

2. mysql package-based connection and query:

[Root @~ /Wade/nodejs/nodebeginner/mysql_test] # cat mysqltest. js var 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, so you don't have to worry about making connection close when the query is asynchronous.

3. Implementation steps:

It is no different from other languages. First, configure parameters to describe how to connect to the database to be connected, which account to connect to, and then execute corresponding SQL operations after the connection is successful. 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

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.