binlog_format=row;二进制日志的格式。maser上最好还设置sync_binlog=1 和 innodb_flush_log_at_trx_commit=1防止发生服务器崩溃时
1. 利用mysqldump进行逻辑备份
1
2
3
4
5
6
7
8
9
|
[root
@localhost
~]# mysqldump -uroot -p --routines --flush-logs --master-data=
2
--databases db2 db1>/root/backup.sql
Enter password:
[root
@localhost
~]# scp /root/backup.sql
192.168
.
137.9
:/tmp/backup.sql
The authenticity of host
'192.168.137.9 (192.168.137.9)'
can't be established.
RSA key fingerprint is a4:cd:c0:
13
:d1:8c:c0:a5:e7:c4:
43
:b5:
95
:
17
:af:d3.
Are you sure you want to
continue
connecting (yes/no)? yes
Warning: Permanently added
'192.168.137.9'
(RSA) to the list of known hosts.
root
@192
.168.
137.9
's password:
backup.sql
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root
@localhost
~]# head -
50
/tmp/backup.sql
......
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */
;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */
;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */
;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */
;
--
-- Position to start replication or point-in-time recovery from
--
-- CHANGE MASTER TO MASTER_LOG_FILE=
'mysql-bin.000010'
, MASTER_LOG_POS=
809
;
|
1
2
3
4
5
6
7
8
9
|
[root
@localhost
~]# head -n
50
gs_ngx_lua_backup.sql
-- MySQL dump
10.13
Distrib
5.6
.
26
,
for
linux-glibc2.
5
(i686)
--
-- Host: localhost Database: gs
... ...--
-- Position to start replication or point-in-time recovery from
--
-- CHANGE MASTER TO MASTER_LOG_FILE=
'mysql-bin.000027'
, MASTER_LOG_POS=
120
;
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
mysql> delete from user where id=
5
;
Query OK,
1
row affected (
0.02
sec)
mysql> select * from user;
+----+----------+------+-------------+----------+
| id | name| sex | phone | addr|
+----+----------+------+-------------+----------+
|
1
| yuanfang |
1
|
14465463786
| hangzhou |
|
2
| Andy|
0
|
14465463786
| beijing |
|
3
| peter |
0
|
14465463786
| Hongkong |
|
4
| lexin |
1
|
36565634
| shenzhen |
+----+----------+------+-------------+----------+
4
rows in set (
0.00
sec)
mysql> flush logs;
Query OK,
0
rows affected (
0.11
sec)
mysql> show binary logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.
000027
|
370
|
| mysql-bin.
000028
|
120
|
+------------------+-----------+
2
rows in set (
0.00
sec)
|
1
2
3
4
5
6
7
8
9
|
mysql> select * from user;
+----+----------+------+-------------+----------+
| id | name| sex | phone | addr|
+----+----------+------+-------------+----------+
|
1
| yuanfang |
1
|
14465463786
| hangzhou |
|
2
| Andy|
0
|
14465463786
| beijing |
|
3
| peter |
0
|
14465463786
| Hongkong |
+----+----------+------+-------------+----------+
3
rows in set (
0.00
sec)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
mysql> use gs;
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> select * from user;
+----+----------+------+----------------+----------+
| id | name| sex | phone| addr|
+----+----------+------+----------------+----------+
|
1
| yuanfang |
1
|
14465463786
| hangzhou |
|
2
| Andy|
0
|
14465463786
| beijing |
|
3
| peter |
0
|
14465463786
| Hongkong |
|
4
| lexin |
1
|
36565634
| shenzhen |
|
5
| lexin2 |
1
|
43563436565634
| aomao |
+----+----------+------+----------------+----------+
5
rows in set (
0.01
sec)
|
1
2
3
4
5
6
7
8
9
10
|
mysql> mysql> select * from user;
+----+----------+------+-------------+----------+
| id | name| sex | phone | addr|
+----+----------+------+-------------+----------+
|
1
| yuanfang |
1
|
14465463786
| hangzhou |
|
2
| Andy|
0
|
14465463786
| beijing |
|
3
| peter |
0
|
14465463786
| Hongkong |
|
4
| lexin |
1
|
36565634
| shenzhen |
+----+----------+------+-------------+----------+
4
rows in set (
0.00
sec)
|
1
2
3
4
5
6
7
8
9
|
mysql> select * from user;
+----+----------+------+-------------+----------+
| id | name| sex | phone | addr|
+----+----------+------+-------------+----------+
|
1
| yuanfang |
1
|
14465463786
| hangzhou |
|
2
| Andy|
0
|
14465463786
| beijing |
|
3
| peter |
0
|
14465463786
| Hongkong |
+----+----------+------+-------------+----------+
3
rows in set (
0.00
sec)
|