글
MariaDB ( SQL )
MariaDB ( SQL )
1. DDL ( 데이터 정의어 )
- 데이터에 실제로 변화를 줄 수 없음
- create , drop , ...
2. DML ( 데이터 조작어 )
- 데이터에 실제로 변화를 줄 수 있음
- select , insert , delete , update , ...
3. DCL ( 데이터 제어어 )
- 권한 , 트랜잭션 , ...
- grank , invoke , ...
# systemctl status httpd <<---- httpd가 동작중인지 확인
동작중이지 않다면 # systemctl start httpd << -- httpd 동작시키기
# systemctl stop firewalld <<---- 방화벽 끄기
MariaDB 접속하기
# mysql -u root -p
password 입력
1. DB
1) DB 확인
> show databases; <<---- 세미콜론 문장(커맨드)끝을 의미
+-------------------------------+
l information_schema l < --
l mysql l < -- 사용자 정보 사용자 권한
l performance_schema l < --
+ ----------------------------- +
l test l
+-------------------------------+
2) DB 생성
> create database <db_name>;
ex) > korea DB 생성
> create database korea;
3) DB 삭제
> drop database <db_name>;
> drop database korea;
4) DB 선택
> use <db_name>;
ex) korea db 선택
> use korea;
MariaDB [(none)] > ===>>>>> MariaDB [(korea)] 로 변경
2. Table
1) Table 확인
- 전체 테이블 확인
> show tables;
- 특정 테이블 확인
> desc <table_name>;
2) Table 생성
> create table <table_name>(column , .....);
- 자료형
- int : 정수형
- float : 실수형
- char(num) : 고정 사이즈 , 문자
- varchar(num) : 가변사이즈 , 문자
- text : 제한없음 , 문자
ex) user table 생성
- name char(20)
- age int
- addr varchar(50)
- phone char(30)
- email varchar (40)
> create table user(name char(20), age int,addr varchar(50), phone char(30)
,email varchar(40));
> show table;
> desc user;
3) Table 수정
> alter table <table_name> <option>;
--- < option > ---
- column 추가 : add <col_name> <col_type>;
ex) user table에 subject(text) column 추가
> alter table user add subject text;
> desc user;
- column 변경 : modify column <col_name> <mod_col_name> <type> <option>;
- column 삭제 : drop column <col_name>;
- table 이름 변경 : rename <table_name>;
4) Table 삭제
> drop table <table_name>;
3. DATA
1) DATA 확인
- 특정 column 확인
> select <col_name>, ... from <table_name>;
- 모든 column 확인
> select * from <table_name>;
- 조건( WHERE )
> select * from <table_name> where <조건>;
ex) name이 홍길동인 데이터를 확인
> select * from user where name='홍길동';
2) DATA 입력
- 전체 데이터를 입력할때
> insert into <table_name> values(<data>,<data>,<data>,.....);
- 특정 데이터만 입력할때
> insert into <table_name>(<col_name>,<col_name>,...) values(<data>,<data>,...);
ex) user Table에 DATA 추가
입력사항 - '홍길동',10,'경기도','010-123-123','dong@naver.com','linux' -
> insert into user values('홍길동',10,'경기도','010-123-123','dong@naver.com','linux');
> select * from user;
ex) subject 가 java 인 데이터 , subject 가 C 언어 인 데이터 추가 입력
> insert into user values('ㅎㅇ',23,'서울','010-1234-5678','hihi@naver.com','C언어');
> insert into user values('ㅎㅇㅇ',24,'부산','010-3456-7898','hi@naver.com','java');
ex) subject 가 java 인 데이터를 확인
> select * from user where subject='java';
ex)
name이 ㅎㅇㅇ 인 데이터의 name, addr column 확인
> select name,addr from user where name='ㅎㅇㅇ';
ex) UNION
name이 ㅎㅇㅇ 인 데이터의 name, addr column 확인하고 subject 가 linux인 데이터의
name , age column 확인
> select name,addr from user where name='ㅎㅇㅇ' union select name,age from user where
subject='linux';
3) DATA 수정
- 모든 데이터가 모두 수정된다
> update <table_name> set <col_name>=<data>;
- 조건에 부합하는 데이터만 수정된다
> update <table_name> set <col_name>=<data> where <조건>;
ex) name이 ㅎㅇㅇ 인 데이터의 subject를 linux로 수정
> update user set subject='linux' where name='ㅎㅇㅇ'
4) DATA 삭제
- 모든 데이터 삭제
> delete from <table_name>;
- 조건에 부합하는 데이터만 삭제
> delete from <table_name> where <조건>;
'Linux > Linux (CentOS)' 카테고리의 다른 글
Network (0) | 2018.07.13 |
---|---|
방화벽 & 서비스 (0) | 2018.07.12 |
sudo 설정 & service (0) | 2018.07.10 |
네트워크설정 & ACL 권한 (0) | 2018.07.09 |
사용자 생성하기 (0) | 2018.07.08 |