분류 sql

MySQL 다루기 Cheat Sheet

컨텐츠 정보

  • 조회 586 (작성일 )

본문

Create, Drop, Alter


/* create database */
CREATE DATABASE dbName
CREATE DATABASE dbName CHARACTER SET utf8

/* drop database */
DROP DATABASE dbName

/* alter database charset */
ALTER DATABASE dbName CHARACTER SET utf8

/* or */
ALTER DATABASE dbName CHARACTER SET utf8 COLLATE utf8_general_ci

/* read database charset */
SELECT @@character_set_database, @@collation_database



Dump and Restore

- Dump


# command
mysqldump --opt -u [uname] -p [pass] [dbname] > [filename.sql]

# examples

# dump all databases to a file
mysqldump --all-databases > myFile.sql

# dump multiple databases to a file
mysqldump --databases mydb1 mydb2 > myFile.sql

# dump a single database to a file
mysqldump --databases mydb > myFile.sql

# or without --databases option
mysqldump mydb > myFile.sql



- Restore



# command
mysql -u [uname] -p [pass] [dbname] < [filename.sql]

# example

# restore myFile.sql file to the mydb database.
mysql -u root -p mydb < myFile.sql