大本赢彩票开户

码迷,xscp18.com
大本赢彩票开户 > 数据库 > 详细

使用Nodejs的mysql模块连接MySql数据库出现以下错误

时间:2018-03-25 17:03:19      阅读:2422      评论:0      收藏:0      [点我收藏+]

标签: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数据库出现以下错误

标签:func   UI   ejs   sha   blog   create   pass   lib   not   

原文地址:https://www.cnblogs.com/xiandedanteng/p/8645206.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
           
© 2014 xscp18.com 版权所有 京ICP备13008772号-2
迷上了代码!
宏运彩票开户 77彩票网开户 云鼎彩票开户 四柱彩票开户 九度彩票开户 多彩彩票开户 众享彩票开户 36彩票开户 全球彩票开户 福布斯彩票开户