데이터 베이스 - 정보를 관리하는 전문 에플리케이션
File(기본 적, 원시적 데이터 관리 수단, 설치X, 어느 곳에서나 쉽게 사용 가능) VS DATABASE ( 설치를 해야 하고 배워야 쓸 수 있음, 안전하고 빠름, 프로그래밍적 제어 가능)
관계형 데이터 베이스(보편적) - My SQL - 웹과 함께 성장한 데이터 베이스 (오픈 소스)
MSSQL , Oracle
-> 서로 다른 회사지만 SQL이라는 표준화된 프로그래밍 언어를 구현하고 있어서 동일한 SQL을 통해 시스템 제어
My SQL 회사 소유 변천 과정
MySQL AB -> SUN -> Oracle (오라클의 정체에 불만을 가진 개발자들이 나와서 Maria DB를 만듦)
My SQL = Maria DB (완벽 호환)
데이터 베이스의 키워드 - Structured (구조화된) - 정돈된 상태 -> table system ex) 엑셀
데이터 베이스와 엑셀의 차이 -> SQL(Structured Query Language)의 유무
- 컴퓨터에게 구조화된 정보를 질의하는 프로그래밍 언어
MySQL Client <-> MySQL Server
SELECT * FROM topic; -> 데이터 베이스를 제어할 때 쓰는 언어 (SQL)
웹브라우저 <-> 웹서버 <-> PHP <-> MySQL
- MySQL에 관에서 PHP는 클라이언트다 ->클라이언트와 서버의 관계는 가변적임
MySQL monitor 실행 - cmd 창
디렉토리 변경
1) cd mysql 디렉토리
2) mysql -hlocalhost -uroot -p 엔터 후 비밀번호 입력
-h -> 뒤에 와는 것이 주소 이름임을 나타냄 (클라이언트와 서버컴이 다른 경우 서버컴의 주소를 입력)
-u -> 뒤에 있는 id가 root임
-p -> 비밀번호를 입력 받아라
My SQL 서버에 데이터베이스가 포함되고 데이터베이스 안에는 여러 테이블들이 있다.
-테이블은 파일과 같음(파일이 많아지면 디렉토리를 만들어 이름이 같은 여러 파일 생성 가능)
제로보드나 wordpres 등 설치 사용 웹 에플리케이션은 하나의 데이터베이스이다.
1.데이터베이스 생성
CREATE DATABASE opentutorrials CHARATER SET utf8 COLLATE utf8_general_cj;
-> opentutorials 라는 이름을 가진 데이터 베이스를 생성, 입력할 데이터카 utf8 방식의 문자로 기록됨
-> 문법적인 것은 대문자 나머지는 소문자로 기록
2.데이터베이스 안에 들어가 작업 (파일 작업시 해당 디렉토리에 들어가는 것과 같은 이치)
use opentutorials (오픈튜토리어스 데이터베이스 접속)
3.테이블 만들기 (엑셀시트 하나 만드는 것과 같음)
ID |
title |
description |
author |
created |
|
|
|
|
|
|
|
|
|
|
CREATE TABLE `topic ` ( ( ` -> 안의 문자가 문법이 아니라는 것을 구분함)
`id`
int
(11)
NOT
NULL
AUTO_INCREMENT,
`title`
varchar
(100)
NOT
NULL
,
`description` text
NOT
NULL
,
`author`
varchar
(30)
NOT
NULL
,
`created` datetime
NOT
NULL
,
PRIMARY
KEY
(id)
) ENGINE=InnoDB
DEFAULT
CHARSET=utf8;
데이터베이스와 엑셀의 차이점 -> 정보의 엄격한 관리
-> 테이블에 정보가 들어감으로서 정해진 포멧이 확실히 보장됨
ex) id int(11) -> 정수 아닌 데이터는 입력 불가, 사용자가 id 데이터는 정수라는 확신을 가질 수 있음
NOT NULL -> 정보가 반드시 있다는 걸(NULL 값이 없다는 것) 보증
테이블 행의 추가 -> 데이터 추가
테이블 열의 추가 -> 구조 추가
생성된 테이블 확인
show tables;
데이터 삽입
INSERT
INTO
`topic` (`id`, `title`, `description`, `author`, `created`)
VALUES
(1,
'About JavaScript'
,
'<h3>Desctiption</h3>\r\n<p>JavaScript is a dynamic computer programming language. It is most commonly used as part of web browsers, whose implementations allow client-side scripts to interact with the user, control the browser, communicate asynchronously, and alter the document content that is displayed.</p>\r\n<p>\r\nDespite some naming, syntactic, and standard library similarities, JavaScript and Java are otherwise unrelated and have very different semantics. The syntax of JavaScript is actually derived from C, while the semantics and design are influenced by the Self and Scheme programming languages.\r\n</p>\r\n<h3>See Also</h3>\r\n<ul>\r\n <li><a href="http://en.wikipedia.org/wiki/Dynamic_HTML">Dynamic HTML and Ajax (programming)</a></li>\r\n <li><a href="http://en.wikipedia.org/wiki/Web_interoperability">Web interoperability</a></li>\r\n <li><a href="http://en.wikipedia.org/wiki/Web_accessibility">Web accessibility</a></li>\r\n</ul>\r\n'
,
'egoing'
,
'2015-03-31 12:14:00'
);
INSERT
INTO
`topic` (`id`, `title`, `description`, `author`, `created`)
VALUES
(2,
'Variable and Constant'
,
'<h3>Desciption</h3>\r\n\r\nIn computer programming, a variable or scalar is a storage location paired with an associated symbolic name (an identifier), which contains some known or unknown quantity or information referred to as a value. The variable name is the usual way to reference the stored value; this separation of name and content allows the name to be used independently of the exact information it represents. The identifier in computer source code can be bound to a value during run time, and the value of the variable may thus change during the course of program execution.\r\n\r\n<h3>See Also</h3>\r\n<ul>\r\n<li>Non-local variable</li>\r\n<li>Variable interpolation</li>\r\n</ul>\r\n'
,
'k8805'
,
'2015-05-14 10:04:00'
);
INSERT
INTO
`topic` (`id`, `title`, `description`, `author`, `created`)
VALUES
(3,
'Opeartor'
,
'<h2>Operator</h2>\r\n<h3>Description</h3>\r\n<p>Programming languages typically support a set of operators: constructs which behave generally like functions, but which differ syntactically or semantically from usual functions</p>\r\n<p>Common simple examples include arithmetic (addition with +, comparison with >) and logical operations (such as AND or &&). </p>\r\n'
,
'egoing'
,
'2015-06-18 05:00:00'
);
INSERT
INTO
`topic` (`id`, `title`, `description`, `author`, `created`)
VALUES
(4,
'Conditional'
,
'<h3>Description</h3>\r\n<p>In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false. Apart from the case of branch predication, this is always achieved by selectively altering the control flow based on some condition.</p>\r\n<p>In imperative programming languages, the term "conditional statement" is usually used, whereas in functional programming, the terms "conditional expression" or "conditional construct" are preferred, because these terms all have distinct meanings.</p>\r\n<h3>See Also</h3>\r\n<ul>\r\n<li><a href="http://en.wikipedia.org/wiki/Branch_(computer_science)" title="Branch (computer science)">Branch (computer science)</a></li>\r\n<li><a href="http://en.wikipedia.org/wiki/Conditional_compilation" title="Conditional compilation">Conditional compilation</a></li>\r\n<li><a href="http://en.wikipedia.org/wiki/Dynamic_dispatch" title="Dynamic dispatch">Dynamic dispatch</a> for another way to make execution choices</li>\r\n<li><a href="http://en.wikipedia.org/wiki/McCarthy_Formalism" title="McCarthy Formalism">McCarthy Formalism</a> for history and historical references</li>\r\n<li><a href="http://en.wikipedia.org/wiki/Named_condition" title="Named condition" class="mw-redirect">Named condition</a></li>\r\n<li><a href="http://en.wikipedia.org/wiki/Test_(Unix)" title="Test (Unix)">Test (Unix)</a></li>\r\n<li><a href="http://en.wikipedia.org/wiki/Yoda_conditions" title="Yoda conditions">Yoda conditions</a></li>\r\n</ul>'
,
'c2'
,
'2015-07-25 00:00:00'
);
-> id는 AUTO_INCREMENT 로 인해 데이터를 추가될 때마다 자동으로 1씩 증가되어 추가되서 따로 입력하지 않아도 됨
-> 어느 특정 행의 정보만을 가져올 때, 유일무이한 값인 id로하여금 원하는 행의 정보를 가져올 수 있다.
원하는 데이터 불러오기
SELECT * FROM topic; -> topic 테이블 정보를 가져오라 ( * 는 열 전부를 특함)
SELECT title, author FROM topic; -> topic 테이블의 title, author 정보를 가져오라.
SELECT title, author FROM topic WHERE id=2; -> id=2에 해당하는 행의 title, author 정보 소환
* 정렬기능
뒤에 ORDER BY id DESC; -> 아이디 내림차순 (큰수부터 작은수로)
ORDER BY author DESC; (author 내림차순)
'프로그래밍 > 코딩야학' 카테고리의 다른 글
관계형 디비 이론, 실습 (0) | 2017.06.20 |
---|---|
데이터베이스 실습 (0) | 2017.06.19 |
PHP 실습 (0) | 2017.06.16 |
16 JS 실습 (0) | 2017.06.14 |
15일 UI VS API , 프로그래밍 접근방법 (0) | 2017.06.14 |