MySQL 命令行工具之 mysqldump 深入研究(6)

--max-allowed-packet=#  The maximum packet length to send to or receive from server.
  --net-buffer-length=#      The buffer size for TCP/IP and socket communication.

3)这几个选项指定 登录的用户名,密码,mysqld IP地址,端口,连接使用的协议等等。

一般常用的是 -h192.168.2.xx -uxxx -p ,如果mysqld默认端口不是3306,则需要使用 -Pxxx 指定端口.

--max-allowed-packet 我们一般配置在my.cnf中。--net-buffer-length 是为了优化网络连接的socket buffer.

使用示例: mysqldump -h192.168.1.20 -uxxx -p -P3057

3. mysqldump 选择备份内容的相关选项

我们可以选择备份所有数据库,某几个数据库,某一个数据库,某一个数据库中的某几个表,某一个数据库中的一个表;

可以选择是否备份 存储过程和函数,触发器,调度事件.

1)选择导出的数据库 和 表:

-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.

database [tables]  导出数据库 database 中的表结构 和 表中数据;

2)选择是否导出 建库,建表语句,是否导出 表中的数据:

-n, --no-create-db  Suppress the CREATE DATABASE ... IF NOT EXISTS statement that normally is output for each dumped database if 

--all-databases or --databases is given. (不导出建库语句: CREATE DATABASE,也就是不导库结构)

-t, --no-create-info Don't write table creation info. (不导出建表语句)

-d, --no-data        No row information. (不导出数据,有时我们仅仅需要导出表结构,也就是建表语句就行了)

3)选择是否导出 存储过程和函数,触发器,调度事件:

-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.)

4)指定不导出 某个库的某个表:

--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. (在导出数据库时,排除某个或者某几个表不导出)

5) 按照 where 条件导出:

-w, --where='where_condition' Dump only selected records. Quotes are mandatory.

6)使用示例:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/38784cef23fd1f12966185d2cc51010a.html