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

g2ieeal7  于 2021-06-17  发布在  Mysql
关注(0)|答案(0)|浏览(289)

我正在使用node.js的mysql库并执行以下代码:

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

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题