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