我收到提示: 錯誤:錯誤:握手閒置超時到的NodeJS MySQL連接錯誤
0
A
回答
0
使用連接池:
var mysql = require('mysql');
var pool = mysql.createPool({
host : 'example.org',
user : 'bob',
password : 'secret'
});
pool.getConnection(function(err, connection) {
// Use the connection
connection.query('SELECT something FROM sometable', function(err, rows) {
// And done with the connection.
connection.release();
// Don't use the connection here, it has been returned to the pool.
});
});
0
您可以使用node-mysql,它非常容易使用。我已經使用過一次,這裏是例子: -
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret',
database : 'my_db'
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
if (err) throw err;
console.log('The solution is: ', rows[0].solution);
});
connection.end();
相關問題
- 1. nodejs連接mysql錯誤
- 2. mysql連接丟失錯誤nodejs
- 3. 將nodejs連接到mysql
- 4. 當連接到mysql時mac上的nodejs錯誤
- 5. nodejs mysql錯誤:連接丟失服務器關閉了連接
- 6. 錯誤連接到MySQL
- 7. nodejs mongoose連接到數據庫錯誤
- 8. 錯誤nodejs連接到數據庫
- 9. NodeJs錯誤:連接ETIMEDOUT
- 10. MySQL連接錯誤
- 11. MySQL連接錯誤
- 12. Node.js的連接mysql錯誤
- 13. MySQL錯誤連接到MySQL失敗
- 14. node-mysql錯誤:連接ECONNREFUSED
- 15. Mysql連接錯誤
- 16. 錯誤MySQL連接
- 17. 連接mysql錯誤
- 18. 連接錯誤MySQL
- 19. Nodejs套接字連接錯誤
- 20. 連接mysql得到廢棄的錯誤
- 21. 使用java連接到mysql的錯誤
- 22. 將PHP連接到MYSQL的錯誤
- 23. 連接錯誤的Django到mysql
- 24. C++ Netbeans的連接到MySQL給錯誤
- 25. C++連接到mysql與庫的錯誤
- 26. php mysql - 連接到locahost的錯誤
- 27. Java到MySQL的連接錯誤
- 28. 錯誤Solr的連接到MySQL
- 29. 連接到MySQL的錯誤Zend Framework
- 30. 用的NodeJS MSSQL連接超時錯誤
您可以發佈在上下文中的代碼的NodeJS? – 2016-04-28 06:20:46
看到這個帖子:http://stackoverflow.com/questions/20210522/nodejs-mysql-error-connection-lost-the-server-closed-the-connection – Subburaj
變化'主持人: 「127.0.0.1」''到主機:「localhost」的' –