Skip to content

Instantly share code, notes, and snippets.

@yeiichi
Last active August 29, 2022 04:45
Show Gist options
  • Save yeiichi/d1f2986215f917b553ebb4487af4ee7a to your computer and use it in GitHub Desktop.
Save yeiichi/d1f2986215f917b553ebb4487af4ee7a to your computer and use it in GitHub Desktop.
/* CREATE */
CREATE DATABASE IF NOT EXISTS db_name
CHARACTER SET utf8mb4
COLLATE utf8mb4_0900_ai_ci;
-- https://dev.mysql.com/doc/refman/8.0/en/charset-mysql.html
CREATE TABLE IF NOT EXISTS tbl_name (
id SERIAL,
col_name FLOAT(length),
col_name CHAR(length),
col_name VARCHAR(length),
col_name TEXT,
PRIMARY KEY(id)
);
-- https://dba.stackexchange.com/a/48758/238206
SHOW GLOBAL VARIABLES LIKE 'local_infile';
SET GLOBAL local_infile = 'ON';
SHOW GLOBAL VARIABLES LIKE 'local_infile';
LOAD DATA LOCAL INFILE 'foobar.csv'
INTO TABLE foobar
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
IGNORE 1 LINES
;
INSERT INTO tbl_name (col_name,...)
VALUES ({expr | DEFAULT},...);
/* READ */
/* UPDATE */
UPDATE table_name
SET col_1 = 3.14, col_2 = 2.718
WHERE id = 42;
/* DELETE */
/* MISC */
-- https://hevodata.com/learn/mysql-export-to-csv/
/* If your MySQL server has been started with –secure-file-priv option, you must use:
This command will show you the directory that has been configured.
You can only store your output file in this directory. */
SHOW VARIABLES LIKE "secure_file_priv"
-- FK
ALTER TABLE table_name
DROP CONSTRAINT foobar_ibfk_1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment