xtrabackup简介_MySQL
bitsCN.com
mysql的备份方式
1.mysqldump
效率比较低,备份和还原的速度都很慢,任何数据插入和更新操作都会被挂起
2.mysqlhotcopy
mysqlhotcopy 是专门针对myisam 数据表进行备份,备份的过程中,任何数据插入和更新操作都会被挂起
3.准备一台从服务器,专门做备份(master-slave方式)
4.xtrabackup 是 percona 的一个开源项目,可热备份innodb ,XtraDB,MyISAM(会锁表)
Xtrabackup有两个主要的工具:xtrabackup、innobackupex
xtrabackup只能备份InnoDB和XtraDB两种数据表,而不能备份MyISAM数据表
innobackupex-1.5.1则封装了xtrabackup,是一个脚本封装,所以能同时备份处理innodb和myisam,但在处理myisam时需要加一个读锁
相比之下 xtrabackup 备份比较靠谱
下载 xtrabackup-1.6-245.rhel5.x86_64.rpm
安装 rpm -ivh xtrabackup-1.6-245.rhel5.x86_64.rpm
备份(xtrabackup只备份数据文件,并不备份数据表结构(.frm))
xtrabackup --defaults-file=/etc/my.cnf --backup --target-dir=/bak/
恢复(执行两次)
xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/bak/
xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/bak/
二、 增量备份
对比innobackupex和xtrabackup,innobackupex操作起来更方便,但是innobackupex会有短暂的锁表.xtrabackup备份还有另一个重要特性:增量备份.
1. 全量备份
xtrabackup --defaults-file=/etc/my.cnf --backup --target-dir=/bak/
2. 增量备份
xtrabackup --defaults-file=/etc/my.cnf --backup --target-dir=/bak/ --incremental-basedir=/bak/increm/
在增量备份的目录下,数据文件都是以.delta结尾的。增量备份只备份上一次全量备份之后被修改过的page,所以增量备份一般只暂用较少的空间。
3. 增量备份恢复
分别对全量、增量备份各做一次prepare操作。
xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/bak/
xtrabackup --prepare --target-dir=/bak/ --incremental-dir=/bak/increm/
/bak/下的数据文件就可以直接放到你的MySQL数据目录下,恢复数据了。
一般的备份 比如不会换全新的环境 用xtrabackup 就可以了
在不停生产的情况下备份数据给slave
首先确保两边的/etc/my.cnf 文件里边都指定了datadir
接着备份数据:
innobackupex-1.5.1 --defaults-file=/etc/my.cnf --stream=tar --user=root --password=**** --port=3306 --slave-info /bak | gzip>/bak/bak_mysql.tar.gz
将bak_mysql.tar.gz cp 到另一台机器上
scp /bak/bak_mysql.tar.gz root@host:/home/bak_mysql.tar.gz
解压bak_mysql.tar.gz到/bak
tar -ixvf mysqlbak.tar(一定要加i 参数 我也不知道为什么)
恢复先 --apply-log 再 --copy-back
innobackupex-1.5.1 --defaults-file=/etc/my.cnf --user=root --password=XXXX --port=3306 --apply-log /bak
--copy-back这里容易报错
(innobackupex-1.5.1: Copying directory '/bak/tech_soft_drp_ywmy'
innobackupex-1.5.1: Copying directory '/bak/mysql'
mkdir: 无法创建目录 “arb/mysql/mysql”: 文件已存在
innobackupex-1.5.1: Error: Failed to create directory 'arb/mysql/mysql' : 没有那个文件或目录 at /usr/bin/innobackupex-1.5.1 line 336.)
我也不知道咋整。好像是官方1bug 见https://bugs.launchpad.net/percona-xtrabackup/+bug/737569
我看了看/bak目录 决定把mysql test 等自带的一些库直接rm 了。执行已下命令成功
innobackupex-1.5.1 --defaults-file=/etc/my.cnf --user=root --password=XXXX --port=3306 --copy-back /bak
重启数据库服务又有问题
(110719 19:30:16 mysqld_safe Starting mysqld daemon with databases from arb/mysql
110719 19:30:16 [Note] Plugin 'FEDERATED' is disabled.
110719 19:30:16 InnoDB: The InnoDB memory heap is disabled
110719 19:30:16 InnoDB: Mutexes and rw_locks use GCC atomic builtins
110719 19:30:16 InnoDB: Compressed tables use zlib 1.2.3
110719 19:30:16 InnoDB: Using Linux native AIO
110719 19:30:16 InnoDB: Initializing buffer pool, size = 2.0G
110719 19:30:16 InnoDB: Completed initialization of buffer pool
110719 19:30:16 InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ib_logfile0
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
110719 19:30:16 mysqld_safe mysqld from pid file arb/mysql/r410.pid ended)
不知道啥情况。网上搜搜好像是权限问题 直接将mysql 目录 chmod 777 -R mysql 重启服务好了
菩萨保佑 问题好了
将my.cnf 配置成server-id=2 主从配置在这里不多提了
CHANGE MASTER TO MASTER_HOST='xxxx',MASTER_USER='xx',MASTER_PASSWORD='xxx',MASTER_LOG_FILE='mysql-bin.000047',MASTER_LOG_POS=43446639
MASTER_LOG_FILE这个值去/bak 下面的 xtrabackup_binlog_info 找
大功告成
省了以前通宵用mysqldump 来同步数据再做主从同步
这东东是个神器

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

Navicat itself does not store the database password, and can only retrieve the encrypted password. Solution: 1. Check the password manager; 2. Check Navicat's "Remember Password" function; 3. Reset the database password; 4. Contact the database administrator.

1. Use the correct index to speed up data retrieval by reducing the amount of data scanned select*frommployeeswherelast_name='smith'; if you look up a column of a table multiple times, create an index for that column. If you or your app needs data from multiple columns according to the criteria, create a composite index 2. Avoid select * only those required columns, if you select all unwanted columns, this will only consume more server memory and cause the server to slow down at high load or frequency times For example, your table contains columns such as created_at and updated_at and timestamps, and then avoid selecting * because they do not require inefficient query se

Create a database using Navicat Premium: Connect to the database server and enter the connection parameters. Right-click on the server and select Create Database. Enter the name of the new database and the specified character set and collation. Connect to the new database and create the table in the Object Browser. Right-click on the table and select Insert Data to insert the data.

Copying a table in MySQL requires creating new tables, inserting data, setting foreign keys, copying indexes, triggers, stored procedures, and functions. The specific steps include: creating a new table with the same structure. Insert data from the original table into a new table. Set the same foreign key constraint (if the original table has one). Create the same index. Create the same trigger (if the original table has one). Create the same stored procedure or function (if the original table is used).

Navicat for MariaDB cannot view the database password directly because the password is stored in encrypted form. To ensure the database security, there are three ways to reset your password: reset your password through Navicat and set a complex password. View the configuration file (not recommended, high risk). Use system command line tools (not recommended, you need to be proficient in command line tools).

View the MySQL database with the following command: Connect to the server: mysql -u Username -p Password Run SHOW DATABASES; Command to get all existing databases Select database: USE database name; View table: SHOW TABLES; View table structure: DESCRIBE table name; View data: SELECT * FROM table name;
