데이터
관리 도구 -> 파일
관리 도구 -> database
database 종류 : MySQL, Oracle, SQL Server, PostgreSQL, MongoDB 등
CRUD : database 의 핵심 작업
스프레드시트
를 통한 파일 내 데이터들 처리
관계형 데이터 베이스(Relational DBMS)
관계형 데이터 베이스 X (Document store)
요약
스프레드시트 VS MySQL
MySQL 의 구조
database 장점
SQL (Structured Query Language)
관련 용어 정리
[schema]
CREATE DATABASE opentutorials
USE opentutorials
SHOW opentutorials
[table]
CREATE TABLE topic(
id INT(11) NOT NULL AUTO_INCREMENT,
title VARCHAR(100) NOT NULL,
description TEXT NULL,
created DATETIME NOT NULL,
author VARCHAR(15) NULL,
profile VARCHAR(200) NULL,
PRIMARY KEY(id)
);
id INT(11) NOT NULL AUTO_INCREMENT
: id 컬럼, int 형으로 11자리까지 노출, 공백 허용 X, 자동으로 값 증가
title VARCHAR(100) NOT NULL
: title 컬럼, VARCHAR 형 100자리까지 생성, 공백 허용 X
PRIMARY KEY(id)
: 메인키는 id, 중복 불가능
table 출력 : SHOW TABLES
table 생성 후 확인 : DESC topic;
참고) 검색을 할 때 cheat sheet 를 참고하면서 하면 좋다!
CRUD : Create
, Read
, Update
, Delete
INSERT
(내용 생성)
INSERT INTO topic (title, description, created, author, profile)
VALUES('MySQL', 'MySQL is ...', NOW(), 'egoing', 'developer');
SELECT
(출력)
SELECT * FROM topic;
SELECT id, title, author FROM topic;
engoing
인 데이터만 출력 : SELECT * FROM topic WHERE author='egoing';
SELECT * FROM topic ORDER BY id DESC;
SELECT * FROM topic LIMIT 2;
UPDATE
(업데이트)
UPDATE topic
SET description='Oracle is ...', title='Oracle'
WHERE id=2;
DELETE
(삭제)DELETE from topic WHERE id=5;
[테이블 분리하기]
author_id 값에 대한 table 을 생성(TABLE author)하고 topic 의 author 에서는 author_id 값을 저장함
author
table 생성CREATE TABLE `author` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`profile` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`)
)
author
데이터 입력INSERT INTO `author` VALUES (1,'egoing','developer');
INSERT INTO `author` VALUES (2,'duru','database administrator');
INSERT INTO `author` VALUES (3,'taeho','data scientist, developer');
topic
table 생성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`)
)
topic
데이터 입력INSERT INTO `topic` VALUES (1,'MySQL','MySQL is...',now(),1);
INSERT INTO `topic` VALUES (2,'Oracle','Oracle is ...',now(),1);
INSERT INTO `topic` VALUES (3,'SQL Server','SQL Server is ...',now(),2);
INSERT INTO `topic` VALUES (4,'PostgreSQL','PostgreSQL is ...',now(),3);
INSERT INTO `topic` VALUES (5,'MongoDB','MongoDB is ...',now(),1);
[JOIN]
SELECT topic.id AS topic_id, title, description, created, name, profile
FROM topic LEFT JOIN author ON topic.author_id = author.id;
topic.id, title, description, created, name, profile
만 출력topic.id AS topic_id
: table 에 id 가 아닌 topic_id 로 변경되어 출력됨topic LEFT JOIN author
: topic table 을 중심으로 author table 합치기 진행ON topic.author_id = author.id;
: JOIN 기준[관계형 데이터베이스의 장점]
JOIN
을 통해서 관계를 맺을 수 있음[인터넷과 데이터베이스]
mysqldump
, binary log
AWS RDS
, Google Cloud SQL for MySQL
, AZURE Database for MySQL
Python mysql api
, php mysql api
, java mysql api