file의 한계
Relational Database
데이터를 표의 형태로 나타낸다.
컴퓨터 언어를 통해서 데이터베이스를 제어
mysql community edition download
bitnami wamp
Apache, mySQL, PHP 를 동시에 설치해주는 프로그램Manage Servers 탭에서 실행 혹은 중지C:\Bitnami\wampstack-7.4.9-0\mysql\bin 로 이동 후 mysql -uroot -p.구성요소
표(table)데이터베이스(database, schema) : 일종의 폴더로 표들을 그룹핑한 것데이터베이스 서버(database server) : 데이터베이스, 스키마를 그룹핑한 것데이터베이스 서버로 접속
bitnami wamp
Apache, mySQL, PHP 를 동시에 설치해주는 프로그램Manage Servers 탭에서 실행 혹은 중지C:\Bitnami\wampstack-7.4.9-0\mysql\bin 로 이동 후 mysql -uroot -p효용
-u : User
-p : Password
데이터베이스 사용
검색
mysql create databasemysql delete databasehow to show database list in mysql생성
CREATE DATABASE 스키마이름;삭제
DROP DATABASE 스키마이름;확인
SHOW DATABASES;사용
USE 스키마이름;*SQL
SQL을 통해 MySQL Server와 대화table, 표
row, record, 행column, 열테이블 생성
create table in mysql cheat sheetid column 생성
mysql datatype numberNOT NULL : 값을 반드시 입력AUTO_INCREMENT : 자동으로 1씩 증가PRIMARY KEY (id) : 식별자로 사용하고 있기 때문에 중복방지title column 생성
mysql datatype stringVARCHAR : 정한 글자수만 입력description column 생성
mysql datatype stringTEXT : 65,535자 까지 가능created column 생성
mysql datatype date/timeERROR 1820 (HY000): You must reset your password using ALTER USER statement before excuting this statement.
SET PASSWORD = PASSWORD('새로운 비밀번호');`CREATE TABLE topic (
  id INT(11) NOT NULL AUTO_INCREMENT,
  title VARCHAR(100) NOT NULL,
  description TEXT NULL,
  created DATETIME NOT NULL,
  author VARCHAR(30) NULL,
  profile VARCHAR(100) NULL,
  PRIMARY KEY (id)
);
CRUD
CreateReadUpdateDelete쓰기
**row 생성
mysql create rowINSERT INTO table_name (column1, ...) VALUES (value1...);DESC 테이블명; : 구조를 보여준다.실습
INSERT INTO topic (title,description,created,author,profile) VALUES('MySQL','MySQL is ...',NOW(),'egoing','developer');how to read row in mysql읽기
mysql select syntaxSELECT * FROM topic;
column 보기SELECT '표시하고 싶은 column' FROM topic WHERE '조건';
SELECT id, title,created,author FROM topic WHERE author='egoing' ORDER BY id DESC LIMIT 2;WHERE : 조건에 맞는 행만을 출력ORDER BY 원하는 행의 오름차순, 내림차순 정렬LIMIT : 데이터를 가져오는 수수정
sql update mysqlUPDATE 'table이름' SET 'column이름 = '값'' WHERE '원하는 행';
WHERE 을 사용하지 않으면 모든 데이터가 바뀐다.UPDATE topic SET description='ORACLE is', title='Oracle' WHERE id=2;삭제
sql delete in mysql DELETE FROM '테이블이름' WHERE '원하는 행';
WHERE 을 사용하지 않으면 모든 데이터가 삭제된다.DELETE FROM topic WHERE id =5;혁신과 본질
Relational = 혁신 = innovationDatabase = 본질 = essence = CRUD필요성
흐름을 이해해보자
topic 테이블 이름을 topic_backup 으로 변경topic 테이블의 author_id 가 author 테이블 참조--
-- Table structure for table `author`
--
 
 
CREATE TABLE `author` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  `profile` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`)
);
 
--
-- Dumping data for table `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');
 
--
-- Table structure for table `topic`
--
 
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`)
);
 
--
-- Dumping data for table `topic`
--
 
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);
topic 테이블의 author_id 값과 author 테이블의 id 값을 연결
SELECT * FROM topic LEFT JOIN author ON topic.author_id=author.id;
topic 테이블과 join 테이블을 합친다ON 조건 만족시키는 경우SELECT id, title, description, created, name, profile FROM topic LEFT JOIN author ON topic.author_id = author.id;
SELECT topic.id, title, description, created, name, profile FROM topic LEFT JOIN author ON topic.author_id = author.id;
SELECT topic.id AS topic_id, title, description, created, name, profile FROM topic LEFT JOIN author ON topic.author_id = author.id; 
id 란 값이 2개 중복되므로 id 를 topic.id 로 열 구분을 해줘야 함topic.id AS topic_id에서 AS 를 이용해 이름 변경하여 출력 가능테이블을 분리한다는 것은, 모든 테이블이 식별자 값만 행에 포함하고 있다면
JOIN 을 통해 얼마든지 관계를 맺을 수 있다.**
client → Internet → server
client ← Internet ← server
**mysql 은 서버 와 클라이언트 둘다 설치
mysql monitor(client) 를 통해 명령어로 server 를 제어database server 를 직접 제어할 수 없다.MySQL monitor
CLI 기반MySQL client
mysql clientWorkbench GUI 환경
SQL 을 MySQL 서버에 전송함으로써 데이터베이스 서버를 제어./mysql -uroot -p -hlocalhost공부할 것들
index (색인) : 사용자들이 검색을 자주 하는 컬럼에 색인을 걸어둠modeling : 성능, 설계backup : 내 컴퓨터와 별도의 컴퓨터에 복제해서 보관 ex) mysqldump, binary logcloud : 내 컴퓨터가 아닌 큰 회사들의 인프라를 임대해서 원격 제어.backup도 알아서 해준다.AWS RDS, Google Cloud SQL for MySQL, AZURE Database for MySQLprogramming : DB 서버 핸들링python mysql api, php mysql api, java mysql api