mysqlhotcopy使用lock tables、flush tables和cp或scp来快速备份数据库.它是备份数据库或单个表最快的途径,完全属于物理备份,但只能用于备份MyISAM存储引擎和运行在数据库 目录所在的机器上.与mysqldump备份不同,mysqldump属于逻辑备份,备份时是执行的sql语句.使用mysqlhotcopy命令前需要 要安装相应的软件依赖包.

1.安装mysqlhotcopy所依赖的软件包(perl-DBD,DBD-mysql)

[root@tong2 ~]# yum install perl-DBD* -y

[root@tong2 ~]# wget https://cpan.metacpan.org/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.029.tar.gz

[root@tong2 ~]# tar xvf DBD-mysql-4.029.tar.gz

[root@tong2 ~]# cd DBD-mysql-4.029[root@tong2 DBD-mysql-4.029]# perl Makefile.PL

[root@tong2 DBD-mysql-4.029]# make

[root@tong2 DBD-mysql-4.029]# make install

[root@tong2 DBD-mysql-4.029]# echo $?

0

[root@tong2 DBD-mysql-4.029]# cd

[root@tong2 ~]#

2.查看mysqlhotcopy的帮助信息

[root@tong2 ~]# vim /usr/my.cnf    --在配置文件中添加如下参数

[mysqlhotcopy]

interactive-timeout

host=localhost

user=root

password=system

port=3306

[root@tong2 ~]# /etc/init.d/mysql restart      --重启服务

Shutting down MySQL.. SUCCESS!

Starting MySQL. SUCCESS!

[root@tong2 ~]# mysqlhotcopy  --helpWarning: /usr/bin/mysqlhotcopy is deprecated and will be removed in a future version.

/usr/bin/mysqlhotcopy Ver 1.23

Usage: /usr/bin/mysqlhotcopy db_name[./table_regex/] [new_db_name | directory]

-?, --help          display this help-screen and exit

-u, --user=#        user for database login if not current user

-p, --password=#    password to use when connecting to server (if not set

in my.cnf, which is recommended)

-h, --host=#        hostname for local server when connecting over TCP/IP

-P, --port=#        port to use when connecting to local server with TCP/IP

-S, --socket=#      socket to use when connecting to local server

--old_server    connect to old MySQL-server (before v5.5) which

doesn't have FLUSH TABLES WITH READ LOCK fully implemented.

--allowold          don't abort if target dir already exists (rename it _old)    --不覆盖以前备份的文件

--addtodest          don't rename target dir if it exists, just add files to it      --属于增量备份

--keepold            don't delete previous (now renamed) target when done

--noindices          don't include full index files in copy          --不备份索引文件

--method=#          method for copy (only "cp" currently supported)

-q, --quiet          be silent except for errors

--debug              enable debug                                          --启用调试输出

-n, --dryrun        report actions without doing them

--regexp=#          copy all databases with names matching regexp  --使用正规表达式

--suffix=#          suffix for names of copied databases

--checkpoint=#      insert checkpoint entry into specified db.table    --插入检查点条目

--flushlog          flush logs once all tables are locked                    --所有表锁定后刷新日志

--resetmaster        reset the binlog once all tables are locked        --一旦锁表重置binlog文件

--resetslave        reset the master.info once all tables are locked  --一旦锁表重置master.info文件

--tmpdir=#        temporary directory (instead of /tmp)

--record_log_pos=#  record slave and master status in specified db.table

--chroot=#          base directory of chroot jail in which mysqld operates

Try 'perldoc /usr/bin/mysqlhotcopy' for more complete documentation[root@tong2 ~]#

3.备份一个数据库到一个目录中

[root@tong2 ~]# mysqlhotcopy -u root -p system tong /opt/

[root@tong2 ~]# ll /opt/tong/

total 112

-rw-rw----. 1 mysql mysql    15 Jan  5 14:35 q.isl

-rw-rw----. 1 mysql mysql  8554 Jan  4 18:03 t.frm

