Skip to content

Instantly share code, notes, and snippets.

@harveyqing
Last active August 29, 2015 13:57
Show Gist options
  • Save harveyqing/9559440 to your computer and use it in GitHub Desktop.
Save harveyqing/9559440 to your computer and use it in GitHub Desktop.
A description of how to dump & backup mysql data in CLI.
* Export a whole database:
Syntax:
mysqldump -u username -p [pwd] DBname > /path/to/backup
* Export a table in a specified database:
Syntax:
mysqldump -u username -p [pwd] DBname table_name > /path/to/backup
* Export a database structure (without data):
Syntax:
mysqldump -u username -p [pwd] -d --add-drop-table DBname > /path/to/backup
: arg `-d` : without data
: option `--add-drop-table` :add `drop table...` statement before `create`
* Import a database:
Syntax:
mysql> use DBname;
mysql> source /path/to/backup;
Syntax:
mysql -D DBname < /path/to/backup;
* Import data to a table:
Syntax:
load data infile "/path/to/data" into table table_name;
or
load data infile "/path/to/data" into table DBname.table_name;
- note:
text data show follow some formats: fields are seperated by `tab`, `null` is replaced by character `n`.
* Export data to a file:
Syntax:
mysql> select * from DBname.table_name into outfile "/path/to/file";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment