mysql dump 命令_mysqldump 命令

mysqldump是用来导出mysql的数据的;

--all-databases: 可以导出所有的DB, 但不包括information_schema, mysql database里也只有少量的信息;

-t, --no-create-info: 不包含建表的信息;

-n, --no-create-db: Suppress the CREATE DATABASE ... IF EXISTS statement that

normally is output for each dumped database if  --all-databases or --databases is given.

-d, --no-data: 不包含表中的数据;

-S, --socket=name: 指定特定的socket file;

-q,--quick: 带上这个参数会让mysqldump在导出数据的时候不要缓存,可以更快一些,但是经过测试提高的量不大;

-w, --where="": 用来按条件导出表内容

--triggers: 为每个表导出triggers

--tz-utc: 在导出文件中带上timezone, 当表中有timestamp字段的时候有用;

--dump-date:Put a dump date to the end of the output

--single-transaction: 如果要导出多个表,那么加上这个参数会保证所有这些导出在一个transaction里完成。尽管从dump出的文件里看不出来是一时锁定了所有的表,但是在测试的时候能够很明显感觉出来,确实是这个database下的所有表都给lock for write了. 不过这个参数如果带上的话也是够危险的,如果有其他任何一张表被锁定了,这条语句就会执行不下去,因为他不能一把锁住所有的表嘛,整个过程只有等待了.

那--no-create-info --no-data一起指定了呢? 会导出database下的trigger, procedure等信息;

下面举几个例子:

time -p mysqldump -t -n -u root -ppass -B webdb -S /home/oracle/mysql/run/mysql.sock > /home/oracle/webdb_orion.sql

time -p mysqldump -t -n -u root -ppass webdb usertype -S /home/oracle/mysql/run/mysql.sock > /home/oracle/usertype2.sql

在这里加上time -p是用来打印mysqldump执行的时间的;

经过多次测试: 在32G内存,16 CPU(2.4G)的机子上,导出1015M的数据,只花了96.49s;

除了mysqldump之外,还可以使用select into outfile '' 语句来导出数据。导入select into outfile对应记录的方法是: load data infile '' into table table_name;--导入select .. into outfile的结果文件:root@webdb 02:18:13>truncate table usertype;Query OK, 0 rows affected (0.19 sec)root@webdb 02:18:45>load data infile '/home/oracle/mysql/usertype_outfile.sql' into table usertype;Query OK, 2362578 rows affected (43.29 sec)Records: 2362578Deleted: 0Skipped: 0Warnings: 0;--导入mysqldump结果文件:root@webdb 02:18:13>truncate table usertype;Query OK, 0 rows affected (0.19 sec)[root@dbmysql01 mysql]# time -p mysql -u root -ppass webdb -e 'source usertype2.sql'real 49.55user 5.43sys 0.14--导入的记录数root@webdb 02:37:43>select count(*) from usertype;+----------+| count(*) |+----------+|2362578 |+----------+

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值