Physical backups consist of raw copies of the directories and files that store database contents. This type of backup is suitable for large, important databases that need to be recovered quickly when problems occur.
Logical backups save information represented as logical database structure (CREATE DATABASE, CREATE TABLE statements) and content (INSERT statements or delimited-text files). This type of backup is suitable for smaller amounts of data where you might edit the data values or table structure, or recreate the data on a different machine architecture.
Mysqldump 8.0.26新版本引入新参数source-data,导出的时候会出现以下提醒: WARNING: --master-data is deprecated and will be removed in a future version. Use --source-data instead. 解决方法: [root@db01 ~]# mysqldump --user=root -p -A -R -E --triggers --flush-logs --set-gtid-purged=off --source-data=2 --single-transaction > /tmp/full.sql
使用mysql_config_editor绕过密码: [root@db01 ~]# mysql_config_editor set --login-path=root --user=root --password --host=localhost
参数说明: -A, --all-databases Dump all the databases. This will be same as --databases with all databases selected -B, --databases Dump several databases. Note the difference in usage; in this case no tables are given. All name arguments are regarded as database names. 'USE db_name;' will be included in the output. -E, --events Dump events. --log-error=name Append warnings and errors to given file. -R, --routines Dump stored routines (functions and procedures). --skip-opt Disable --opt. Disables --add-drop-table, --add-locks, --create-options, --quick, --extended-insert, --lock-tables, --set-charset, and --disable-keys.
--tables Overrides option --databases (-B). --triggers Dump triggers for each dumped table. (Defaults to on; use --skip-triggers to disable.) -l, --lock-tables Lock all tables for read. (Defaults to on; use --skip-lock-tables to disable.) --max-allowed-packet=# The maximum packet length to send to or receive from server. -i, --comments Write additional information. (Defaults to on; use --skip-comments to disable.) --add-drop-database Add a DROP DATABASE before each create. --add-drop-table Add a DROP TABLE before each create. (Defaults to on; use --skip-add-drop-table to disable.) --add-drop-trigger Add a DROP TRIGGER before each create. -t, --no-create-info Don't write table creation info. -d, --no-data No row information. --master-data[=#] This causes the binary log position and filename to be appended to the output. If equal to 1, will print it as a CHANGE MASTER command; if equal to 2, that command will be prefixed with a comment symbol. This option will turn --lock-all-tables on, unless --single-transaction is specified too (in which case a global read lock is only taken a short time at the beginning of the dump; don't forget to read about --single-transaction below). In all cases, any action on logs will happen at the exact moment of the dump. Option automatically turns --lock-tables off. --single-transaction Creates a consistent snapshot by dumping all tables in a single transaction. Works ONLY for tables stored in storage engines which support multiversioning (currently only InnoDB does); the dump is NOT guaranteed to be consistent for other storage engines. While a --single-transaction dump is in process, to ensure a valid dump file (correct table contents and binary log position), no other connection should use the following statements: ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE, as consistent snapshot is not isolated from them. Option automatically turns off --lock-tables. -F, --flush-logs Flush logs file in server before starting dump. Note that if you dump many databases at once (using the option --databases= or --all-databases), the logs will be flushed for each database dumped. The exception is when using --lock-all-tables or --master-data: in this case the logs will be flushed only once, corresponding to the moment all tables are locked. So if you want your dump and the log flush to happen at the same exact moment you should use --lock-all-tables or --master-data with --flush-logs.
解决办法: 从备份中找出创建mydb数据库语句,然后手工创建,然后重新导入: [root@db01 ~]# grep -i "^create database" /tmp/full.sql CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mydb` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
[root@db01 ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 66 Server version: 5.7.26-log MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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> CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mydb` /*!40100 DEFAULT CHARACTER SET utf8mb4 */; Query OK, 1 row affected (0.00 sec)
[root@db01 ~]# mysql --login-path=root --one-database mydb < /tmp/full.sql
mysql> use mydb Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
Database changed mysql> show tables; +----------------+ | Tables_in_mydb | +----------------+ | t | | t1 | | test | +----------------+ 3 rows in set (0.00 sec)
方法二:从备份文件中提取单库数据恢复
(1) 生成mydb脚本 [root@db01 ~]# sed -n '/^-- Current Database: `mydb`/,/^-- Current Database: `/p' /tmp/full.sql > /tmp/mydb.sql
(2) 添加时区 [root@db01 ~]# vim /tmp/mydb.sql -- Current Database: `mydb` --
set session TIME_ZONE='+00:00';
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mydb` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
从全备文件/tmp/full.sql中 SET @@GLOBAL.GTID_PURGED='d5d29a37-ace6-11eb-9949-000c29bdd3e5:1-34',可知1-34事务已全备 从binlog分析可知,GTID:35和GTID:37需要恢复的数据,而GTID:36是delete数据,需要跳过此步: SET @@SESSION.GTID_NEXT= 'd5d29a37-ace6-11eb-9949-000c29bdd3e5:35' SET @@SESSION.GTID_NEXT= 'd5d29a37-ace6-11eb-9949-000c29bdd3e5:37' SET @@SESSION.GTID_NEXT= 'd5d29a37-ace6-11eb-9949-000c29bdd3e5:36'
先从全备中恢复t表: [root@db01 ~]# mysql -uroot -p --one-database mydb < /tmp/full.sql Enter password: ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty.
A high-performance event-loop library used in asynchronous network applications.
libgcrypt
A general-purpose cryptographic library providing encryption, decryption, and hashing algorithms.
openssl
A robust library for implementing SSL/TLS encryption and cryptographic functions.
zlib
A compression library that supports data compression and decompression using the DEFLATE algorithm.
libaio
A library for asynchronous I/O operations, providing non-blocking I/O functionality.
If yum reports missing dependencies, it may offer to install them automatically. If not, you can install these dependencies manually using the following example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[root@server soft]# yum install libev libgcrypt openssl zlib libaio Trying other mirror. No package libev available. Package libgcrypt-1.5.3-14.el7.x86_64 already installed and latest version Package matching 1:openssl-1.0.2k-16.el7.x86_64 already installed. Checking for update. Package zlib-1.2.7-18.el7.x86_64 already installed and latest version Package libaio-0.3.109-13.el7.x86_64 already installed and latest version Nothing to do
温馨提示: 安装percona-xtrabackup-80-8.0.32-26版本,提示缺失zstd依赖包: Error: Package: percona-xtrabackup-80-8.0.34-29.1.el7.x86_64 (/percona-xtrabackup-80-8.0.34-29.1.el7.x86_64) Requires: zstd You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest
IMPORTANT: Please check that the backup run completes successfully. At the end of a successful backup run innobackupex prints "completed OK!".
210713 16:00:37 version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup' as 'root' (using password: YES). Failed to connect to MySQL server: DBI connect(';mysql_read_default_group=xtrabackup','root',...) failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) at - line 1314. 210713 16:00:37 Connecting to MySQL server host: localhost, user: root, password: set, port: not set, socket: not set Failed to connect to MySQL server: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)