1、连输mysql,查看mysql版本:
[mysql@mysql binlog]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.39-log Source distribution
Copyright (c) 2000, 2018, 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> select version();
+------------+
| version() |
+------------+
| 5.6.39-log |
+------------+
1 row in set (0.00 sec)
2、查询当前mysql的所有binlog日志
mysql> show master logs ;
+---------------+-----------+
| Log_name | File_size |
+---------------+-----------+
| binlog.000001 | 164 |
| binlog.000002 | 120 |
+---------------+-----------+
2 rows in set (0.00 sec)
3、创建测试表
mysql> show databases ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| jfedu |
| mysql |
| performance_schema |
| test |
| zhjsdb01 |
+--------------------+
6 rows in set (0.00 sec)
mysql> use test ;
Database changed
mysql> show tables ;
Empty set (0.00 sec)
mysql> create table test001(id int,name varchar(10));
Query OK, 0 rows affected (0.07 sec)
mysql> show master logs ;
+---------------+-----------+
| Log_name | File_size |
+---------------+-----------+
| binlog.000001 | 592 |
+---------------+-----------+
1 row in set (0.00 sec)
4、为了我们便于测试,清理掉历史binlog日志,从新开始
mysql> reset master;
Query OK, 0 rows affected (0.00 sec)
mysql> show master logs ;
+---------------+-----------+
| Log_name | File_size |
+---------------+-----------+
| binlog.000001 | 120 |
+---------------+-----------+
1 row in set (0.00 sec)
5、此时开始在表中插入两条初始数据:
mysql> insert into test001 values(1,'AAAA');
Query OK, 1 row affected (0.00 sec)
mysql> insert into test001 values(2,'BBBB');
Query OK, 1 row affected (0.00 sec)
mysql> select * from test001 ;
+------+------+
| id | name |
+------+------+
| 1 | AAAA |
| 2 | BBBB |
+------+------+
2 rows in set (0.00 sec)
6、然后就可以使用xtrabackup进行备份了:
[root@mysql xtrabackup]# innobackupex \
> --defaults-file=/u01/my3306/my.cnf \
> --user=root \
> --password='root123' \
> --socket=/u01/my3306/run/mysql.sock \
> --no-timestamp \
> /apps/backup/xtrabackup
--defaults-file 表示备份使用的配置文件,我这边就是我mysql数据库的配置文件;
--user和--password指定备份使用的mysql用户及密码;
--socket指定mysql的socket文件;
--no-timestamp表示备份目录自定义,不使用系统默认;
/apps/backup/xtrabackup表示备份文件产生在此目录中;
[root@mysql xtrabackup]# innobackupex \
> --defaults-file=/u01/my3306/my.cnf \
> --user=root \
> --password='root123' \
> --socket=/u01/my3306/run/mysql.sock \
> --no-timestamp \
> /apps/backup/xtrabackup
xtrabackup: recognized server arguments: --datadir=/u01/my3306/data --open_files_limit=65535 --server-id=101 --tmpdir=/u01/my3306/tmp --log_bin=/u01/my3306/log/binlog/binlog --innodb_data_home_dir=/u01/my3306/log/iblog --innodb_log_group_home_dir=/u01/my3306/log/iblog --innodb_adaptive_hash_index=1 --innodb_checksums=1 --innodb_buffer_pool_size=128M --innodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextend --innodb_doublewrite=1 --innodb_file_per_table=1 --innodb_flush_log_at_trx_commit=1 --innodb_flush_method=O_DIRECT --innodb_io_capacity=1000 --innodb_log_buffer_size=67108864 --innodb_log_file_size=1048576000 --innodb_log_files_in_group=4 --innodb_max_dirty_pages_pct=60 --innodb_open_files=60000 --innodb_read_io_threads=4 --innodb_use_native_aio=0 --innodb_write_io_threads=10
xtrabackup: recognized client arguments: --datadir=/u01/my3306/data --open_files_limit=65535 --server-id=101 --tmpdir=/u01/my3306/tmp --log_bin=/u01/my3306/log/binlog/binlog --innodb_data_home_dir=/u01/my3306/log/iblog --innodb_log_group_home_dir=/u01/my3306/log/iblog --innodb_adaptive_hash_index=1 --innodb_checksums=1 --innodb_buffer_pool_size=128M --innodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextend --innodb_doublewrite=1 --innodb_file_per_table=1 --innodb_flush_log_at_trx_commit=1 --innodb_flush_method=O_DIRECT --innodb_io_capacity=1000 --innodb_log_buffer_size=67108864 --innodb_log_file_size=1048576000 --innodb_log_files_in_group=4 --innodb_max_dirty_pages_pct=60 --innodb_open_files=60000 --innodb_read_io_threads=4 --innodb_use_native_aio=0 --innodb_write_io_threads=10
180624 19:01:54 innobackupex: Starting the backup operation
IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex
prints "completed OK!".
180624 19:01:54 version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup;port=3306;mysql_socket=/u01/my3306/run/mysql.sock' as 'root' (using password: YES).
180624 19:01:54 version_check Connected to MySQL server
180624 19:01:54 version_check Executing a version check against the server...
180624 19:01:54 version_check Done.
180624 19:01:54 Connecting to MySQL server host: localhost, user: root, password: set, port: 3306, socket: /u01/my3306/run/mysql.sock
Using server version 5.6.39-log
innobackupex version 2.4.12 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 170eb8c)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /u01/my3306/data
xtrabackup: open files limit requested 65535, set to 65535
xtrabackup: using the following InnoDB configuration:
xtrabackup: innodb_data_home_dir = /u01/my3306/log/iblog
xtrabackup: innodb_data_file_path = ibdata1:32M;ibdata2:16M:autoextend
xtrabackup: innodb_log_group_home_dir = /u01/my3306/log/iblog
xtrabackup: innodb_log_files_in_group = 4
xtrabackup: innodb_log_file_size = 1048576000
xtrabackup: using O_DIRECT
InnoDB: Number of pools: 1
180624 19:01:54 >> log scanned up to (2848651)
xtrabackup: Generating a list of tablespaces
InnoDB: Allocated tablespace ID 3 for mysql/slave_relay_log_info, old maximum was 0
180624 19:01:55 [01] Copying /u01/my3306/log/iblog/ibdata1 to /apps/backup/xtrabackup/ibdata1
180624 19:01:55 [01] ...done
180624 19:01:55 [01] Copying /u01/my3306/log/iblog/ibdata2 to /apps/backup/xtrabackup/ibdata2
180624 19:01:55 [01] ...done
180624 19:01:55 [01] Copying ./mysql/slave_relay_log_info.ibd to /apps/backup/xtrabackup/mysql/slave_relay_log_info.ibd
180624 19:01:55 [01] ...done
180624 19:01:55 [01] Copying ./mysql/innodb_index_stats.ibd to /apps/backup/xtrabackup/mysql/innodb_index_stats.ibd
180624 19:01:55 [01] ...done
180624 19:01:55 [01] Copying ./mysql/slave_master_info.ibd to /apps/backup/xtrabackup/mysql/slave_master_info.ibd
180624 19:01:55 [01] ...done
180624 19:01:55 [01] Copying ./mysql/innodb_table_stats.ibd to /apps/backup/xtrabackup/mysql/innodb_table_stats.ibd
180624 19:01:55 [01] ...done
180624 19:01:55 [01] Copying ./mysql/slave_worker_info.ibd to /apps/backup/xtrabackup/mysql/slave_worker_info.ibd
180624 19:01:55 [01] ...done
180624 19:01:55 [01] Copying ./test/test001.ibd to /apps/backup/xtrabackup/test/test001.ibd
180624 19:01:55 [01] ...done
180624 19:01:55 [01] Copying ./jfedu/t2_bak.ibd to /apps/backup/xtrabackup/jfedu/t2_bak.ibd
180624 19:01:55 [01] ...done
180624 19:01:55 [01] Copying ./zhjsdb01/test01.ibd to /apps/backup/xtrabackup/zhjsdb01/test01.ibd
180624 19:01:55 [01] ...done
180624 19:01:55 >> log scanned up to (2848651)
180624 19:01:56 Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
180624 19:01:56 Executing FLUSH TABLES WITH READ LOCK...
180624 19:01:56 Starting to backup non-InnoDB tables and files
180624 19:01:56 [01] Copying ./mysql/time_zone_transition_type.MYI to /apps/backup/xtrabackup/mysql/time_zone_transition_type.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/proc.MYD to /apps/backup/xtrabackup/mysql/proc.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone.frm to /apps/backup/xtrabackup/mysql/time_zone.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/procs_priv.frm to /apps/backup/xtrabackup/mysql/procs_priv.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/help_category.frm to /apps/backup/xtrabackup/mysql/help_category.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/help_category.MYI to /apps/backup/xtrabackup/mysql/help_category.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/innodb_table_stats.frm to /apps/backup/xtrabackup/mysql/innodb_table_stats.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/slow_log.CSV to /apps/backup/xtrabackup/mysql/slow_log.CSV
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone_transition.frm to /apps/backup/xtrabackup/mysql/time_zone_transition.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/ndb_binlog_index.MYD to /apps/backup/xtrabackup/mysql/ndb_binlog_index.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/columns_priv.frm to /apps/backup/xtrabackup/mysql/columns_priv.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/help_relation.MYD to /apps/backup/xtrabackup/mysql/help_relation.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/plugin.MYD to /apps/backup/xtrabackup/mysql/plugin.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/user.MYI to /apps/backup/xtrabackup/mysql/user.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/user.MYD to /apps/backup/xtrabackup/mysql/user.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/help_category.MYD to /apps/backup/xtrabackup/mysql/help_category.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/slave_master_info.frm to /apps/backup/xtrabackup/mysql/slave_master_info.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone_leap_second.MYI to /apps/backup/xtrabackup/mysql/time_zone_leap_second.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/procs_priv.MYI to /apps/backup/xtrabackup/mysql/procs_priv.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/tables_priv.MYI to /apps/backup/xtrabackup/mysql/tables_priv.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone_name.MYD to /apps/backup/xtrabackup/mysql/time_zone_name.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/proc.MYI to /apps/backup/xtrabackup/mysql/proc.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/tables_priv.MYD to /apps/backup/xtrabackup/mysql/tables_priv.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone_transition_type.frm to /apps/backup/xtrabackup/mysql/time_zone_transition_type.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone_leap_second.frm to /apps/backup/xtrabackup/mysql/time_zone_leap_second.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/help_topic.MYI to /apps/backup/xtrabackup/mysql/help_topic.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/plugin.MYI to /apps/backup/xtrabackup/mysql/plugin.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/help_keyword.frm to /apps/backup/xtrabackup/mysql/help_keyword.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/db.frm to /apps/backup/xtrabackup/mysql/db.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone.MYD to /apps/backup/xtrabackup/mysql/time_zone.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/proxies_priv.frm to /apps/backup/xtrabackup/mysql/proxies_priv.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/slave_worker_info.frm to /apps/backup/xtrabackup/mysql/slave_worker_info.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/db.MYD to /apps/backup/xtrabackup/mysql/db.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/help_topic.MYD to /apps/backup/xtrabackup/mysql/help_topic.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone_name.frm to /apps/backup/xtrabackup/mysql/time_zone_name.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/ndb_binlog_index.frm to /apps/backup/xtrabackup/mysql/ndb_binlog_index.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/event.MYD to /apps/backup/xtrabackup/mysql/event.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/columns_priv.MYD to /apps/backup/xtrabackup/mysql/columns_priv.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/plugin.frm to /apps/backup/xtrabackup/mysql/plugin.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/event.frm to /apps/backup/xtrabackup/mysql/event.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/slow_log.frm to /apps/backup/xtrabackup/mysql/slow_log.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/slow_log.CSM to /apps/backup/xtrabackup/mysql/slow_log.CSM
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/db.MYI to /apps/backup/xtrabackup/mysql/db.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/ndb_binlog_index.MYI to /apps/backup/xtrabackup/mysql/ndb_binlog_index.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/help_relation.MYI to /apps/backup/xtrabackup/mysql/help_relation.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/func.MYI to /apps/backup/xtrabackup/mysql/func.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/help_relation.frm to /apps/backup/xtrabackup/mysql/help_relation.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/help_keyword.MYI to /apps/backup/xtrabackup/mysql/help_keyword.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/servers.MYD to /apps/backup/xtrabackup/mysql/servers.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/innodb_index_stats.frm to /apps/backup/xtrabackup/mysql/innodb_index_stats.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone.MYI to /apps/backup/xtrabackup/mysql/time_zone.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/func.frm to /apps/backup/xtrabackup/mysql/func.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/tables_priv.frm to /apps/backup/xtrabackup/mysql/tables_priv.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/help_keyword.MYD to /apps/backup/xtrabackup/mysql/help_keyword.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone_name.MYI to /apps/backup/xtrabackup/mysql/time_zone_name.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/proxies_priv.MYI to /apps/backup/xtrabackup/mysql/proxies_priv.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/user.frm to /apps/backup/xtrabackup/mysql/user.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/general_log.CSM to /apps/backup/xtrabackup/mysql/general_log.CSM
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone_transition.MYD to /apps/backup/xtrabackup/mysql/time_zone_transition.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/general_log.frm to /apps/backup/xtrabackup/mysql/general_log.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/columns_priv.MYI to /apps/backup/xtrabackup/mysql/columns_priv.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/slave_relay_log_info.frm to /apps/backup/xtrabackup/mysql/slave_relay_log_info.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/event.MYI to /apps/backup/xtrabackup/mysql/event.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/func.MYD to /apps/backup/xtrabackup/mysql/func.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone_transition_type.MYD to /apps/backup/xtrabackup/mysql/time_zone_transition_type.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/servers.frm to /apps/backup/xtrabackup/mysql/servers.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/help_topic.frm to /apps/backup/xtrabackup/mysql/help_topic.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone_leap_second.MYD to /apps/backup/xtrabackup/mysql/time_zone_leap_second.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/proc.frm to /apps/backup/xtrabackup/mysql/proc.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/servers.MYI to /apps/backup/xtrabackup/mysql/servers.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/proxies_priv.MYD to /apps/backup/xtrabackup/mysql/proxies_priv.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/general_log.CSV to /apps/backup/xtrabackup/mysql/general_log.CSV
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/procs_priv.MYD to /apps/backup/xtrabackup/mysql/procs_priv.MYD
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./mysql/time_zone_transition.MYI to /apps/backup/xtrabackup/mysql/time_zone_transition.MYI
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_waits_history_long.frm to /apps/backup/xtrabackup/performance_schema/events_waits_history_long.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_stages_summary_by_host_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_stages_summary_by_host_by_event_name.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_stages_summary_by_user_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_stages_summary_by_user_by_event_name.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_stages_summary_global_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_stages_summary_global_by_event_name.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/file_summary_by_instance.frm to /apps/backup/xtrabackup/performance_schema/file_summary_by_instance.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_waits_summary_by_account_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_waits_summary_by_account_by_event_name.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_stages_current.frm to /apps/backup/xtrabackup/performance_schema/events_stages_current.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/setup_actors.frm to /apps/backup/xtrabackup/performance_schema/setup_actors.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/setup_consumers.frm to /apps/backup/xtrabackup/performance_schema/setup_consumers.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_statements_history.frm to /apps/backup/xtrabackup/performance_schema/events_statements_history.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/setup_timers.frm to /apps/backup/xtrabackup/performance_schema/setup_timers.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_stages_history.frm to /apps/backup/xtrabackup/performance_schema/events_stages_history.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/threads.frm to /apps/backup/xtrabackup/performance_schema/threads.frm
180624 19:01:56 [01] ...done
180624 19:01:56 >> log scanned up to (2848651)
180624 19:01:56 [01] Copying ./performance_schema/socket_instances.frm to /apps/backup/xtrabackup/performance_schema/socket_instances.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/file_instances.frm to /apps/backup/xtrabackup/performance_schema/file_instances.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_waits_summary_by_thread_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_waits_summary_by_thread_by_event_name.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_statements_summary_by_user_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_statements_summary_by_user_by_event_name.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_statements_summary_by_account_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_statements_summary_by_account_by_event_name.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/performance_timers.frm to /apps/backup/xtrabackup/performance_schema/performance_timers.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/file_summary_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/file_summary_by_event_name.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/cond_instances.frm to /apps/backup/xtrabackup/performance_schema/cond_instances.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_stages_summary_by_account_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_stages_summary_by_account_by_event_name.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/table_io_waits_summary_by_index_usage.frm to /apps/backup/xtrabackup/performance_schema/table_io_waits_summary_by_index_usage.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/mutex_instances.frm to /apps/backup/xtrabackup/performance_schema/mutex_instances.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_statements_summary_by_digest.frm to /apps/backup/xtrabackup/performance_schema/events_statements_summary_by_digest.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_stages_summary_by_thread_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_stages_summary_by_thread_by_event_name.frm
180624 19:01:56 [01] ...done
180624 19:01:56 [01] Copying ./performance_schema/events_statements_current.frm to /apps/backup/xtrabackup/performance_schema/events_statements_current.frm
180624 19:01:56 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/setup_objects.frm to /apps/backup/xtrabackup/performance_schema/setup_objects.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/objects_summary_global_by_type.frm to /apps/backup/xtrabackup/performance_schema/objects_summary_global_by_type.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/socket_summary_by_instance.frm to /apps/backup/xtrabackup/performance_schema/socket_summary_by_instance.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/events_stages_history_long.frm to /apps/backup/xtrabackup/performance_schema/events_stages_history_long.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/events_waits_summary_by_user_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_waits_summary_by_user_by_event_name.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/events_statements_summary_by_thread_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_statements_summary_by_thread_by_event_name.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/events_waits_history.frm to /apps/backup/xtrabackup/performance_schema/events_waits_history.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/db.opt to /apps/backup/xtrabackup/performance_schema/db.opt
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/table_lock_waits_summary_by_table.frm to /apps/backup/xtrabackup/performance_schema/table_lock_waits_summary_by_table.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/rwlock_instances.frm to /apps/backup/xtrabackup/performance_schema/rwlock_instances.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/events_statements_summary_by_host_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_statements_summary_by_host_by_event_name.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/host_cache.frm to /apps/backup/xtrabackup/performance_schema/host_cache.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/events_statements_summary_global_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_statements_summary_global_by_event_name.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/table_io_waits_summary_by_table.frm to /apps/backup/xtrabackup/performance_schema/table_io_waits_summary_by_table.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/setup_instruments.frm to /apps/backup/xtrabackup/performance_schema/setup_instruments.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/events_waits_summary_by_host_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_waits_summary_by_host_by_event_name.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/events_statements_history_long.frm to /apps/backup/xtrabackup/performance_schema/events_statements_history_long.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/events_waits_current.frm to /apps/backup/xtrabackup/performance_schema/events_waits_current.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/events_waits_summary_global_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/events_waits_summary_global_by_event_name.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/events_waits_summary_by_instance.frm to /apps/backup/xtrabackup/performance_schema/events_waits_summary_by_instance.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/socket_summary_by_event_name.frm to /apps/backup/xtrabackup/performance_schema/socket_summary_by_event_name.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/session_account_connect_attrs.frm to /apps/backup/xtrabackup/performance_schema/session_account_connect_attrs.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/users.frm to /apps/backup/xtrabackup/performance_schema/users.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/session_connect_attrs.frm to /apps/backup/xtrabackup/performance_schema/session_connect_attrs.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/hosts.frm to /apps/backup/xtrabackup/performance_schema/hosts.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./performance_schema/accounts.frm to /apps/backup/xtrabackup/performance_schema/accounts.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./test/test001.frm to /apps/backup/xtrabackup/test/test001.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./test/db.opt to /apps/backup/xtrabackup/test/db.opt
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./jfedu/t2_bak.frm to /apps/backup/xtrabackup/jfedu/t2_bak.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./jfedu/db.opt to /apps/backup/xtrabackup/jfedu/db.opt
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./zhjsdb01/v_test01.frm to /apps/backup/xtrabackup/zhjsdb01/v_test01.frm
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./zhjsdb01/db.opt to /apps/backup/xtrabackup/zhjsdb01/db.opt
180624 19:01:57 [01] ...done
180624 19:01:57 [01] Copying ./zhjsdb01/test01.frm to /apps/backup/xtrabackup/zhjsdb01/test01.frm
180624 19:01:57 [01] ...done
180624 19:01:57 Finished backing up non-InnoDB tables and files
180624 19:01:57 [00] Writing /apps/backup/xtrabackup/xtrabackup_binlog_info
180624 19:01:57 [00] ...done
180624 19:01:57 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
xtrabackup: The latest check point (for incremental): '2848651'
xtrabackup: Stopping log copying thread.
.180624 19:01:57 >> log scanned up to (2848651)
180624 19:01:57 Executing UNLOCK TABLES
180624 19:01:57 All tables unlocked
180624 19:01:57 Backup created in directory '/apps/backup/xtrabackup/'
MySQL binlog position: filename 'binlog.000001', position '522'
180624 19:01:57 [00] Writing /apps/backup/xtrabackup/backup-my.cnf
180624 19:01:57 [00] ...done
180624 19:01:57 [00] Writing /apps/backup/xtrabackup/xtrabackup_info
180624 19:01:57 [00] ...done
xtrabackup: Transaction log of lsn (2848651) to (2848651) was copied.
180624 19:01:57 completed OK!
[root@mysql xtrabackup]#
7、全备完成后,我们在进行数据变动,备份完成的变动后面就需要通过binlog日志进行恢复了。
mysql> insert into test001 values(3,'CCCCC');
Query OK, 1 row affected (0.00 sec)
mysql> select * from test001 ;
+------+-------+
| id | name |
+------+-------+
| 1 | AAAA |
| 2 | BBBB |
| 3 | CCCCC |
+------+-------+
3 rows in set (0.00 sec)
8、下面就可以进行数据库误操作了,我们可以把数据库文件全部清掉。
查看下当前数据库文件位置
mysql> show variables like '%datadir%';
+---------------+-------------------+
| Variable_name | Value |
+---------------+-------------------+
| datadir | /u01/my3306/data/ |
+---------------+-------------------+
1 row in set (0.00 sec)
然后直接rm -rf掉:
[root@mysql ~]# cd /u01/my3306/data/
[root@mysql data]# ll
总用量 4157484
-rw-rw----. 1 mysql mysql 56 6月 23 23:50 auto.cnf
-rw-r-----. 1 mysql mysql 497 6月 23 23:49 backup-my.cnf
-rw-r-----. 1 mysql mysql 33554432 6月 23 23:49 ibdata1
-rw-r-----. 1 mysql mysql 16777216 6月 23 23:49 ibdata2
-rw-r-----. 1 mysql mysql 1048576000 6月 23 23:49 ib_logfile0
-rw-r-----. 1 mysql mysql 1048576000 6月 23 23:49 ib_logfile1
-rw-r-----. 1 mysql mysql 1048576000 6月 23 23:49 ib_logfile2
-rw-r-----. 1 mysql mysql 1048576000 6月 23 23:50 ib_logfile3
-rw-r-----. 1 mysql mysql 12582912 6月 23 23:50 ibtmp1
drwxr-x---. 2 mysql mysql 4096 6月 23 23:50 jfedu
drwxr-x---. 2 mysql mysql 4096 6月 23 23:50 mysql
drwxr-x---. 2 mysql mysql 4096 6月 23 23:50 performance_schema
drwxr-x---. 2 mysql mysql 4096 6月 24 18:59 test
drwxr-x---. 2 mysql mysql 4096 6月 23 23:50 zhjsdb01
[root@mysql data]# rm -rf *
[root@mysql data]# ll
总用量 0
清的很彻底,一点不剩。
注意我的binlog日志并在该数据文件目录,是单独存放的,如果binlog日志在此目录,还要主要不要把binlog日志给清掉了。
9、下面就可以进行恢复了:
开始恢复前先应用日志:
[root@mysql data]# innobackupex --defaults-file=/apps/backup/xtrabackup/backup-my.cnf --apply-log --user=root --password='root123' /apps/backup/xtrabackup
--defaults-file:要指定备份集产生的配置文件,这个地方要注意;
--apply-log:表示要应用日志,把备份集的lsn恢复到一致性的状态;
最后的目录指定了备份集的位置;
这里有必要说明一下,使用xtrabackup备份的时候,在备份期间,假如备份在晚上10:00:00开始,备份用了半个小时,在10:30:00(时:分:秒),那么在这备份的半个小时以内,还是会有一些业务数据的变动,xtrabackup怎么解决前面备份的lsn跟后面的不一致呢?它也会产生日志,这个日志就是记录的在这个时间段所有的数据变动,那么等到恢复的时候,执行--apply-log就是对产生的备份集,进行日志(这个日志是xtrabackup产生额外记录的,并不是mysql自己的binlog日志)应用,把所有的page(可以理解成oracle里面的block块)的lsn都弄到一致状态,也就是把备份集恢复到最终在10:30:00这个时刻的状态。
[root@mysql data]# innobackupex --defaults-file=/apps/backup/xtrabackup/backup-my.cnf --apply-log --user=root --password='root123' /apps/backup/xtrabackup
xtrabackup: recognized server arguments: --innodb_checksum_algorithm=innodb --innodb_log_checksum_algorithm=innodb --innodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextend --innodb_log_files_in_group=4 --innodb_log_file_size=1048576000 --innodb_fast_checksum=0 --innodb_page_size=16384 --innodb_log_block_size=512 --innodb_undo_directory=. --innodb_undo_tablespaces=0 --server-id=101 --redo-log-version=0
xtrabackup: recognized client arguments: --innodb_checksum_algorithm=innodb --innodb_log_checksum_algorithm=innodb --innodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextend --innodb_log_files_in_group=4 --innodb_log_file_size=1048576000 --innodb_fast_checksum=0 --innodb_page_size=16384 --innodb_log_block_size=512 --innodb_undo_directory=. --innodb_undo_tablespaces=0 --server-id=101 --redo-log-version=0
180624 19:06:11 innobackupex: Starting the apply-log operation
IMPORTANT: Please check that the apply-log run completes successfully.
At the end of a successful apply-log run innobackupex
prints "completed OK!".
innobackupex version 2.4.12 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 170eb8c)
xtrabackup: cd to /apps/backup/xtrabackup/
xtrabackup: This target seems to be not prepared yet.
InnoDB: Number of pools: 1
xtrabackup: xtrabackup_logfile detected: size=8388608, start_lsn=(2848651)
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:32M;ibdata2:16M:autoextend
xtrabackup: innodb_log_group_home_dir = .
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 8388608
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:32M;ibdata2:16M:autoextend
xtrabackup: innodb_log_group_home_dir = .
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 8388608
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: PUNCH HOLE support available
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Uses event mutexes
InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Number of pools: 1
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M
InnoDB: Completed initialization of buffer pool
InnoDB: page_cleaner coordinator priority: -20
InnoDB: Highest supported file format is Barracuda.
InnoDB: The log sequence number 2799158 in the system tablespace does not match the log sequence number 2848651 in the ib_logfiles!
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: xtrabackup: Last MySQL binlog file position 522, file name binlog.000001
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
InnoDB: File './ibtmp1' size is now 12 MB.
InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
InnoDB: 32 non-redo rollback segment(s) are active.
InnoDB: 5.7.19 started; log sequence number 2848651
InnoDB: xtrabackup: Last MySQL binlog file position 522, file name binlog.000001
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 2851939
InnoDB: Number of pools: 1
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:32M;ibdata2:16M:autoextend
xtrabackup: innodb_log_group_home_dir = .
xtrabackup: innodb_log_files_in_group = 4
xtrabackup: innodb_log_file_size = 1048576000
InnoDB: PUNCH HOLE support available
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Uses event mutexes
InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Number of pools: 1
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M
InnoDB: Completed initialization of buffer pool
InnoDB: page_cleaner coordinator priority: -20
InnoDB: Setting log file ./ib_logfile101 size to 1000 MB
InnoDB: Progress in MB:
100 200 300 400 500 600 700 800 900 1000
InnoDB: Setting log file ./ib_logfile1 size to 1000 MB
InnoDB: Progress in MB:
100 200 300 400 500 600 700 800 900 1000
InnoDB: Setting log file ./ib_logfile2 size to 1000 MB
InnoDB: Progress in MB:
100 200 300 400 500 600 700 800 900 1000
InnoDB: Setting log file ./ib_logfile3 size to 1000 MB
InnoDB: Progress in MB:
100 200 300 400 500 600 700 800 900 1000
InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
InnoDB: New log files created, LSN=2851939
InnoDB: Highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 2852364
InnoDB: Doing recovery: scanned up to log sequence number 2852373 (0%)
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: xtrabackup: Last MySQL binlog file position 522, file name binlog.000001
InnoDB: Removed temporary tablespace data file: "ibtmp1"
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
InnoDB: File './ibtmp1' size is now 12 MB.
InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
InnoDB: 32 non-redo rollback segment(s) are active.
InnoDB: page_cleaner: 1000ms intended loop took 40659ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.)
InnoDB: 5.7.19 started; log sequence number 2852373
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 2852392
180624 19:06:55 completed OK!
[root@mysql data]#
10、然后把具有lsn一致性的备份集直接拷贝到原mysql的data目录中区:
[root@mysql ~]# cp -fr /apps/backup/xtrabackup/* /u01/my3306/data
[root@mysql ~]# chown -R mysql:mysql /u01/my3306/data/
11、进行到此,原来mysql服务并没有停止,我们需要停止,然后在起来:
查看当前mysql服务:
[root@mysql ~]# ps -ef|grep mysql
root 3400 2146 0 13:19 pts/0 00:00:00 su - mysql
mysql 3401 3400 0 13:19 pts/0 00:00:00 -bash
mysql 3435 1 0 13:20 pts/0 00:00:00 /bin/sh /u01/my3306/bin/mysqld_safe --defaults-file=/u01/my3306/my.cnf --user=mysql
mysql 4288 3435 0 13:20 pts/0 00:00:03 /u01/my3306/bin/mysqld --defaults-file=/u01/my3306/my.cnf --basedir=/u01/my3306 --datadir=/u01/my3306/data --plugin-dir=/u01/my3306/lib/plugin --log-error=/u01/my3306/log/error.log --open-files-limit=65535 --pid-file=/u01/my3306/run/mysqld.pid --socket=/u01/my3306/run/mysql.sock --port=3306
mysql 4325 3401 0 13:20 pts/0 00:00:00 mysql -uroot -p
root 4416 3343 0 13:47 pts/1 00:00:00 su - mysql
mysql 4417 4416 0 13:47 pts/1 00:00:00 -bash
mysql 5007 4417 0 18:40 pts/1 00:00:00 mysql -uroot -p
root 5183 5159 0 19:07 pts/4 00:00:00 grep mysql
停服务:
[root@mysql ~]# su - mysql
[mysql@mysql ~]$ cd /u01/my3306/
[mysql@mysql my3306]$ ls
bin data lib my.cnf README share stop_mysqld.sh wf_backup
connect_mysql.sh docs log my-new.cnf run sql-bench support-files
COPYING include man mysql-test scripts start_mysqld.sh tmp
[mysql@mysql my3306]$ ./stop_mysqld.sh
Warning: Using a password on the command line interface can be insecure.
[mysql@mysql my3306]$ ps -ef|grep mysql
root 3400 2146 0 13:19 pts/0 00:00:00 su - mysql
mysql 3401 3400 0 13:19 pts/0 00:00:00 -bash
mysql 4325 3401 0 13:20 pts/0 00:00:00 mysql -uroot -p
root 4416 3343 0 13:47 pts/1 00:00:00 su - mysql
mysql 4417 4416 0 13:47 pts/1 00:00:00 -bash
mysql 5007 4417 0 18:40 pts/1 00:00:00 mysql -uroot -p
root 5185 5159 0 19:08 pts/4 00:00:00 su - mysql
mysql 5186 5185 0 19:08 pts/4 00:00:00 -bash
mysql 5216 5186 1 19:08 pts/4 00:00:00 ps -ef
mysql 5217 5186 0 19:08 pts/4 00:00:00 grep mysql
在重新起服务:
[mysql@mysql my3306]$ ./start_mysqld.sh
[mysql@mysql my3306]$ 180624 19:09:11 mysqld_safe Logging to '/u01/my3306/log/error.log'.
180624 19:09:11 mysqld_safe Starting mysqld daemon with databases from /u01/my3306/data
[mysql@mysql my3306]$ ps -ef|grep mysql
mysql 5219 1 0 19:09 pts/4 00:00:00 /bin/sh /u01/my3306/bin/mysqld_safe --defaults-file=/u01/my3306/my.cnf --user=mysql
mysql 6072 5219 0 19:09 pts/4 00:00:00 /u01/my3306/bin/mysqld --defaults-file=/u01/my3306/my.cnf --basedir=/u01/my3306 --datadir=/u01/my3306/data --plugin-dir=/u01/my3306/lib/plugin --log-error=/u01/my3306/log/error.log --open-files-limit=65535 --pid-file=/u01/my3306/run/mysqld.pid --socket=/u01/my3306/run/mysql.sock --port=3306
12、此时我们来验证一下数据:
mysql> select * from test001 ;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 1
Current database: test
+------+------+
| id | name |
+------+------+
| 1 | AAAA |
| 2 | BBBB |
+------+------+
2 rows in set (0.04 sec)
上面的报错是因为我我们中间停过一次库,所以原来的连接断了自己重连了。
这里的数据只是我们做全备之前的,并没有我们做全备之后的那条id是3,name是CCCCC的数据。
后面我们将利用binlog日志进行全备之后的数据恢复。
13、我们的目标应该是要找到在备份之后做的产生的日志的pos点。因为我们这边总共就两个日志,很好找,我们可以全量的找。
先看下当前所有日志的情况:
mysql> show master logs ;
+---------------+-----------+
| Log_name | File_size |
+---------------+-----------+
| binlog.000001 | 747 |
| binlog.000002 | 120 |
+---------------+-----------+
2 rows in set (0.00 sec)
mysql> show master status ;
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000002 | 120 | | | |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
目前一共两个日志,binlog.000002是当前日志。
对这 两个日志进行格式化输出:
[root@mysql ~]# su - mysql
[mysql@mysql ~]$ cd /u01/my3306/log/binlog
[mysql@mysql binlog]$ ls
binlog.000001 binlog.000002 binlog.index
[mysql@mysql binlog]$ mysqlbinlog --base64-output=decode-rows -vv /u01/my3306/log/binlog/binlog.000001 /u01/my3306/log/binlog/binlog.000002 >/tmp/1.sql
[mysql@mysql binlog]$
我们指定两个日志文件:binlog.000001,binlog.000002进行格式化输出,输出内容写到/tmp/1.sql文件中,我们可以看下/tmp/1.sql文件:
[mysql@mysql binlog]$ view /tmp/1.sql
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#180624 19:00:23 server id 101 end_log_pos 120 CRC32 0x8fb4ae18 Start: binlog v 4, server v 5.6.39-log created 180624 19:00:23 at startup
ROLLBACK/*!*/;
# at 120
#180624 19:00:40 server id 101 end_log_pos 192 CRC32 0x2a058264 Query thread_id=7 exec_time=0 error_code=0
SET TIMESTAMP=1529838040/*!*/;
SET @@session.pseudo_thread_id=7/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1073741824/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
# at 192 #开始事务号,这个是第一次插入AAAA的记录的时候的事务
#180624 19:00:40 server id 101 end_log_pos 245 CRC32 0xc922724c Table_map: `test`.`test001` mapped to number 77
# at 245
#180624 19:00:40 server id 101 end_log_pos 290 CRC32 0x8123baef Write_rows: table id 77 flags: STMT_END_F
### INSERT INTO `test`.`test001`
### SET
### @1=1 /* INT meta=0 nullable=1 is_null=0 */
### @2='AAAA' /* VARSTRING(10) meta=10 nullable=1 is_null=0 */ #这边可以看到插入的两个字段值,1和'AAAA'
# at 290
#180624 19:00:40 server id 101 end_log_pos 321 CRC32 0x1878a6e6 Xid = 147
COMMIT/*!*/; #事务结束,自动提交
# at 321
#180624 19:00:46 server id 101 end_log_pos 393 CRC32 0xaae2b9c3 Query thread_id=7 exec_time=0 error_code=0
SET TIMESTAMP=1529838046/*!*/;
BEGIN
/*!*/;
# at 393 #插入第二条记录的事务开始号
#180624 19:00:46 server id 101 end_log_pos 446 CRC32 0xb429c44e Table_map: `test`.`test001` mapped to number 77
# at 446
#180624 19:00:46 server id 101 end_log_pos 491 CRC32 0xbc0020d4 Write_rows: table id 77 flags: STMT_END_F
### INSERT INTO `test`.`test001`
### SET
### @1=2 /* INT meta=0 nullable=1 is_null=0 */ #看到插入的记录的两个字段值2和'BBBB'
### @2='BBBB' /* VARSTRING(10) meta=10 nullable=1 is_null=0 */
# at 491
#180624 19:00:46 server id 101 end_log_pos 522 CRC32 0x1daf52ea Xid = 148
COMMIT/*!*/; #第二个事务自动提交结束
# at 522
#180624 19:04:56 server id 101 end_log_pos 594 CRC32 0x6c807299 Query thread_id=7 exec_time=0 error_code=0
SET TIMESTAMP=1529838296/*!*/;
BEGIN
/*!*/;
# at 594 #插入第三条记录的开始事务号 这个就是全备以后日志起始地方,要记住,后面恢复要用
#180624 19:04:56 server id 101 end_log_pos 647 CRC32 0x48614ae6 Table_map: `test`.`test001` mapped to number 81
# at 647
#180624 19:04:56 server id 101 end_log_pos 693 CRC32 0x01ea9114 Write_rows: table id 81 flags: STMT_END_F
### INSERT INTO `test`.`test001`
### SET
### @1=3 /* INT meta=0 nullable=1 is_null=0 */ #可以看到插入的两个字段值3和'CCCCC',也就是我们全备后的日志开始的地方
### @2='CCCCC' /* VARSTRING(10) meta=10 nullable=1 is_null=0 */
# at 693
#180624 19:04:56 server id 101 end_log_pos 724 CRC32 0x228ad586 Xid = 169
COMMIT/*!*/; #第三个事务结束,自动提交了
# at 724
#180624 19:08:40 server id 101 end_log_pos 747 CRC32 0xe850edf9 Stop
# at 4 #这个地方日志的pos开始变小了,说明日志切换了,这个pos是00002日志里面的位置
#180624 19:09:11 server id 101 end_log_pos 120 CRC32 0x0fd01ca0 Start: binlog v 4, server v 5.6.39-log created 180624 19:09:11 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[mysql@mysql binlog]$
由此可见,我们需要回复的应该是在pos=594开始的事务以及以后的日志记录。
[root@mysql ~]# su - mysql
[mysql@mysql ~]$ mysqlbinlog /u01/my3306/log/binlog/binlog.000001 /u01/my3306/log/binlog/binlog.000002 --start-position=594 --stop-position=4 > /tmp/2.sql
其中
--start-position=594表示是从binlog.000001日志的pos=594的地方开始恢复;
--stop-position=4表示是恢复停止于binlog.000002日志的pos=4的地方;
日志规整后输出到/tmp/2.sql文件中,后面我们将直接利用这个文件进行恢复。
14、恢复:
[mysql@mysql ~]$ mysql -uroot -proot123 < /tmp/2.sql
Warning: Using a password on the command line interface can be insecure.
[mysql@mysql ~]$
15、恢复完成后,我们去查看下测试表数据是否回来了:
mysql> select * from test001 ;
+------+-------+
| id | name |
+------+-------+
| 1 | AAAA |
| 2 | BBBB |
| 3 | CCCCC |
+------+-------+
3 rows in set (0.00 sec)
mysql>
发现数据已经回来了。
16、关于binlog开启说明:
5.6和5.7版本的MySQL,有个参数binlog_row_image,默认值为FULL,表示记录的是全部的binlog操作日志(仅在binlog_format=ROW时候生效)。此外binlog_row_image还可以是minimal,表示binlog记录的就只是影响后的行。如此一来使用ROW格式就能节约很多的磁盘空间。
mysql> show variables like '%log%' ;
+-----------------------------------------+-------------------------------------+
| Variable_name | Value |
+-----------------------------------------+-------------------------------------+
| binlog_format | ROW |
| binlog_row_image | FULL |
上面是截取的指定两条,是默认的情况。