-rw-rw----. 1 mysql mysql 98304 Jan  4 18:03 t.ibd

[root@tong2 ~]# ll /var/lib/mysql/tong

total 112

-rw-rw----. 1 mysql mysql    15 Jan  5 14:35 q.isl

-rw-rw----. 1 mysql mysql  8554 Jan  4 18:03 t.frm

-rw-rw----. 1 mysql mysql 98304 Jan  4 18:03 t.ibd

[root@tong2 ~]#

4.备份多个数据库到一个目录中

[root@tong2 ~]# mysqlhotcopy -u root -p system tong mysql /opt/tong

[root@tong2 ~]# ll /opt/

total 8

drwxr-x---. 2 mysql mysql 4096 Jan  5 15:29 mysql

drwxr-x---. 2 mysql mysql 4096 Jan  5 15:29 tong

[root@tong2 ~]# ll /var/lib/mysql/{mysql,tong} -d

drwxr-xr-x. 2 mysql mysql 4096 Jan  5 15:29 /var/lib/mysql/mysql

drwxr-xr-x. 2 mysql mysql 4096 Jan  5 15:29 /var/lib/mysql/tong

[root@tong2 ~]#

5.备份数据库中某一个表

[root@tong2 ~]# mysqlhotcopy -u root -p system mysql./user*/ /opt/

[root@tong2 ~]# ll /opt/mysql/

total 20

-rw-r--r--. 1 mysql mysql 10684 Jan  4 16:49 user.frm

-rw-r--r--. 1 mysql mysql  784 Jan  4 16:49 user.MYD

-rw-r--r--. 1 mysql mysql  2048 Jan  4 16:49 user.MYI

[root@tong2 ~]# ll /var/lib/mysql/mysql/user.*

-rw-r--r--. 1 mysql mysql 10684 Jan  4 16:49 /var/lib/mysql/mysql/user.frm

-rw-r--r--. 1 mysql mysql  784 Jan  4 16:49 /var/lib/mysql/mysql/user.MYD

-rw-r--r--. 1 mysql mysql  2048 Jan  4 16:49 /var/lib/mysql/mysql/user.MYI

[root@tong2 ~]#

6.恢复数据

[root@tong2 ~]# rm -rf /var/lib/mysql/tong

