Nodejs links to MySQL issues

Source: Internet
Author: User

First you have to have a ballpark understanding of MySQL.

For example: How to install, use the basic syntax, test the installation can be successful, and successful after the simple database, operation (increase and deletion) ...

Here is the business scenario: During a crawler, you need to output the information to MySQL when you rent it.

The problem is the error, said I grammatical errors (1)

Not before this mistake, what was the Com_quit (2) Error, why, because I went to call MySQL in the function, (

Connection.connect ();
Connection.end ();

After the search for Google, some people say that the two can be deleted, causing (2) The cause of the error is because every time to call, I re-read a bit of grammar. Found something that had a connection pool. The 1 errors that you see now appear when you delete the following.

So:

Instead of creating and managing connections One after another, this module uses Mysql.createpool (config) to provide a built-in connection pool.
You can centralize connections to simplify sharing a single connection or to manage multiple connections.
When you complete a connection, simply call Connection.release () and the connection will be returned to the pool, ready to be used again.
varMySQL = require ('MySQL');varPool =Mysql.createpool ({host:'example.org', User:'Bob', Password:'Secret', Database:'my_db'});p ool.getconnection (function (err, connection) {//Use the connectionConnection.query ('SELECT something from SomeTable', function (Error, results, fields) {//And done with the connection.connection.release (); //Handle error after the release.    if(Error)Throwerror; //Don ' t use the connection here, it had been returned to the pool.  });});

Pay special attention to grammar.

Nodejs links to MySQL issues

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.