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_MySQL备份工具之mysqlhotcopy相关推荐

  1. mysql mysqlhotcopy_MySQL 备份和恢复 (mysqlhotcopy)

    一. 备份 mysqlhotcopy 是一个 PERL 程序,最初由Tim Bunce编写.它使用 LOCK TABLES.FLUSH TABLES 和 cp 或 scp 来快速备份数据库.它是备份数 ...

  2. mysql远程备份工具_innobackupex实现MySQL远程备份

    一.了解innobackupex 1.mysqldump mysql逻辑备份工具,作用于服务器本地,不需要额外安装插件 可以单表备份,备份为sql文件形式.方便,在多个场景通用 可通过shell命令实 ...

  3. mysql 物理备份工具_mysql物理备份工具Xtrabackup安装配置

    mysql物理备份工具Xtrabackup安装配置 1Xtrabackup工具介绍 Xtrabackup是一个对InnoDB做物理数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具 ...

  4. mysql物理备份工具Xtrabackup安装配置

    mysql物理备份工具Xtrabackup安装配置 1    Xtrabackup工具介绍 Xtrabackup是一个对InnoDB做物理数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业 ...

  5. mysql自动备份工具_|Mysql自动备份工具(Auto MySQL Backup)下载v1.5 官方版 附教程 - 欧普软件下载...

    Auto MySQL Backup是一款好用的Mysql自动备份工具,可以对MySQL数据库进行每日.每周和每月备份,可同时备份多个数据库.压缩备份.备份远程数据和发送日志等,小编还带来了详细的使用方 ...

  6. mysql企业备份工具(MEB)之mysqlbackup安装及使用

    mysql enterprise版比community在备份工具上有了提升,多了一个mysqlbackup的工具,即mysql企业备份工具. 当然遵循GPL的社区版也可以用: 该工具单独下载: 到官方 ...

  7. MySQL Study之--Mysql数据库备份工具(mysqldump)

    MySQL Study之--Mysql数据库备份工具(mysqldump) 对于Mysql Database的备份方式有很多种,此次文档主要介绍mysqldump工具: mysqldump:     ...

  8. mysql mysqlhotcopy_MySQL备份之mysqlhotcopy与注意事项

    此文章主要向大家介绍的是MySQL备份之mysqlhotcopy与其在实际操作中应注意事项的描述,我们大家都知道实现MySQL数据库备份的常用方法有三个,但是我们今天主要向大家介绍的是其中的一个比较好 ...

  9. mysql的常用的备份工具_39、mysql常用备份工具

    备份和恢复的作用 1.做灾难恢复 2.做审计 3.测试(备份数据做恢复测试) 备份类型: 根据备份时,数据库服务器是否在线 冷备:cold backup 服务器处于离线状态 温备:warm backu ...

最新文章

  1. [20181204]低版本toad 9.6直连与ora-12505.txt
  2. 擦除:提升 CNN 特征可视化的 3 种重要手段
  3. CSS中float属性详解
  4. 清除应用程序所有缓存
  5. for、while循环及其变体
  6. Java实现根据地理位置获取经纬度
  7. linux--命令rcp和scp
  8. Android手机刷机失败的自救方法
  9. 高级项目管理-3、项目立项、变更、整体管理
  10. 宋宝华Linux培训笔记-Linux多进程
  11. CDN回源原理和CDN多级缓存
  12. java基础回顾之Map中 TreeMap排序原理-二叉树
  13. 人工智能在物流行业的发展与应用
  14. 打开html按钮没文字,为什么我打开网页有些字没显示但能点击
  15. NLPCC2019 - User-Characteristic Enhanced Model for Fake News Detection in Social Media
  16. matlab 心形曲线
  17. 阿里云RDS-NAS-OSS
  18. 使用 Vue-cli 搭建SPA项目
  19. 打印幻灯片去掉空白边缘
  20. surface pro3深度linux,surface pro4 安装deepin教程

热门文章

  1. OpenCV图像处理使用笔记(六)——图像滤波
  2. 论文笔记:GVCNN: Group-View Convolutional Neural Networks for 3D Shape Recognition
  3. 一个封锁操作被对 wsacancelblockingcall 的调用中断_操作系统概论
  4. 用LIBSVM做回归和预测的步骤
  5. 高可用keepalived实例
  6. MySQL中的条件赋值
  7. 亿级大表分库分表实战总结(万字干货,实战复盘)
  8. 一文让你轻松了解 JAVA 开发中的四种加密方法
  9. 面试问红黑树,我脸都绿了。。
  10. 5年没有工资收入,他如何支撑世界上最大的免费编程社区?