我无法将 Node.js 项目与 Mamp 数据库连接起来
I am not able connect Node.js project with Mamp dadabase
您好,我正在使用以下代码连接 Mamp 数据库“http://localhost:8888/phpMyAdmin/server_databases.php?server=1”,但无法做到以下几点错误
代码:-
const db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'nodejs.login',
})
db.connect((error) =>{
if(error){
console.log(error)
}else {
console.log("Mysql Connected....")
}
})
错误:-
server startwd on Port 5003
{ Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1117:14)
--------------------
at Protocol._enqueue (/Users/ruchir/Documents/Assesment_Node/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/Users/ruchir/Documents/Assesment_Node/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/Users/ruchir/Documents/Assesment_Node/node_modules/mysql/lib/Connection.js:116:18)
at Object.<anonymous> (/Users/ruchir/Documents/Assesment_Node/app.js:13:4)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true }
您的问题可能出在连接参数上,您正在设置 password: 'root'
。
根据我的经验,密码通常留空:password: ''
.
我能够解决 it.i 检查并发现我的 Mamp 服务器是 运行 在 8889
所以我在连接 port: '8889'
中又添加了一个变量。
您好,我正在使用以下代码连接 Mamp 数据库“http://localhost:8888/phpMyAdmin/server_databases.php?server=1”,但无法做到以下几点错误
代码:-
const db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'nodejs.login',
})
db.connect((error) =>{
if(error){
console.log(error)
}else {
console.log("Mysql Connected....")
}
})
错误:-
server startwd on Port 5003
{ Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1117:14)
--------------------
at Protocol._enqueue (/Users/ruchir/Documents/Assesment_Node/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/Users/ruchir/Documents/Assesment_Node/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/Users/ruchir/Documents/Assesment_Node/node_modules/mysql/lib/Connection.js:116:18)
at Object.<anonymous> (/Users/ruchir/Documents/Assesment_Node/app.js:13:4)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true }
您的问题可能出在连接参数上,您正在设置 password: 'root'
。
根据我的经验,密码通常留空:password: ''
.
我能够解决 it.i 检查并发现我的 Mamp 服务器是 运行 在 8889
所以我在连接 port: '8889'
中又添加了一个变量。