2018.02.07-20일차 DB
* 강의 정리 내용 :
* phpmyadmin 프로그램
1> 개념
- 웹 환경에서 MySQL 프로그램의 기능을 거의 지원하는 MySQL 웹 관리 매니저 프로그램
- 웹 환경에서 MySQL의 데이터베이스, 테이블, 필드, 레코드 등을 쉽게 관리할 수 있음
2> 준비물
// 리눅스 웹 브라우저에서..,
http://www.phpmyadmin.net -> phpmyadmin 프로그램을 다운로드 받을 사이트!
버전 : 4.0.10.20~ tar.gz
# ls
# cd 다운로드
# ls
#
# tar xvzf php* -C /web/server/apache/
# cd /web/server/apache/
# ls
# mv php* phpmyadmin
# ls
# systemctl restart httpd.service
// 웹 브라우저 검색창에 다음과 같이 치기
192.168.46.90/phpmyadmin
// index.php라는걸 알려줘야..,
// apache 환경 설정 파일
/etc/httpd/conf/httpd.conf
168줄 :DirectoryIndex 항목은 기본적으로 index.html 만 지정
phpmyadmin 프로그램을 설치하는 과정에서 index.php가 필요하므로 위 항목에다가 추가를 해야함.
왼쪽부터 우선순위 임
# vi /etc/httpd/conf/httpd.conf
169 DirectoryIndex index.html index.php ; index.html이 없으면, index.php가 우선순위가 됨!
:wq
# systemctl restart httpd.service
F5 // 코딩 소스가 뜨는데, 아직은 뭔가가 부족..,
// php 패키지 추가
# yum -y install --skip-broken php-*
# systemctl restart httpd.service
bank / itbank
실행
1> 개념
ㆍDatabase : 여러가지 공동의 업무에 필요한 데이터를 유기적으로 결합하여 저장한 집합체
ㆍDBMS(DataBase Management System)
- 데이타베이스 관리자라고도 불림
- 다수의 컴퓨터 사용자들의 데이터베이스 안에 데이터들을 기록하거나 접근할 수 있게 해주는 프로그램
- 목적은 데이터베이스 내의 정보 검색, 저장, 효율적인 환경을 제공함
- RDBMS(Relation(관계형) DBMS)는 표준화되어 사용자 및 프로그램 인터페이스를 제공함
ㆍSQL(Structured Query Language : 구조화 질의 언어)
- 종류로는 Oracle, MySQL, MariaDB 등이 있음
ㆍMySQL(CentOS 6.x 까지)
- SQL문을 사용하는 오픈 소스의 RDBMS
- 매우 빠르고 유연하고 사용하기 쉬운 장점
- 다중 사용자, 다중 스레드를 지원하고 C, C++, Java, PHP 스크립트 언어를 위한 응용 프로그램 인터페이스를
제공함
- 유닉스, 윈도우즈 서버, 리눅스에서도 사용함
ㆍMariaDB
- SQL문을 사용하는 오픈 소스의 RDBMS
- MySQL과 동일한 소스 코드를 기반으로 GPL v2 라이선스를 따름
- Oracle 소유의 현재 불확실한 MySQL의 라이선스 상태에서 반발하여 만들어짐
- MySQL 5.5 까지는 소스 코드가 거의 동일함
2> 실습
패키지명은 mariadb로 시작함
mariadb.service를 재시작
mariadb 접속방법
# mysql -u root -p mysql
mysql은 명령어
-u은 접속할 사용가 계정명
root는 관리자
-p는 접속할 사용자 계정의 비밀번호
mysql은 사용할 데이터베이스명
비밀번호는 처음이기 때문에 null 값이다.
mariadb 버전과 현재 날짜
select version(), current_date;
참고로 명령어 뒤에는 반드시 ; (세미콜론)을 입력!
① 첫번째 명령어
> show
show는 데이터베이스 목록을 출력
show는 테이블 목록을 출력
show는 데이터베이스와 테이블에서 사용 가능한 명령어
사용형식
> show databases;
> show tables;
table (> show tables;)
table은 관계형 데이터베이스에서 세로줄과 가로줄의 모델을 이용하여
정렬된 데이터 집합(값)의 모임
db table은 데이터베이스와 사용자를 연동(연결)시켜주는 테이블
user table은 사용자 생성 테이블 사용자는 user table에서만 생성할 수 있음
② 두번째 명령어
use
use는 데이터베이스를 변경
use는 데이터베이스에서 사용
사용형식
> use 데이터베이스;
③ 세번째 명령어
describe
describe는 접속한 데이터베이스의 테이블에 대한 스키마 정보를 확인
describe는 테이블에서 사용
사용형식
> describe 테이블;
> desc 테이블;
> explain 테이블;
스키마(schema)
- 데이터베이스를 구성하는 레코드의 크기, 키(key)의 정의, 레코드의 관계, 검색 방법 등을 정의
- 데이터베이스의 구조와 제약 조건에 전반적인 명세를 기술
④ 네번째 명령어
create
create는 데이터베이스를 생성
create는 테이블을 생성
create는 데이터베이스와 테이블에서 사용
사용형식(데이터베이스 생성)
> create database 데이터베이스명;
사용형식(테이블 생성)
> create table 테이블 (필드 필드타입 (길이));
→ 하나의 필드를 생성하면서 테이블 생성
> create table 테이블 (필드1 필드타입 (길이) 필드2 필드타입(길이), ...);
→ 여러개의 필드를 생성하면서 테이블 생성
field는 항목.
- 파일을 구성하는 기억 영역의 최소 단위로 특정한 종류의 데이터를 포함한 것
(ex. 재고파일의 품명번호, 색 코드)
⑤ 다섯번째 명령어
drop // 개념적으로 큼
drop은 데이터베이스를 삭제
drop은 테이블을 삭제
drop은 데이터베이스와 테이블에서 사용
사용형식(데이터베이스 삭제)
> drop database 데이터베이스명;
사용형식(테이블 삭제)
> drop table 테이블;
⑥ 여섯번째 명령어
select
select는 접속한 데이터베이스에 테이블의 필드 안에 레코드를 조회(확인)
select는 테이블에서 상숑
레코드(record)는 데이터(값)로써 최소한의 단위
사용형식
> select *(모든필드) from 테이블;
→ 테이블의 모든 필드의 레코드를 조회
> select 필드1, 필드2, 필드3, ... from 테이블;
→ 테이블에 지정한 필드의 레코드를 조회
⑦ 일곱번쨰 명령어
update
update는 접속한 데이터베이스에 테이블의 필드 안에 레코드 수정
update는 테이블에서 사용
사용형식
> update 테이블 set 필드='값';
→ 테이블의 수정할 필드 안에 값을 전부 수정
> update 테이블 set 필드='값' where(조건) 필드='값';
→ 테이블의 수정할 필드 안에 값을 조건은 건 필드 쪽에만 수정
(참고로 password 필드 작업시 password()를 사용해야 암호화로 할 수 있음)
ex) password=password('값')
⑧ 여덟번째 명령어
delete // << drop보다 작은 개념
delete는 접속한 데이터베이스에 테이블의 필드 안에 레코드를 삭제
delete는 테이블에서 사용
사용형식
> delete from 테이블;
→ 테이블의 필드 안에 모든 레코드를 삭제 (지금 user 테이블에서 쓰면 망..,)
> delete from 테이블 where(조건) 필드='값';
→ 테이블에 조건을 건 필드 안에 레코드만 삭제
⑨ 아홉번째 명령어
insert
insert는 접속한 데이터베이스에 테이블의 필드 안에 레코드를 삽입
insert는 테이블에서 사용
사용형식
> insert into 테이블 (필드) value ('값');
→ 테이블의 필드 안에 레코드 하나 삽입
> insert into 테이블 (필드1, 필드2, 필드3, ... ) values ('값1', '값2', '값3',... );
→ 테이블의 여러 필드 안에 여러 레코드 삽입
⑩ 열번째 명령어
alter
alter는 접속한 데이터베이스에 테이블의 필드를 수정, 추가, 삭제 등
alter는 테이블에서 사용
사용형식(필드타입 수정)
> alter table 테이블 modify 필드 필드타입(길이);
사용형식(필드명 변경)
> alter table 테이블 change 기존필드 변경필드 필드타입(길이);
사용형식(필드 추가 : 맨 마지막에)
> alter table 테이블 add 필드 필드타입(길이);
사용형식(필드 추가 : a필드와 b필드 사이에)
> alter table 테이블 add 필드 필드타입(길이) after a필드;
사용형식(필드 추가 : 맨 앞에)
> alter table 테이블 add 필드 필드타입(길이) first;
사용형식(필드 삭제)
> alter table 테이블 drop 필드;
cf) 기타 명령어
> help
리눅스 colsole의 clear == Ctrl + L
> 중간에 입력 잘못 했을 시, \c
[실습] db ↔ 사용자 연결
현재 kgitbank db가 있고, 사용자 bank 추가
사용자 생성
> insert into user (host, user, password) values ('localhost', '사용자', password('값'));
사용자와 데이터베이스 연동(연결)
> insert into db values ('localhost', '데이터베이스', '사용자', 'y'*19);
mariadb에서 작업한 설정을 적용하기 위해서 아래와 같은 방법을 사용
1) mariadb 프로그램에서 자체 적용 방법
flush privileges;
2) mariadb 프로그램 종료 후 적용방법
systemctl restart mariadb.service
// mariadb 실습
[root@junga ~]# yum -y install mariadb*
...
Complete!
[root@junga ~]# systemctl restart mariadb.service
[root@junga ~]#
[root@junga ~]# mysql -u root -p mysql
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [mysql]> select version(), current_date;
+----------------+--------------+
| version() | current_date |
+----------------+--------------+
| 5.5.56-MariaDB | 2018-02-06 |
+----------------+--------------+
1 row in set (0.00 sec)
MariaDB [mysql]>
MariaDB [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.00 sec)
> exit
// 2018.02.07
[root@junga ~]# systemctl restart mariadb.service
[root@junga ~]#
[root@junga ~]# mysql -u root -p mysql
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [mysql]>
MariaDB [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [mysql]> use test;
Database changed
MariaDB [test]>
MariaDB [test]> show tables;
Empty set (0.00 sec)
MariaDB [test]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> exit
Bye
[root@junga ~]# use mysql;
bash: use: 명령을 찾을 수 없습니다...
[root@junga ~]#
[root@junga ~]# mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]>
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.00 sec)
MariaDB [mysql]> describe db;
+-----------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+---------------+------+-----+---------+-------+
| Host | char(60) | NO | PRI | | |
| Db | char(64) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
+-----------------------+---------------+------+-----+---------+-------+
22 rows in set (0.10 sec)
MariaDB [mysql]>
MariaDB [mysql]> desc user
-> ;
+------------------------+-----------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+---------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Create_user_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
| Create_tablespace_priv | enum('N','Y') | NO | | N | |
| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) | NO | | 0 | |
| plugin | char(64) | NO | | | |
| authentication_string | text | NO | | NULL | |
+------------------------+-----------------------------------+------+-----+---------+-------+
42 rows in set (0.00 sec)
MariaDB [mysql]> show database
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'database' at line 1
MariaDB [mysql]>
MariaDB [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [mysql]> create database testdatabase;
Query OK, 1 row affected (0.00 sec)
MariaDB [mysql]> create database kgitbank;
Query OK, 1 row affected (0.00 sec)
MariaDB [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| kgitbank |
| mysql |
| performance_schema |
| test |
| testdatabase |
+--------------------+
6 rows in set (0.00 sec)
MariaDB [mysql]>
// 현재 작업공간은 mysql임!
MariaDB [mysql]>
MariaDB [mysql]> create table testtable;
ERROR 1113 (42000): A table must have at least 1 column
MariaDB [mysql]>
MariaDB [mysql]> help
General information about MariaDB can be found at
http://mariadb.org
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for `help'.
clear (\c) Clear the current input statement.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mysql server, display result vertically.
exit (\q) Exit mysql. Same as quit.
go (\g) Send command to mysql server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mysql prompt.
quit (\q) Quit mysql.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (\!) Execute a system shell command.
tee (\T) Set outfile [to_outfile]. Append everything into given outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
For server side help, type 'help contents'
MariaDB [mysql]>
MariaDB [mysql]> create table testtable;
ERROR 1113 (42000): A table must have at least 1 column
MariaDB [mysql]>
MariaDB [mysql]> create table testtable (number int(2),
-> name char(20));
Query OK, 0 rows affected (0.11 sec)
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| testtable |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
25 rows in set (0.00 sec)
MariaDB [mysql]> desc testtable;
+--------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| number | int(2) | YES | | NULL | |
| name | char(20) | YES | | NULL | |
+--------+----------+------+-----+---------+-------+
2 rows in set (0.00 sec)
MariaDB [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| kgitbank |
| mysql |
| performance_schema |
| test |
| testdatabase |
+--------------------+
6 rows in set (0.00 sec)
MariaDB [mysql]> drop database testdatabase;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| kgitbank |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [mysql]>
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| testtable |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
25 rows in set (0.00 sec)
MariaDB [mysql]>
MariaDB [mysql]> drop table testtable;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.00 sec)
MariaDB [mysql]>
MariaDB [mysql]> select * from user;
+----------------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin | authentication_string |
+----------------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+
| localhost | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | | |
| junga.kgitbank | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | | |
| 127.0.0.1 | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | | |
| ::1 | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | | |
| localhost | | | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 | | |
| junga.kgitbank | | | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 | | |
+----------------+------+----------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+--------+-----------------------+
6 rows in set (0.03 sec)
MariaDB [mysql]> select host, user, password from user;
+----------------+------+----------+
| host | user | password |
+----------------+------+----------+
| localhost | root | |
| junga.kgitbank | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| junga.kgitbank | | |
+----------------+------+----------+
6 rows in set (0.17 sec)
MariaDB [mysql]> select * from db;
+------+---------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+
| Host | Db | User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Create_tmp_table_priv | Lock_tables_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Execute_priv | Event_priv | Trigger_priv |
+------+---------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+
| % | test | | Y | Y | Y | Y | Y | Y | N | Y | Y | Y | Y | Y | Y | Y | Y | N | N | Y | Y |
| % | test\_% | | Y | Y | Y | Y | Y | Y | N | Y | Y | Y | Y | Y | Y | Y | Y | N | N | Y | Y |
+------+---------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+------------+--------------+
2 rows in set (0.05 sec)
MariaDB [mysql]> select host, db, user from db;
+------+---------+------+
| host | db | user |
+------+---------+------+
| % | test | |
| % | test\_% | |
+------+---------+------+
2 rows in set (0.00 sec)
MariaDB [mysql]>
MariaDB [mysql]> update user set password='itbank';
Query OK, 6 rows affected (0.07 sec)
Rows matched: 6 Changed: 6 Warnings: 0
MariaDB [mysql]> select host, user, password from user;
+----------------+------+----------+
| host | user | password |
+----------------+------+----------+
| localhost | root | itbank |
| junga.kgitbank | root | itbank |
| 127.0.0.1 | root | itbank |
| ::1 | root | itbank |
| localhost | | itbank |
| junga.kgitbank | | itbank |
+----------------+------+----------+
6 rows in set (0.00 sec)
MariaDB [mysql]> update user set password=password('itbank') where user='root';
Query OK, 4 rows affected (0.03 sec)
Rows matched: 4 Changed: 4 Warnings: 0
MariaDB [mysql]> select host, user, password from user;
+----------------+------+-------------------------------------------+
| host | user | password |
+----------------+------+-------------------------------------------+
| localhost | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| junga.kgitbank | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| 127.0.0.1 | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| ::1 | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| localhost | | itbank |
| junga.kgitbank | | itbank |
+----------------+------+-------------------------------------------+
6 rows in set (0.00 sec)
MariaDB [mysql]> delete from user where user='' \c
MariaDB [mysql]>
MariaDB [mysql]> delete from user where password='itbank';
Query OK, 2 rows affected (0.00 sec)
MariaDB [mysql]> select host, user, password from user;
+----------------+------+-------------------------------------------+
| host | user | password |
+----------------+------+-------------------------------------------+
| localhost | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| junga.kgitbank | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| 127.0.0.1 | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| ::1 | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
+----------------+------+-------------------------------------------+
4 rows in set (0.00 sec)
MariaDB [mysql]> select host, db, user from db;
+------+---------+------+
| host | db | user |
+------+---------+------+
| % | test | |
| % | test\_% | |
+------+---------+------+
2 rows in set (0.00 sec)
MariaDB [mysql]>
MariaDB [mysql]> delete from db where user='' \c // or
MariaDB [mysql]>
MariaDB [mysql]> delete from db \c // or
MariaDB [mysql]>
MariaDB [mysql]> delete from db where host='%' \c // or
MariaDB [mysql]>
MariaDB [mysql]> delete from db where db='test' or db='test\_%';
Query OK, 2 row affected (0.00 sec)
MariaDB [mysql]>
MariaDB [mysql]> select host, db, user from db;
Empty set (0.00 sec)
MariaDB [mysql]> select host, user, password from user;
+----------------+------+-------------------------------------------+
| host | user | password |
+----------------+------+-------------------------------------------+
| localhost | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| junga.kgitbank | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| 127.0.0.1 | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| ::1 | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
+----------------+------+-------------------------------------------+
4 rows in set (0.00 sec)
MariaDB [mysql]> insert into user (host, user, password) values
-> ('localhost', 'bank', password('itbank'));
Query OK, 1 row affected, 4 warnings (0.00 sec)
MariaDB [mysql]> select host, user, password from user;
+----------------+------+-------------------------------------------+
| host | user | password |
+----------------+------+-------------------------------------------+
| localhost | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| junga.kgitbank | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| 127.0.0.1 | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| ::1 | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| localhost | bank | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
+----------------+------+-------------------------------------------+
5 rows in set (0.01 sec)
// db ↔ 사용자 연결
MariaDB [mysql]> insert into db values('localhost', 'kgitbank',
-> 'bank','y','y','y','y','y','y','y','y','y','y',
-> 'y','y','y','y','y','y','y','y','y');
Query OK, 1 row affected (0.00 sec)
MariaDB [mysql]> select host, db, user from db;
+-----------+----------+------+
| host | db | user |
+-----------+----------+------+
| localhost | kgitbank | bank |
+-----------+----------+------+
1 row in set (0.00 sec)
MariaDB [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| kgitbank |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [mysql]> select host, user, password from user;
+----------------+------+-------------------------------------------+
| host | user | password |
+----------------+------+-------------------------------------------+
| localhost | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| junga.kgitbank | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| 127.0.0.1 | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| ::1 | root | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
| localhost | bank | *E1B74369B47EB3AD8EF858144E1A0364E3259329 |
+----------------+------+-------------------------------------------+
5 rows in set (0.00 sec)
MariaDB [mysql]> select host, db, user from db;
+-----------+----------+------+
| host | db | user |
+-----------+----------+------+
| localhost | kgitbank | bank |
+-----------+----------+------+
1 row in set (0.00 sec)
MariaDB [mysql]>
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.03 sec)
MariaDB [mysql]> quit
Bye
[root@junga ~]#
[root@junga ~]# mysql -u bank -p kgitbank
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [kgitbank]>
MariaDB [kgitbank]> show databases; // 일반 사용자는 자신이 만든 table 밖에 못 봄
+--------------------+
| Database |
+--------------------+
| information_schema |
| kgitbank |
+--------------------+
2 rows in set (0.00 sec)
MariaDB [kgitbank]> create table kangsabu (number int(2),
-> subject char(15), name char(20));
Query OK, 0 rows affected (0.04 sec)
MariaDB [kgitbank]> describe kangsabu;
+---------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+----------+------+-----+---------+-------+
| number | int(2) | YES | | NULL | |
| subject | char(15) | YES | | NULL | |
| name | char(20) | YES | | NULL | |
+---------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)
MariaDB [kgitbank]> select * from kangsabu;
Empty set (0.00 sec)
MariaDB [kgitbank]> insert into kangsabu(number, subject, name)
-> values ('1','c_lang','kokildong');
Query OK, 1 row affected (0.00 sec)
MariaDB [kgitbank]> select number, subject, name from kangsabu;
+--------+---------+-----------+
| number | subject | name |
+--------+---------+-----------+
| 1 | c_lang | kokildong |
+--------+---------+-----------+
1 row in set (0.00 sec)
// 필드타입 수정
MariaDB [kgitbank]> alter table kangsabu modify subject varchar(15);
Query OK, 1 row affected (0.03 sec)
Records: 1 Duplicates: 0 Warnings: 0
MariaDB [kgitbank]> desc kangsabu;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| number | int(2) | YES | | NULL | |
| subject | varchar(15) | YES | | NULL | |
| name | char(20) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
// 필드명 변경
MariaDB [kgitbank]> alter table kangsabu change number num int(2);
Query OK, 1 row affected (0.01 sec)
Records: 1 Duplicates: 0 Warnings: 0
MariaDB [kgitbank]> desc kangsabu;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| num | int(2) | YES | | NULL | |
| subject | varchar(15) | YES | | NULL | |
| name | char(20) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
// 필드 추가 (맨 마지막에)
MariaDB [kgitbank]> alter table kangsabu add age int(2);
Query OK, 1 row affected (0.04 sec)
Records: 1 Duplicates: 0 Warnings: 0
MariaDB [kgitbank]> desc kangsabu;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| num | int(2) | YES | | NULL | |
| subject | varchar(15) | YES | | NULL | |
| name | char(20) | YES | | NULL | |
| age | int(2) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
// 필드 추가 (중간에)
MariaDB [kgitbank]> alter table kangsabu add bloodtype char(3) after subject;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
MariaDB [kgitbank]> desc kangsabu;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| num | int(2) | YES | | NULL | |
| subject | varchar(15) | YES | | NULL | |
| bloodtype | char(3) | YES | | NULL | |
| name | char(20) | YES | | NULL | |
| age | int(2) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
// 필드 추가 (맨 앞에)
MariaDB [kgitbank]> alter table kangsabu add address char(20) first;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
MariaDB [kgitbank]>
MariaDB [kgitbank]> desc kangsabu;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| address | char(20) | YES | | NULL | |
| num | int(2) | YES | | NULL | |
| subject | varchar(15) | YES | | NULL | |
| bloodtype | char(3) | YES | | NULL | |
| name | char(20) | YES | | NULL | |
| age | int(2) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
// 필드 삭제
MariaDB [kgitbank]> alter table kangsabu drop bloodtype;
Query OK, 1 row affected (0.05 sec)
Records: 1 Duplicates: 0 Warnings: 0
MariaDB [kgitbank]> desc kangsabu;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| address | char(20) | YES | | NULL | |
| num | int(2) | YES | | NULL | |
| subject | varchar(15) | YES | | NULL | |
| name | char(20) | YES | | NULL | |
| age | int(2) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)