搜索
首页数据库mysql教程MySQL备份的几种方式的讨论,重点关注在线热备

MySQL的备份方式,目前我想到的有五种,有可能还有 1,mysqldump方式,加上具体参数名(单库,多库,触发器,存储过程,表结构,字符集,single-transaction,等等) 2,mysqlhotcopy 只能备份myisam数据表备份,速度相当快,因为是文件拷贝,可能瞬间被锁表

MySQL的备份方式,目前我想到的有五种,有可能还有 MySQL备份的几种方式的讨论,重点关注在线热备
1,mysqldump方式,加上具体参数名(单库,多库,触发器,存储过程,表结构,字符集,–single-transaction,等等)
2,mysqlhotcopy 只能备份myisam数据表备份,速度相当快,因为是文件拷贝,可能瞬间被锁表,任何的数据操作,比如插入和更新都会挂起。
3,LVM的快照功能进行数据库分区的备份,这种方法是利用的逻辑卷的镜像功能,对整个分区进行在线备份,这种备份数据量大,而且备份性能低下,因为每次备份都是整个镜像,不能针对数据做备份。桶装备份
4,开启二进制同步日志功能,主从复制,从机器做备份功能。
5,在线的热备份,采用开源的 Xtrabackup 备份工具对innodb 数据表进行在线备份,测试阶段。

下面是备份的xtrabackup的测试例子。

[@root.localhost.nova ~]# /usr/bin/innobackupex-1.5.1 –user=root –defaults-file=/home/mysql/my.cnf –socket=/home/mysql/mysql.sock –database=serverinfo –slave-info –stream=tar /root/ |gzip > /root/bak_mysql.tar.gz

InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy.
All Rights Reserved.

This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.

IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackup
prints “innobackup completed OK!”.

innobackupex: Using mysql Ver 14.12 Distrib 5.0.83, for pc-linux-gnu (i686) using readline 5.1
innobackupex: Using mysql server version 5.0.83-community-log

innobackupex: Created backup directory /root
090823 17:37:51 innobackupex: Starting mysql with options: –unbuffered –user=root –socket=/home/mysql/mysql.sock
090823 17:37:51 innobackupex: Connected to database with mysql child process (pid=28803)
090823 17:37:55 innobackupex: Connection to database server closed

090823 17:37:55 innobackupex: Starting ibbackup with command: xtrabackup –defaults-file=/home/mysql/my.cnf –backup –suspend-at-end –log-stream –target-dir=./
innobackupex: Waiting for ibbackup (pid=28809) to suspend
innobackupex: Suspend file ‘/home/mysql/xtrabackup_suspended’

xtrabackup: suspend-at-end is enabled.
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /home/mysql
xtrabackup: Target instance is assumed as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 4194304
xtrabackup: Stream mode.
>> log scanned up to (0 85364)

090823 17:37:57 innobackupex: Continuing after ibbackup has suspended

innobackupex: Starting to backup InnoDB tables and indexes
innobackupex: from original InnoDB data directory ‘/home/mysql’
innobackupex: Backing up as tar stream ‘ibdata1′
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_djgameserver.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_djgameserverlog.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_repairhistory.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_serverinfo.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_serverinfolog.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_tlgameserver.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_tlgameserverlog.ibd’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_user.ibd’
090823 17:37:58 innobackupex: Starting mysql with options: –unbuffered –user=root –socket=/home/mysql/mysql.sock
090823 17:37:58 innobackupex: Connected to database with mysql child process (pid=28834)
>> log scanned up to (0 85364)
090823 17:38:02 innobackupex: Starting to lock all tables…
>> log scanned up to (0 85364)
>> log scanned up to (0 88314)
>> log scanned up to (0 88415)
090823 17:38:20 innobackupex: All tables locked and flushed to disk

090823 17:38:20 innobackupex: Starting to backup .frm, .MRG, .MYD, .MYI,
innobackupex: .TRG, .TRN, and .opt files in
innobackupex: subdirectories of ‘/home/mysql’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_djgameserver.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_djgameserverlog.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_repairhistory.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_serverinfo.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_serverinfolog.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_tlgameserver.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_tlgameserverlog.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/simsys_user.frm’
innobackupex: Backing up file ‘/home/mysql/serverinfo/db.opt’
090823 17:38:20 innobackupex: Finished backing up .frm, .MRG, .MYD, .MYI, .TRG, .TRN, and .opt files

innobackupex: Resuming ibbackup

xtrabackup: The latest check point (for incremental): ‘0:88415′
>> log scanned up to (0 88415)
xtrabackup: Transaction log of lsn (0 85364) to (0 88415) was copied.
090823 17:38:24 innobackupex: All tables unlocked
090823 17:38:24 innobackupex: Connection to database server closed

