MySQL两种不完全恢复的方法
MySQL 5.6.14生产环境凌晨3点的备份,不完全恢复到中午12点.(xtrabackup_binlog_pos_innodb的内容是mysql-bin.006946 3784607)
MySQL 5.6.14
生产环境凌晨3点的备份,不完全恢复到中午12点.
(xtrabackup_binlog_pos_innodb的内容是mysql-bin.006946 3784607)
第一种方式:mysqlbinlog
1.找到需要恢复的binlog
进入binlog目录,执行
ll | awk '{print $9}' > /tmp/binlog.index
然后修改/tmp/binlog.index文件,删除不需要恢复的文件名.
2.解析binlog
time mysqlbinlog $(cat /tmp/binlog.index) --start-position=3784607 --stop-datetime='2015-07-13 12:00:00' > /tmp/binlog
real 2m32.399s
user 1m24.514s
sys 1m5.803s
3.设置MySQL服务器参数
max_allowed_packet=100M
innodb_flush_log_at_trx_commit=0
4.执行
time mysql -uroot -p -S mysql.sock --force
real 50m24.341s
user 5m1.426s
sys 3m32.348s
执行3.4G的文件,用时50分钟.
第二种方式:复制,使用SQL线程执行
1.找到需要恢复的binlog
进入binlog目录,执行
ll | awk '{print $9}' > /tmp/binlog.index
然后修改/tmp/binlog.index文件,删除不需要恢复的文件名.
2.拷贝需要的binlog至一个新的目录
mkdir /tmp/testlog
cp $(cat /tmp/binlog.index) /tmp/testlog/
3.修改服务器参数
max_allowed_packet=100M
innodb_flush_log_at_trx_commit=0
server_id=111
relay_log=/tmp/testlog/mysql-bin
relay_log_index=/tmp/testlog/mysql-bin.index
skip_slave_start = 1
其中
server_id一定要修改为一个不同的值,否则binlog被直接丢弃.
skip_slave_start防止自动启动复制
4.启动实例,生成复制的相关文件
change master to
master_host='localhost',
master_port=3306,
master_user='repl',
master_password='repl',
master_log_file='dummy.binlog',
master_log_pos=777;
master是一个随便的值,主要是生成master.info,relay-log.info等相关文件
5.关闭实例,修改文件
修改relay-log.info
修改/tmp/testlog/mysql-bin.index 为
awk '{print "/tmp/testlog/"$1'} /tmp/binlog.index > /tmp/testlog/mysql-bin.index
6.启动实例,启动复制
start slave sql_thread UNTIL RELAY_LOG_FILE = 'mysql-bin.006982', RELAY_LOG_POS = 37300415;
恢复用时43分钟.
mysqlbinlog方式更简单,但是一旦出错,容易前功尽弃
复制的方式,前期配置比较复杂,但是出现错误,更容易修正.
从效率上看,相差不大
如果有大量的binlog需要恢复,建议使用复制的方式.
如果只有少量的binlog需要恢复,还是使用mysqlbinlog更简洁一些.
本文永久更新链接地址:
,
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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

PHP database connection guide: MySQL: Install the MySQLi extension and create a connection (servername, username, password, dbname). PostgreSQL: Install the PgSQL extension and create a connection (host, dbname, user, password). Oracle: Install the OracleOCI8 extension and create a connection (servername, username, password). Practical case: Obtain MySQL data, PostgreSQL query, OracleOCI8 update record.
