Skip to main content

MySQL


CMD

Execute .sql

mysql <db_name> < </path/sql_file>

or

SOURCE </path/sql_file>

Table

CREATE TABLE

SHOW CREATE TABLE `<table>`

ALTER TABLE

ALTER TABLE
`<table>`
[<alter_option>[,<alter_option>]]
[<partition_option>[,<partition_option>]]

ALTER TABLE ADD

ALTER TABLE
`<table>`
ADD
[COLUMN] `<column>` <col_definition>
[FIRST | AFTER `<column>`]

ALTER TABLE MODIFY

ALTER TABLE
`<table>`
MODIFY
[COLUMN] `<column>` <col_definition>
[FIRST | AFTER `<column>`]

ALTER TABLE DROP

ALTER TABLE
`<table>`
DROP
[COLUMN] `<column>`

Data

INSERT

INSERT INTO
`<table>` [(<col_name>[,<col_name>])]
VALUES
(<value>[,<value>])

LOAD DATA

LOAD DATA [LOCAL] INFILE <path> INTO TABLE `<table>`
[FIELDS [TERMINATED BY '<string>'] [ENCLOSED BY '<char>']]
[LINES [STARTING BY '<string>'] [TERMINATED BY '<string>']]
[IGNORE <number> ROWS]
[(<col_name_or_user_var>[,<col_name_or_user_var>])]
[SET
col_name=<expr>]
  • LOCAL: 파일이 Client에 있는 경우
info

SELECT ... INTO OUTFILE ...명령어로 옵션에 따라 파일이 어떻게 출력되는지 확인한 후 LOAD DATA 명령어를 사용할 수도 있습니다.

UPDATE

UPDATE
`<table>`
SET
<assignment_list>
[WHERE
<where_condition>]

SELECT

SELECT
<select_expr>
[FROM
<table_references>]
[WHERE
<where_condition>]
[LIMIT
[<offset>,] <row_count>]

DELETE

DELETE FROM
`<table>`
[WHERE
<where_condition>]