주석처리
# CREATE DATABASE <database name>;
/*
CREATE DATABASE <database name>;
*/
Database
생성
CREATE DATABASE <database name>;
삭제
DROP DATABASE <database name>;
선택
USE <database name>;
모든 Database 확인
SHOW DATABASES;
User
생성
CREATE USER 'testuser'@'localhost' identified by 'password';
삭제
DROP user "testuser"@"localhost";
권한 승인
- 특정 Database에 모든 권한을 특정 user에게 승인
grant all PRIVILEGES on .\* to userid@localhost identified by 'password';
- 특정 Database의 특정 Table에 모든 권한을 특정 user에게 승인
grant all PRIVILEGES on .\* to userid@localhost identified by 'password';
- 특정 Database의 특정 Table에 select, insert 권한을 특정 user에게 승인
grant select,insert on . to userid@localhost identified by 'password';
권한 확인
show grants for "test"@"localhost";
권한 삭제
- 특정 Database에 모든 권한을 특정 user에게서 삭제
REVOKE all on .\* from userid@localhost;
- 특정 Database의 Table에 모든 권한을 특정 user에게서 삭제
REVOKE all on .\* from userid@localhost;
권한 변경적용
FLUSH PRIVILEGES;
Table
생성
CREATE TABLE <table name>(
id int(11) not null auto_increment,
name varchar(10) not null,
email varchar(30),
primary key(id),
index name_index(name(10))
);
- name 필드를 name_index라는 이름으로 인덱스합니다.
삭제
Drop TABLE <table name>;
컬럼 확인
SHOW COLUMNS FROM <table name>;
SHOW FULL COLUMNS FROM <table name>;
모든 테이블 확인
SHOW TABLES;
Data
추가
INSERT INTO <table name>(<column name>, email) VALUES("sample", "sample@sample.com");
삭제
DELETE FROM <tablename> WHERE id = 0;
DELETE FROM <tablename>;
- TRUNCATE와 비슷하지만 다릅니다. → 나중에 정리
수정
UPDATE SET email='example@gmail.com' WHERE name='example';
선택
SELECT [* | <column> <column>] FROM WHERE <column>='example';