본문 바로가기
코딩야학

생활코딩 Day20

by Jacob93 2017. 6. 24.

오늘은 20일차! 데이터베이스(MySQL) 이론 시간입니다!


<데이터 베이스 이론 1>


우선 데이터 베이스란 무엇일까요?


데이터 베이스란 정보를 관리하는 전문 애플리케이션 이라고 합니다!


쉽게 말해서 실제적으로 정보를 저장하는것을 의미합니다!


시스템이 고장났을때 방지할 수 있다는 특성이 있습니다. 왜냐하면 백업하는 기능이 기본적으로 들어있기 때문입니다!


SQL이라는 것을 통해서 프로그래밍적 제어가 가능합니다.


생활코딩에서 사용할 것은 MySQL이라고 합니다.


이것을 왜 사용하느냐...!  오픈소스로 되어있기 때문이라고 합니다!


그렇다면 SQL은 무엇의 약자 일까요?


Structured Query Language입니다.


컴퓨터에게 구조화된 정보를 질의 하는 언어라고 할 수 있습니다!


<데이터 베이스 이론 2>


MySQL은 서버와 클라이언트의 구조를 가지고 있는데요


서버와 클라이언트의 구조는 네트워크에서만 존재하는것이 아니라 데이터베이스에서도 존재하는 것을 알 수 있습니다.


생활코딩에서는 MySQL monitor를 통해 서버를 제어한다고 합니다.


그럼 제어하는 방법을 알아보도록 할게요!


먼저 윈도우키+R을 눌러서 실행창을 켭니다.


그후 cmd를 입력해 명령프롬프트를 실행시킵니다.



다음과 같은 화면이 나오게 되면 정상적으로 실행 준비가 된 것입니다.


그럼 이제 Mysql서버로 접근하는 법을 알아보도록 할게요


우선 bitnami에 깔려있는 mysql을 찾아 들어갑니다.


mysql폴더에서 bin폴더안에 mysql.exe 를 찾아 해당 폴더 주소를 복사합니다.




명령 프롬프트에 cd C:\Bitnami\wampstack-7.0.18-0\mysql\bin 를 입력합니다.


(주소를 복사한 후 붙여넣기는 마우스 오른쪽 버튼을 누르면 됩니다.)



엔터를 누르고 위치가 Bitnami\wampstack-7.0.18-0\mysql\bin 로 바뀌었다면 잘 따라고오 계십니다ㅎㅎ


다음 mysql -hlocalhost -uroot -p 를 입력한 후 비밀번호를 입력합니다.


-hlocalhost  : host는 localhost

-uroot : user는 root

-p : password


의 약자입니다!!



이런 화면이 떴다면 성공적으로 mysql서버에 접근을 한것입니다!


<데이터 베이스 이론 3>


데이터베이스 서버에 접근을 완료했죠!ㅎㅎ


그럼 이번엔 데이터베이스에 접근해서 테이블을 만들어 보도록 하겠습니다.


우선 어떤 데이터베이스들이 있는지 볼게요!


명령어는 show databases;



기본적으로 


information_schema

mysql

performance_schema

sys


라는 데이터 베이스들이 있는것을 볼 수 있습니다


그럼 데이터베이스를 만들어 볼게요!


데이터 베이스 생성의 명령어는


CREATE DATABASE opentutorials CHARACTER SET utf8 COLLATE utf8_general_ci;


이렇게 입력하고 다시 데이터 베이스가 생성되었는지 볼게요!



보시면 opentutorials라는 데이터 베이스가 생성된 것을 볼 수 있습니다!


이제 데이터베이스 중에 opentutorials를 선택해서 테이블을 만들어 보도록 하겠습니다.


데이터 베이스를 선택하는 명령어는 use opentutorials;


opentutorials 데이터베이스를 사용해서


그 안에서 topic이라는 테이블을 생성해줍니다.


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;


여기까지하면 이제 기본 틀이 만들어 진 것입니다.


이제 이 틀에다가 하나씩 속성을 넣어보도록 할게요!


우선 테이블이 만들어 졌는지 확인해보도록 하겠습니다.



이러면 topic이라는 테이블이 생성된것을 확인할 수 있게 됩니다.


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');

생활코딩님이 만들어 주신 insert문을 넣어보면



다음과 같이 잘 들어가 있는 것을 확인할 수 있게 됩니다~!!

'코딩야학' 카테고리의 다른 글

코딩야학Day19  (0) 2017.06.19
코딩야학Day16  (0) 2017.06.17
코딩야학Day15  (0) 2017.06.17
코딩야학Day14  (0) 2017.06.15
코딩야학Day13  (0) 2017.06.14

댓글