node. JS (Connection MySQL)

Source: Internet
Author: User

SQL in the MySQL statement

Classification in SQL statements:

---DDL: (data define language) to define the columns (create,drop,alter,truncate)

---DML: (data manipulate language)-operation data row (insert Delete,update)

---DQL: (data Query Language)--querying (SELECT)

---DCL: (Data Control Language)--controlling user rights (Grant,revoke)

Using node. js to access the MySQL server requires the use of a third-party module--mysql module

1.---Create a connection to the database server

Const MySQL = require (' mysql ');

var con = mysql.createconnertion ({});

---Send SQL statements to the database server for execution

Con.query (' sql ... ', function (Err,result) {});

---close connection con.end ();

2.--Creating a connection pool

Const MySQL = require (' mysql ');

var pool = Mysql.createpool ({

Host: ' localhost ',

User: ' Root ',

Password: ",

Connectionlimit:10});

Pool.getconnection ((Err,con) =>{

Con.query (' sql:?,? [ x, Y], (err,result) =>{

Con.release ();

}}

node. JS (Connection MySQL)

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.