Error: connect ECONNREFUSED 127.0.1:3306 (구덩이 피하기!!!)
6401 단어 전단 학습 중 사소한 문제에 부딪히다
Error: connect ECONNREFUSED 127.0.0.1:3306
오늘 koa 연결 데이터베이스 설정을 할 때 Error:connect ECONNREFUSED 127.0.1:3306
잘못 보고하다 Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
--------------------
at Protocol._enqueue (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\mysql\lib\Pool.js:48:16)
at Pool.query (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\mysql\lib\Pool.js:202:8)
at D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\co-mysql\index.js:23:13
at new Promise (<anonymous>)
at Object.o.query (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\co-mysql\index.js:14:13)
at server.use (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-\mysql-co-mysql.js:21:26)
at dispatch (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\koa-compose\index.js:42:32)
몇 차례의 검사 후 액세스 포트 수정 등에서 문제가 없음을 발견하였다
server.use (D:\weblearning\mycode\mobileWebCode\webRecodeode\koa-\mysql-co-mysql.js:21:26)
거의 문제 없어요.
mysql-co-mysql.js const Koa=require('koa')
const Router=require('koa-router')
const mysql=require('mysql')
const co=require('co-mysql')
let conn=mysql.createPool({
host:'localhost',
user:'root',
password:'',
database:'20191217'
})
let db=co(conn);
let server=new Koa()
server.listen(8000);
server.context.db=db;
// , ctx.db ,
server.use(async ctx=>{
let data=await ctx.db.query('SELECT * FROM item_table')
ctx.body=data;
})
마지막으로 wampserver를 검사한 결과 열려 있는 MySQL 포트가 3308(잊어버렸을 수도 있음)이고 포트를 3306으로 다시 설정하면 됩니다.
Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
--------------------
at Protocol._enqueue (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\mysql\lib\Pool.js:48:16)
at Pool.query (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\mysql\lib\Pool.js:202:8)
at D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\co-mysql\index.js:23:13
at new Promise (<anonymous>)
at Object.o.query (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\co-mysql\index.js:14:13)
at server.use (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-\mysql-co-mysql.js:21:26)
at dispatch (D:\weblearning\mycode\mobileWebCode\webRecode
ode\koa-
ode_modules\koa-compose\index.js:42:32)
const Koa=require('koa')
const Router=require('koa-router')
const mysql=require('mysql')
const co=require('co-mysql')
let conn=mysql.createPool({
host:'localhost',
user:'root',
password:'',
database:'20191217'
})
let db=co(conn);
let server=new Koa()
server.listen(8000);
server.context.db=db;
// , ctx.db ,
server.use(async ctx=>{
let data=await ctx.db.query('SELECT * FROM item_table')
ctx.body=data;
})