mysqldump进行mysql备份
示例
导出远程数据库
mysqldump -uroot -pxxx -hxxx > xxx.sql
只导出结构(表,视图,函数)
mysqldump -uroot -pxxx -d -R dataname > xxx.sql
只导出数据
mysqldump -uroot -pxxx -n dataname > xxx.sql
导出所有的表和数据(包含视图,函数)
mysqldump -uroot -pxxx -a -R dataname > xxx.sql
只导出某个表的shuj
mysqldump -uroot -pxxx dataname table > xxx.sql
mysqldump 命令详解
我们可以选择备份所有数据库,某几个数据库,某一个数据库,某一个数据库中的某几个表,某一个数据库中的一个表;
可以选择是否备份 存储过程和函数,触发器,调度事件。
-
选择导出的数据库 和 表:
-a, --all-databases
Dump all the databases. This will be same as --databases with all databases selected.
-B, --databases
Dump several databases. Note the difference in usage; in this case no tables are given. All name arguments are regarded as database names. 'USE db_name;' will be included in the output.
-
选择是否导出 建库,建表语句,是否导出 表中的数据: -n, --no-create-db
Suppress the CREATE DATABASE ... IF NOT EXISTS statement that normally is output for each dumped database if
-t, --no-create-info
Don't write table creation info. (不导出建表语句)
-d, --no-data
No row information. (不导出数据,有时我们仅仅需要导出表结构,也就是建表语句就行了)
-
选择是否导出 存储过程和函数,触发器,调度事件:
-R, --routines
Dump stored routines (functions and procedures). (导出存储过程和函数)
--triggers
Dump triggers for each dumped table. (Defaults to on; use --skip-triggers to disable.) (导出触发器)
--skip-triggers
不导出触发器
-E, --events
Dump events. 导出调度事件(根据备份的目的进行选择,如果是搭建slave,那么就不要导出events.)
-
指定不导出 某个库的某个表: --ignore-table=name
Do not dump the specified table. To specify more than one table to ignore, use the directive multiple times, once for each table. Each table must be specified with both database and table names, e.g., --ignore-table=database.table. (在导出数据库时,排除某个或者某几个表不导出)
-
按照 where 条件导出: -w, --where='where_condition'