innobackupex: Backup created in directory ‘/root’
innobackupex: MySQL binlog position: filename ”, position
innobackupex: MySQL slave binlog position: master host ”, filename ”, position
090823 17:38:24 innobackupex: innobackup completed OK!
innobackupex: You must use -i (–ignore-zeros) option for extraction of the tar stream.
[@root.localhost.nova ~]#
[@root.localhost.nova ~]# ls -ltr
total 11752
drwxr-xr-x 2 oracle ftp 4096 Apr 20 15:43 linux
-rw-r–r– 1 root root 17969 Apr 20 15:43 linux.tgz
-rw-r–r– 1 root root 4698 Jun 5 16:08 install.sh
-rw-r–r– 1 root root 3565 Jun 18 11:21 HP-set.sh
-rw-r–r– 1 root root 98676 Jul 27 13:33 install.log.syslog
-rw-r–r– 1 root root 68464 Jul 27 13:33 install.log
-rw-r–r– 1 root root 1299 Jul 27 13:33 anaconda-ks.cfg
-rw-rw—- 1 mysql mysql 10485760 Aug 14 10:57 ibdata1
-rw-r–r– 1 root root 1230176 Aug 23 17:12 xtrabackup-0.7-1.rhel4.x86_64.rpm
-rw-r–r– 1 root root 44998 Aug 23 17:38 bak_mysql.tar.gz
[@root.localhost.nova ~]#

[@root.localhost.nova tmp]# ls -lR
.:
total 10336
-rw-r–r– 1 root root 259 Aug 23 17:37 backup-my.cnf
-rw-r–r– 1 root root 44998 Aug 23 17:43 bak_mysql.tar.gz
-rw-rw—- 1 mysql mysql 10485760 Aug 23 17:28 ibdata1
-rw-r–r– 1 root root 0 Aug 23 17:37 mysql-stderr
-rw-r–r– 1 root root 506 Aug 23 17:38 mysql-stdout
drwxr-xr-x 2 root root 380 Aug 23 17:43 serverinfo
-rw-r–r– 1 root root 1 Aug 23 17:38 xtrabackup_binlog_info
-rw-r–r– 1 root root 60 Aug 23 17:38 xtrabackup_checkpoints
-rw-r–r– 1 root root 5632 Aug 23 17:38 xtrabackup_logfile
-rw-r–r– 1 root root 53 Aug 23 17:38 xtrabackup_slave_info

./serverinfo:
total 1020
-rw-rw—- 1 mysql mysql 61 Aug 12 19:59 db.opt
-rw-rw—- 1 mysql mysql 34626 Aug 12 20:00 simsys_djgameserver.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_djgameserver.ibd
-rw-rw—- 1 mysql mysql 8760 Aug 12 20:00 simsys_djgameserverlog.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_djgameserverlog.ibd
-rw-rw—- 1 mysql mysql 12944 Aug 12 20:00 simsys_repairhistory.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_repairhistory.ibd
-rw-rw—- 1 mysql mysql 26072 Aug 12 20:00 simsys_serverinfo.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_serverinfo.ibd
-rw-rw—- 1 mysql mysql 8760 Aug 12 20:00 simsys_serverinfolog.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_serverinfolog.ibd
-rw-rw—- 1 mysql mysql 56550 Aug 12 20:00 simsys_tlgameserver.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_tlgameserver.ibd
-rw-rw—- 1 mysql mysql 8760 Aug 12 20:00 simsys_tlgameserverlog.frm
-rw-rw—- 1 mysql mysql 98304 Aug 12 20:00 simsys_tlgameserverlog.ibd
-rw-rw—- 1 mysql mysql 8646 Aug 12 20:00 simsys_user.frm
-rw-rw—- 1 mysql mysql 98304 Aug 14 10:57 simsys_user.ibd

备份出来的文件是:bak_mysql.tar.gz,解压方法:tar zxvfi bak_mysql.tar.gz

恢复时候就采用复制文件,覆盖,然后mysqldump方式导入导出。

 

http://www.imdba.cn/2009/08/31/mysqlbakup-eg/

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
图文详解mysql架构原理图文详解mysql架构原理May 17, 2022 pm 05:54 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

mysql的msi与zip版本有什么区别mysql的msi与zip版本有什么区别May 16, 2022 pm 04:33 PM

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

mysql怎么去掉第一个字符mysql怎么去掉第一个字符May 19, 2022 am 10:21 AM

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

mysql怎么替换换行符mysql怎么替换换行符Apr 18, 2022 pm 03:14 PM

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

MySQL复制技术之异步复制和半同步复制MySQL复制技术之异步复制和半同步复制Apr 25, 2022 pm 07:21 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

mysql怎么将varchar转换为int类型mysql怎么将varchar转换为int类型May 12, 2022 pm 04:51 PM

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

mysql怎么判断是否是数字类型mysql怎么判断是否是数字类型May 16, 2022 am 10:09 AM

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

mysql怎么删除unique keymysql怎么删除unique keyMay 12, 2022 pm 03:01 PM

在mysql中,可利用“ALTER TABLE 表名 DROP INDEX unique key名”语句来删除unique key;ALTER TABLE语句用于对数据进行添加、删除或修改操作,DROP INDEX语句用于表示删除约束操作。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具