[root@tong2 ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 29

Server version: 5.6.21-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014,Oracleand/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test              |

+--------------------+

4 rows in set (0.00 sec)

[root@tong2 ~]# cp -arp /opt/tong /var/lib/mysql/        --将备份的数据移到mysql数据根目录

[root@tong2 ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 30

Server version: 5.6.21-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \u tong

Database changed

mysql> show tables;

+----------------+

| Tables_in_tong |

+----------------+

| t              |

+----------------+

2 rows in set (0.00 sec)

[root@tong2 ~]#

MySQL备份工具之mysqlhotcopy的更多相关文章

  1. MySQL备份工具之mysqldump使用

    MySQL备份工具之mysqldump使用说明 一.备份分类 根据能否停用数据库,将备份类型分为: 1. 冷备:数据库服务停止后备份 2. 温备:只能对数据库进行读操作,不能进行写操作 3. 热备:在 ...

  2. mysql备份工具innobackupex,xtrabackup-2.1的原理和安装

    mysql备份工具innobackupex,xtrabackup-2.1的原理和安装 http://bbs.2cto.com/read.php?tid=310496 一.Xtrabackup介绍 1. ...

  3. Mysql备份工具xtraback全量和增量测试

    Mysql备份工具xtraback全量和增量测试   xtrabackup 是 percona 的一个开源项目,可以热备份innodb ,XtraDB,和MyISAM(会锁表) 官方网址http:// ...

  4. Mysql备份工具比较

    Mysql备份工具比较 大 | 中 | 小 [ 2012/12/25 12:10 | by Sonic ] 1. 使用automysqlbackup http://sourceforge.net/pr ...

  5. Mysql备份工具mysqldump和mysqlhotcopy

    (1).Mysql备份类型 1)按照备份时对数据库的影响分为 Hot backup(热备):也叫在线备份.指在数据库运行中直接备份,对正在运行的数据库没有任何影响. Cold backup(冷备):也 ...

  6. shell编写mysql备份工具

    如需转载,请经本人同意. 这是之前写的一个备份脚本,调用的备份工具是xtrabackup 编写思路是:每周一全备份,备份后提取lSN号,对备份文件进行压缩,其余时候在LSN的基础上进行增量备份,并对3 ...

  7. mysql备份工具 :mysqldump mydumper Xtrabackup 原理

    备份是数据安全的最后一道防线,对于任何数据丢失的场景,备份虽然不一定能恢复百分之百的数据(取决于备份周期),但至少能将损失降到最低.衡量备份恢复有两个重要的指标:恢复点目标(RPO)和恢复时间目标(R ...

  8. mysql二进制日志和mysql备份工具介绍以及日志恢复

    mysql备份: 三种备份方式 冷备:数据库停机,在进行备份 热备:lock table锁表,read   数据库只可以读不能写,在备份 温备:备份时数据库正常运行 备份类型:完整备份:全部备份,部分 ...

  9. MySQL备份工具收集

    说明:MySQL的备份不像SQL Server那么的简单,备份时需要分数据库引擎类型,现在主流的就两个:InnoDB和MyISAM,而这两种类型备份方式各不一样. MyISAM: mysqlhotco ...

随机推荐

  1. NFS pv部署

    一.部署nfs服务端: 可以选择kubernetes_cluster内的任意的node去做为nfs服务端,部署节点也可以.我选择的是部署节点去做为nfs服务端. (1)部署节点安装nfs服务软件包: ...

  2. lwip 内存配置和使用,以及 如何 计算 lwip 使用了多少内存?

    /** * 内存配置 * suozhang 2019年9月6日20:25:48 参考 <<LwIP 应用开发实战指南>> 野火 第5章 LwIP 的内存管理 * * 动态内存池 ...

  3. 【bzoj 4059】Non-boring sequences

    这题的重点不在于代码,而在于复杂度分析…… 首先我们肯定会写 $n^2$ 暴力,就是每次暴力扫 $[l,r]$ 区间,找到任意一个在此区间中只出现过一次的数.设其下标为 $mid$,显然在这个区间中任 ...

  4. redis 加锁与释放锁(分布式锁1)

    使用Redis的 SETNX 命令可以实现分布式锁 SETNX key value 返回值 返回整数,具体为 - 1,当 key 的值被设置 - 0,当 key 的值没被设置 分布式锁使用 impor ...

  5. java 数组转list asList用法

    https://www.cnblogs.com/zheyangsan/p/6910476.html java中数组转list使用Arrays.asList(T... a)方法. 示例: public ...

  6. 遗传算法解决寻路问题——Python描述

    概要 我的上一篇写遗传算法解决排序问题,当中思想借鉴了遗传算法解决TSP问题,本质上可以认为这是一类问题,就是这样认为:寻找到一个序列X,使F(X)最大. 详解介绍 排序问题:寻找一个序列,使得这个序 ...

  7. poj2182 Lost Cows[BIT二分]

    blog题解鸽了许久了..本来说好的切一题写一个题解的说 一个$1 \sim n$数列,已知每个数前面比他小的数个数,试确定该序列. 相当的一道水题.可以发现数列最后一个数是首先可以确定下来的.然后把 ...

  8. jquery visible 选择器 语法

    jquery visible 选择器 语法 作用::visible 选择器选取每个当前是可见的元素.除以下几种情况之外的元素即是可见元素:设置为 display:none   type="h ...

  9. CF 680D 堆塔

    D. Bear and Tower of Cubes time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  10. 使用Qt Designer进行布局

    在使用Form之前,需要将Form上的对象放置到布局中.这确保在应用程序中预览或使用Form时,对象将正确显示.在布局中放置对象还可以确保在调整窗体大小时它们也能正确调整大小. 应用和打断布局    ...