如何在express.js中连接mysql数据库?

时间:2018-12-11 02:24:50

标签: mysql node.js

我将mysql库用于node.js,并执行以下代码:

  var connection = mysql.createConnection({
  host: 'example.com',
  user: 'user',
  password: 'password',
  database:'databasename',


});

connection.connect();

我收到以下错误:

Error: listen EADDRINUSE :::3000
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at Server.setupListenHandle [as _listen2] (net.js:1367:14)
at listenInCluster (net.js:1408:12)
at Server.listen (net.js:1492:7)
at Function.listen (/home/daniel/Desktop/100server/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/daniel/Desktop/100server/server.js:33:5)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)

我认为它与主机有关,应该执行类似mysql://example.com

的操作

0 个答案:

没有答案