mysql备份工具之mysqlhotcopy

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

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

[[email protected] ~]# yum install perl-DBD* -y

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

[[email protected] ~]# tar xvf DBD-mysql-4.029.tar.gz

[[email protected] ~]# cd DBD-mysql-4.029
[[email protected] DBD-mysql-4.029]# perl Makefile.PL

[[email protected] DBD-mysql-4.029]# make

[[email protected] DBD-mysql-4.029]# make install

[[email protected] DBD-mysql-4.029]# echo $?
0
[[email protected] DBD-mysql-4.029]# cd
[[email protected] ~]#

2.查看mysqlhotcopy的帮助信息

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

[mysqlhotcopy]
interactive-timeout
host=localhost
user=root
password=system
port=3306

[[email protected] ~]# /etc/init.d/mysql restart      --重启服务
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

[[email protected] ~]# mysqlhotcopy  --help
Warning: /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
[[email protected] ~]#

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

[[email protected] ~]# mysqlhotcopy -u root -p system tong /opt/

[[email protected] ~]# 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
[[email protected] ~]# 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
[[email protected] ~]#

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

[[email protected] ~]# mysqlhotcopy -u root -p system tong mysql /opt/tong

[[email protected] ~]# 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

[[email protected] ~]# 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
[[email protected] ~]#

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

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

[[email protected] ~]# 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

[[email protected] ~]# 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
[[email protected] ~]#

6.恢复数据

[[email protected] ~]# rm -rf /var/lib/mysql/tong
[[email protected] ~]# 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, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye

[[email protected] ~]# cp -arp /opt/tong /var/lib/mysql/
[[email protected] ~]# 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)

mysql> exit
Bye

[[email protected] ~]#

时间: 2024-11-09 03:04:55

mysql备份工具之mysqlhotcopy的相关文章

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

Mysql备份工具xtraback全量和增量测试   xtrabackup 是 percona 的一个开源项目,可以热备份innodb ,XtraDB,和MyISAM(会锁表) 官方网址http://www.percona.com/docs/wiki/percona-xtrabackup:start Xtrabackup是由percona开发的一个开源软件,此软件可以说是innodb热备工具ibbackup的一个开源替代品.这个软件是由2个部分组成的:xtrabackup和innobackupe

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

mysql备份工具innobackupex,xtrabackup-2.1的原理和安装 http://bbs.2cto.com/read.php?tid=310496 一.Xtrabackup介绍 1.1:Xtrabackup是什么Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品. Xtrabackup有两个主要的工具:xtrabackup.innobackupex1.xtraback

mysql 备份工具简介

mysql自带的: mysqldump:逻辑备份工具,对MySAM可以实现温备,对innodb可以进行热备 mysqlhotcopy:物理备份工具(温备份) 文件系统工具: 比如你在Linux下面的直接使用cp 命令(冷备份),win下面的复制(冷备份) LVM快照功能可以实现几乎热备份 LVM快照备份MyISAM 和innodb引擎的数据时候需要注意: 对MyISAM而言使用LVM快照备份需要在mysql执行sql命令 flush tables:然后LOCK TABLE 然后才能创建快照,创建

MySQL备份工具XtraBackup的使用

xtrabackup简介 Xtrabackup是由percona提供的mysql数据库备份工具,据官方介绍,这也是世界上惟一一款开源的能够对innodb和xtradb数据库进行热备的工具.特点: (1)备份过程快速.可靠: (2)备份过程不会打断正在执行的事务: (3)能够基于压缩等功能节约磁盘空间和流量: (4)自动实现备份检验: (5)还原速度快: 官方下载地址:地址,你可以通过此链接下载最新版. #wget https://www.percona.com/downloads/XtraBac

mysql备份工具

备份还原脚本及工具 1)Xtrabackup实现是物理备份,而且是物理热备 目前主流的有两个工具可以实现物理热备:ibbackup和xtrabackup:ibbackup是商业软件,需要授权,非常昂贵.而xtrabackup功能比ibbackup还要强大,但却是开源的. 2)Xtrabackup提供了两种命令行工具: xtrabackup:专用于备份InnoDB和XtraDB引擎的数据: innobackupex:这是一个perl脚本,在执行过程中会调用xtrabackup命令,这样用该命令即可

mysql备份工具之xtrabackup

1.备份xtrabackup工具安装(只能备份数据,不能备份表结构)http://tongcheng.blog.51cto.com/6214144/1562538 2.xtrabackup基本参数 --defaults-file      --数据库的默认配置文件 --target-dir         --备份文件存放的目录 --backup             --备份到--target-dir目录中 --prepare            --备份文件恢复前的准备 --use-me

MySQL备份工具收集

说明:MySQL的备份不像SQL Server那么的简单,备份时需要分数据库引擎类型,现在主流的就两个:InnoDB和MyISAM,而这两种类型备份方式各不一样. MyISAM: mysqlhotcopy InnoDB: xtrabackup(innodb和xtradb两种引擎的表) innobackupex(支持同时备份innodb和myisam) mysqldump 参考: https://www.zhihu.com/question/19693621

MySQL备份工具mydumper备份

#!/usr/bin/phthon import os import time import commands import shutil import threading from os.path import join, getsize import MySQLdb as mydb # 备份目录 baseDir = "/data2/backup/backup_data/" # ns 或 wx; 备份后是否要压缩(mydumper 自带压缩功能),要压缩 True,否则 False.

mysql备份工具--mysqldump备份以及恢复

https://help.aliyun.com/knowledge_detail/41738.html mysql全备:记录pos位置 mysqldump -h10.10.10.1 -uadmin -p --master-data=2 --single-transaction -R --events -q --all-databases > 2.sql cat 2.sql |head -22 在导出的备份中的22行会看到pos位置点和具体的binlog文件名称 CHANGE MASTER TO