• 회원가입
  • 로그인
  • 구글아이디로 로그인

[mysql] Node.js - MySQL Create Database (DB 생성)

2,471  
목차

 

DB 생성

1. C:\User\사용자명\hz.js 생성. (DB명 : hz) 

※ 핑크색 부분을 본인 사정에 맞게 적당히 수정.

 

var mysql = require('mysql');

 

var con = mysql.createConnection({

  host: "localhost",

  user: "root",

  password: "autoset"

});


con.connect(function(err) {

  if (err) throw err;

  console.log("Connected!");

  con.query("CREATE DATABASE hz", function (err, result) {

    if (err) throw err;

    console.log("Database created");

  });

});

 


2. CMD 모드에서 아래 명령어 입력해 시작 설정.

 

C:\User\사용자명>node hz.js

 

 

※ DB 생성 성공하면 아래 메세지 뜸.

Connected!

Database created



분류 제목
mysql Node.js - MySQL 설치・연결 + 쿼리 보내기
mysql Node.js - MySQL Create Database (DB 생성)
mysql Node.js - MySQL Create Table (테이블 생성) ※ Primary key 설정.
mysql Node.js - MySQL Insert Into (데이터 삽입)
mysql Node.js - MySQL Select From (데이터 선택)
mysql Node.js - MySQL Where (조건절)
mysql Node.js - MySQL Order By (정렬 순서)
mysql Node.js - MySQL Delete From (데이터 삭제)
mysql Node.js - MySQL Drop Table (테이블 삭제)
mysql Node.js - MySQL Update (데이터 수정)
mysql Node.js - MySQL Limit (데이터 출력개수)
mysql Node.js - MySQL Join (테이블 결합)
목록
찾아주셔서 감사합니다. Since 2012