gpt4 book ai didi

node.js - 运行 node-mysql 教程时出错

转载 作者:搜寻专家 更新时间:2023-10-31 23:10:10 24 4
gpt4 key购买 nike

我正在运行 node-mysql 教程部分的代码,它给我错误

代码

var MySQLPool = require("mysql-pool").MySQLPool;
var pool = new MySQLPool({
poolSize: 4,
user: 'root',
password: 'root',
database: 'test'
});

pool.query("SELECT 'Hello, World!' AS hello", function(err, rows, fields) {
if(err) throw err;
console.log(rows[0].hello);
});

for(var i = 0; i < 10; ++i) {
pool.query("SELECT SLEEP(2), ? AS i", [i], function(err, rows, fields) {
if(err) throw err;
console.log("Slept: " + rows[0].i);
});
}

错误:

/home/comapq/Works/Nodejs/Codes/node_modules/mysql-pool/lib/mysql-pool/pool.js:158 for(var key in Client.prototype) { ^ TypeError: Cannot read property 'prototype' of undefined at MySQLPool._populate (/home/comapq/Works/Nodejs/Codes/node_modules/mysql-pool/lib/mysql-pool/pool.js:158:23) at new MySQLPool (/home/comapq/Works/Nodejs/Codes/node_modules/mysql-pool/lib/mysql-pool/pool.js:44:7) at Object. (/home/comapq/Works/Nodejs/Codes/test-mysql-3.js:2:12) at Module._compile (module.js:449:26) at Object.Module._extensions..js (module.js:467:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.runMain (module.js:492:10) at process.startup.processNextTick.process._tickCallback (node.js:244:9)

最佳答案

经过一番研究,我发现了问题所在。您可能像这样安装了 mysql:

npm install mysql

这会获取最新的 mysql 包,即 2.0.0-alpha5(开发阶段,大部分未经测试)。你需要安装最新稳定版的mysql:

npm install mysql@0.9.6

关于node.js - 运行 node-mysql 教程时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14070188/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com