Error: connect ECONNREFUSED ::1:3306 is when i try to use typeorm in nestjs

7.1k views Asked by At

This error when i try to use typeorm in nestjs

i did setting for using typeorm like this

app.module.ts

import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
import { UserModule } from './user/user.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import config from './ormconfig';
import { User } from './user/user.entity';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql', //Database 설정
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: "",
      database: 'hinest',
      entities: [User], // Entity 연결
      synchronize: true,
    }),
    GraphQLModule.forRoot<ApolloDriverConfig>({
      driver: ApolloDriver,
      debug: false,
      playground: false,
      autoSchemaFile: 'schema.gpl'
    }),
    UserModule,
    TypeOrmModule.forFeature([User])
  ],
  controllers: [],
  providers: [],
})
export class AppModule { }

Some People said "You have to start mysql" so i did "mysql.server start" or "mysql.server restart" but error still lives..

if you want to see anthor code i can show that

i can not do nothing cuz this erorr

plz help me..

2

There are 2 answers

0
Matheus Reis On

you can change the host of the connection to 127.0.0.1 as well

imports: [
    TypeOrmModule.forRoot({
      type: 'mysql', //Database 설정
      host: '127.0.0.1',
      port: 3306,
      username: 'root',
      password: "",
      database: 'hinest',
      entities: [User], // Entity 연결
      synchronize: true,
    }),
    GraphQLModule.forRoot<ApolloDriverConfig>({
      driver: ApolloDriver,
      debug: false,
      playground: false,
      autoSchemaFile: 'schema.gpl'
    }),
    UserModule,
    TypeOrmModule.forFeature([User])
  ],
2
Antonio Trapani On

Edit your /etc/hosts and remove the line starting with ::1