使用Nodejs的mysql模組串連MySql資料庫出現以下錯誤

來源:互聯網
上載者:User

標籤:func   UI   ejs   sha   blog   create   pass   lib   not   

C:\Users\horn1\Desktop\node.js\39>node express.js{ Error: Handshake inactivity timeout    at Handshake.<anonymous> (C:\Users\horn1\Desktop\node.js\39\node_modules\mysql\lib\protocol\Protocol.js:164:17)    at emitNone (events.js:105:13)    at Handshake.emit (events.js:207:7)    at Handshake._onTimeout (C:\Users\horn1\Desktop\node.js\39\node_modules\mysql\lib\protocol\sequences\Sequence.js:129:8)    at ontimeout (timers.js:469:11)    at tryOnTimeout (timers.js:304:5)    at Timer.listOnTimeout (timers.js:264:5)    --------------------    at Protocol._enqueue (C:\Users\horn1\Desktop\node.js\39\node_modules\mysql\lib\protocol\Protocol.js:145:48)    at Protocol.handshake (C:\Users\horn1\Desktop\node.js\39\node_modules\mysql\lib\protocol\Protocol.js:52:23)    at PoolConnection.connect (C:\Users\horn1\Desktop\node.js\39\node_modules\mysql\lib\Connection.js:130:18)    at Pool.getConnection (C:\Users\horn1\Desktop\node.js\39\node_modules\mysql\lib\Pool.js:48:16)    at IncomingMessage.<anonymous> (C:\Users\horn1\Desktop\node.js\39\express.js:29:8)    at emitOne (events.js:115:13)    at IncomingMessage.emit (events.js:210:7)    at IncomingMessage.Readable.read (_stream_readable.js:478:10)    at flow (_stream_readable.js:849:34)    at resume_ (_stream_readable.js:831:3)  code: ‘PROTOCOL_SEQUENCE_TIMEOUT‘,  fatal: true,  timeout: 10000 }

代碼如下:

‘use strict‘;var express=require(‘express‘);var fs=require(‘fs‘);var querystring=require(‘querystring‘);var http=require(‘http‘);var app=express();var mysql=require(‘mysql‘);var pool=mysql.createPool({    host:‘192.168.80.129‘,// 資料庫在本地虛擬機器上,能用mysql-front連通    port:‘3306‘,    database:‘test‘,    user:‘root‘,    password:‘12345678‘,        timeout:1000000000,        connectTimeout:1000000000,});app.get(‘/index.html‘,function(req,res){    res.writeHead(200,{‘Content-type‘:‘text/html‘});    var file=fs.createReadStream(‘index.html‘);    file.pipe(res);});app.post(‘/index.html‘,function(req,res){    req.on(‘data‘,function(data){        var obj=querystring.parse(data.toString());        pool.getConnection(function(err,connection){            if(err){                res.send(‘Can not connect to MySql DB‘);                console.log(err);            }else{                var str;                connection.query(‘insert into emp set ?‘,{name:obj.name},function(err,result){                    if(err){                        str=‘Insert failed‘;                    }else{                        str="Insert succeed";                    }                    connection.release();                    res.send(str);                })            }        });    });});app.listen(3333,"127.0.0.1");

 

使用Nodejs的mysql模組串連MySql資料庫出現以下錯誤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.