DDL – 구조를 만들자
웹 데이터 베이스
DataBase
• 자료를 저장하고 보여주고 관리하는 작업 공간
• 문자 저장 방식에 대한 이해 필요
o http://dev.mysql.com/doc/refman/5.1/en/charset-general.html o Character Set
• 심볼과 특정 코드로 인코딩 될 규칙들의 집합
• Ex) “A”, “B”, “a”, “b”
o “A” = 0, “B” = 1”, “a” = 2, “b” = 3
• “A”, “B”, “a”, “b” : 심볼
• 0, 1, 2, 3 : 코드 o Collation
• Character Set에서 문자들을 비교하기 위한 규칙들의 집합
• Ex) “A” = 0, “B” = 1
o 0 < 1 이므로 “A” 가 “ㅠ” 보다 작다 o 대소문자 비교는?
• binary collation : Case-sensitive
• 대소문자를 비교하지 않을 경우 : Case-insensitive
DataBase
• MySQL에서 지원하는 Character Set
DataBase
• MySQL에서 지원하는 Collation
DataBase
• DB 생성문 : CREATE DATABASE
o http://dev.mysql.com/doc/refman/5.1/en/create-database.html o CREATE DATABASE [IF NOT EXISTS] db_name [create_specification]
• Create_specification
o [DEFAULT] CHARACTER SET [=] charset_name o [DEFAULT] COLLATE [=] collation_name
Ex)
- DB명을 test1DB로 하되 동일한 이름이 있을 경우에만
CHARACTER SET이 utf8이 되는 DB를 생성하시오
DataBase
• DB 제거문 : DROP DATABASE
o http://dev.mysql.com/doc/refman/5.1/en/drop-database.html o DROP DATABASE [IF EXISTS] db_name
Ex)
- 방금 전에 작성한 test1DB가 있는지 점검하여 해당 db가 존재하면
제거하시오.
사용자
• 현대의 DBMS들은 별도의 사용 자를 갖는다.
• MySQL 설치시 시스템 사용자 인 ‘root’를 갖는다.
• DBMS 사용자는 시스템 자원 (DB, table, index, view 등)별 로 주어진 권한을 부여 받아 해 당 권한에 맞게 DB에 접근할 수 있다.
o ‘root’의 경우 일반 자원 접근 권 한과 서버 관리 권한을 모두 부여 받는다.
• http://dev.mysql.com/doc/
refman/5.1/en/privilege- system.html
Privilege Column Context
CREATE USER Create_user_priv server administration PROCESS Process_priv server administration RELOAD Reload_priv server administration REPLICATION CLIENT Repl_client_priv server administration
REPLICATION SLAVE Repl_slave_priv server administration
SHOW DATABASES Show_db_priv server administration SHUTDOWN Shutdown_priv server administration SUPER Super_priv server administration ALL [PRIVILEGES] server administration
USAGE server administration
관리자 권한
사용자
Privilege Column Context
CREATE Create_priv databases, tables, or indexes DROP Drop_priv databases, tables, or views
GRANT OPTION Grant_priv databases, tables, or stored ro utines
REFERENCES References_priv databases or tables EVENT Event_priv databases
ALTER Alter_priv tables DELETE Delete_priv tables INDEX Index_priv tables
INSERT Insert_priv tables or columns SELECT Select_priv tables or columns UPDATE Update_priv tables or columns CREATE TEMPORA
RY TABLES
Create_tmp_table_priv tables
LOCK TABLES Lock_tables_priv tables TRIGGER Trigger_priv tables CREATE VIEW Create_view_priv views SHOW VIEW Show_view_priv views
ALTER ROUTINE Alter_routine_priv stored routines CREATE ROUTINE Create_routine_priv stored routines EXECUTE Execute_priv stored routines
FILE File_priv file access on server host
일반 자원 접근 권한
사용자 : 추가
• 사용자 추가 : CREATE USER
o http://dev.mysql.com/doc/refman/5.1/en/adding-users.html o http://dev.mysql.com/doc/refman/5.1/en/create-user.html o CREATE USER user_specification
• User_specification
o ‘User_name’@’Host_name’
o [IDENTIFIED BY [PASSWORD] ‘password’]
Ex)
- 클라이언트가 서버와 같은 호스트에서 접근할 수 있는 사용자
‘test_user’를 암호가 ‘test_pwd’가 되도록 생성하시오.
사용자 : 추가
사용자 : 삭제
• 사용자 삭제 : DROP USER
o http://dev.mysql.com/doc/refman/5.1/en/drop-user.html o DROP USER ‘user_name’@’host_name’;
Ex)
- 앞선 예에서 생성한 test_user2를 제거 하시오.
사용자 : 테이블
• 사용자 테이블은 mysql DB 에 존재
• 사용자의 정보와 기본 권한 에 대해 저장
• use mysql 후 desc user; 를
입력해 보자.
사용자 : 테이블
• test_user 사용자의 정보 출력
사용자 : 권한 부여
• 사용자를 생성하였으니 이제 생성된 사용자에게 DB 자원에 대해 권 한을 부여해 보자.
• 앞서 설명한 권한들을 주는 과정이다.
• http://dev.mysql.com/doc/refman/5.1/en/grant.html
GRANT priv_type [(column_list)] [, priv_type [(column_list)]] ...
ON [object_type] priv_level
TO user_specification [, user_specification] ...
[REQUIRE {NONE | ssl_option [[AND] ssl_option] ...}]
[WITH with_option ...]
object_type
TABLE | FUNCTION | PROCEDURE priv_level:
* | *.* | db_name.* | db_name.tbl_name | tbl_name db_name.routine_name
user_specification
user [IDENTIFIED BY [PASSWORD] 'password']
사용자 : 권한부여
Privilege Meaning Privilege Meaning
ALL [PRIVILEGES] Grant all privileges at specified access le vel except GRANT OPTION
INSERT Enable use of INSERT
ALTER Enable use of ALTER TABLE LOCK TABLES Enable use of LOCK TABLES on tables for which you have the SELECT privilege ALTER ROUTINE Enable stored routines to be altered or d
ropped
PROCESS Enable the user to see all processes with S HOW PROCESSLIST
CREATE Enable database and table creation REFERENCES Not implemented
CREATE ROUTINE Enable stored routine creation RELOAD Enable use of FLUSH operations CREATE TEMPORARY
TABLES
Enable use of CREATE TEMPORARY T ABLE
REPLICATION CLIE NT
Enable the user to ask where master or sla ve servers are
CREATE USER Enable use of CREATE USER, DROP U SER, RENAME USER, and REVOKE A LL PRIVILEGES
REPLICATION SLAV E
Enable replication slaves to read binary log events from the master
CREATE VIEW Enable views to be created or altered SELECT Enable use of SELECT
DELETE Enable use of DELETE SHOW DATABASES Enable SHOW DATABASES to show all da tabases
DROP Enable databases, tables, and views to be dropped
SHOW VIEW Enable use of SHOW CREATE VIEW
EVENT Enable use of events for the Event Sche duler
SHUTDOWN Enable use of mysqladmin shutdown
EXECUTE Enable the user to execute stored routin es
SUPER Enable use of other administrative operatio ns such as CHANGE MASTER TO, KILL, P URGE BINARY LOGS, SET GLOBAL, an d mysqladmin debugcommand
FILE Enable the user to cause the server to re ad or write files
TRIGGER Enable trigger operations