Node.js中测试mysql的代码var client = mysql.createClient运行出错:TypeError: Object # has no method ‘createClient’
今天在WebStorm下熟悉一个node.js的项目,配置环境时,手一抖,将mysql包从0.8升级到了2.1.1,结果再运行时就出错了。
[Fri Mar 14 2014 17:05:49] 连接数据库失败:TypeError: Object #<Object> has no method 'createClient'
TypeError: Object false has no method 'query'
at getPlayedFun (C:\Users\Administrator\getdata\data.js:80:9)
at Object.<anonymous> (C:\Users\Administrator\getdata\data.js:69:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
后面在网上搜索了下,幸好我不是第一个遇到这种问题的人,原文链接;
只要将mysql.createClient
改成mysql.createConnection,就可以运行了。