본문 바로가기
Dev/Nodejs-mysql

[Nodejs-mysql] mysql 데이터 등록

by Ellen571 2020. 8. 5.
반응형

[생활코딩] 실습준비

 

 

서버 접속하기

 

mysql -uroot -p

 

 

데이터베이스 생성하고 확인하기

 

CREATE DATABASE openturorials;
SHOW DATABASES;

 

 

데이터베이스 사용하기

 

USE opentutorials;

 

 

테이블 생성하고 데이터 넣기

 

CREATE TABLE author (
  id int(11) NOT NULL AUTO_INCREMENT,
  name varchar(20) NOT NULL,
  profile varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`)
);

 

INSERT INTO author VALUES (1,'egoing','developer');
INSERT INTO author VALUES (2,'duru','database administrator');
INSERT INTO author VALUES (3,'taeho','data scientist, developer');

 

CREATE TABLE topic (
  id int(11) NOT NULL AUTO_INCREMENT,
  title varchar(30) NOT NULL,
  description text,
  created datetime NOT NULL,
  author_id int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
);

 

INSERT INTO topic VALUES (1,'MySQL','MySQL is...','2018-01-01 12:10:11',1);
INSERT INTO topic VALUES (2,'Oracle','Oracle is ...','2018-01-03 13:01:10',1);
INSERT INTO topic VALUES (3,'SQL Server','SQL Server is ...','2018-01-20 11:01:10',2);
INSERT INTO topic VALUES (4,'PostgreSQL','PostgreSQL is ...','2018-01-23 01:03:03',3);
INSERT INTO topic VALUES (5,'MongoDB','MongoDB is ...','2018-01-30 12:31:03',1);

 

 

테이블 확인하기

 

SHOW tables;

 

 

테이블 데이터 확인하기

 

SELECT * FROM topic;
SELECT * FROM author;
반응형