1、單錶備份
[root@centos7 backup]
# innobackupex --include='hellodb_innodb.students' /data/mysql/backup
200308 15:42:17 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!"
.unrecognized character \x01; marked by <-- here after <-- here near column 1 at - line 1374.
200308 15:42:17 connecting to mysql server host: localhost, user: not set, password: not set, port: not set, socket: not set
using server version 5.5.56-mariadb
innobackupex version 2.4.6 based on mysql server 5.7.13 linux (x86_64)
(revision id: 8ec05b7)
xtrabackup: uses posix_fadvise(
).xtrabackup: cd to /var/lib/mysql
xtrabackup: open files limit requested 0, set to 1024
xtrabackup: using the following innodb configuration:
xtrabackup: innodb_data_home_dir =
.xtrabackup: innodb_data_file_path = ibdata1:10m:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 5242880
....
..mysql binlog position: filename 'mariadb-bin.000001', position '245'
200308 15:42:19 [00] writing backup-my.cnf
200308 15:42:19 [00]
...done
200308 15:42:19 [00] writing xtrabackup_info
200308 15:42:19 [00]
...done
xtrabackup: transaction log of lsn (1639958) to (1639958) was copied.
200308 15:42:19 completed ok!
2、備份表結構
[root@centos7 ~]
# mysql -e 'show create table hellodb_innodb.students'>/data/scripts/student.sql
[root@centos7 ~]
# cat /data/scripts/student.sql
table create table
students create table `students`
(\n `stuid`
int(10) unsigned not null auto_increment,\n `name`
varchar(50) not null,\n `age`
tinyint(3) unsigned not null,\n `gender`
enum(
'f','m'
) not null,\n `classid`
tinyint(3) unsigned default null,\n `teacherid`
int(10) unsigned default null,\n primary key (
`stuid`
)\n) engine=innodb auto_increment=27 default charset=utf8
3、刪除表
[root@centos7 ~]
# mysql -e 'drop table hellodb_innodb.students'
4、匯出表
[root@centos7 backup]
[root@centos7 ~]
# vim /data/scripts/student.sql
create table `students`
(\n `stuid`
int(10) unsigned not null auto_increment,\n `name`
varchar(50) not null,\n `age`
tinyint(3) unsigned not null,\n `gender`
enum(
'f','m'
) not null,\n `classid`
tinyint(3) unsigned default null,\n `teacherid`
int(10) unsigned default null,\n primary key (
`stuid`
)\n) engine=innodb auto_increment=27 default charset=utf8
匯入資料庫中
[root@centos7 ~]
# mysql hellodb_innodb
pager set to stdout
pager set to stdout
pager set to stdout
pager set to stdout
pager set to stdout
pager set to stdout
pager set to stdout
pager set to stdout
6、在匯入表結構時,會建立預設的表空間(表資料),這裡需要刪除預設的表空間。
[root@centos7 ~]
# ll /var/lib/mysql/hellodb_innodb/ | grep students
總用量 856
-rw-rw---- 1 mysql mysql 8736 3月 8 16:21 students.frm
-rw-rw---- 1 mysql mysql 98304 3月 8 16:21 students.ibd
mariadb [hellodb_innodb]
> alter table students discard tablespace
->
;query ok, 0 rows affected (0.14 sec)
[root@centos7 ~]
# ll /var/lib/mysql/hellodb_innodb/ | grep students
-rw-rw---- 1 mysql mysql 8736 3月 8 16:21 students.frm
7、複製備份目錄下的相關檔案到資料庫目錄中(無需複製表結構檔案,即students.frm)
[root@centos7 ~]
# ls /data/mysql/backup/2020-03-08_15-42-17/hellodb_innodb/
students.cfg students.exp students.frm students.ibd
[root@centos7 ~]
# cp /data/mysql/backup/2020-03-08_15-42-17/hellodb_innodb/students. /var/lib/mysql/hellodb_innodb/
8、修改檔案屬性,改為mysql使用者所擁有。
[root@centos7 ~]
# chown -r mysql.mysql /var/lib/mysql/hellodb_innodb/
[root@centos7 ~]
# ll /var/lib/mysql/hellodb_innodb/ | grep students
-rw-r--r-- 1 mysql mysql 647 3月 8 16:49 students.cfg
-rw-r----- 1 mysql mysql 16384 3月 8 16:49 students.exp
-rw-rw---- 1 mysql mysql 8736 3月 8 16:21 students.frm
-rw-r----- 1 mysql mysql 98304 3月 8 16:49 students.ibd
9、匯入表空間(即資料)
mariadb [hellodb_innodb]
> alter table students import tablespace;
xtrabackup單錶備份與恢復
備份 單錶備份主要是使用include引數,格式如下 include name 指定表名,格式 databasename.tablename具體命令如下 innobackupex defaults file data01 3306 conf my.cnf socket data01 3306 tmp...
postgre 匯出單錶和匯入
pg除了可以通過dump的方式匯入和匯出。如果只是匯出資料,可以直接使用copy copy user to tmp data test.csv with csv copy user name,password to tmp data test.csv with csv copy select fro...
xtraBackup和qpress安裝和使用
xtrabackup和qpress是用來備份資料庫和恢復資料庫的,屬於物理操作 由於版本有要求,mysql5.7以上的,要用xtrabackup2.4以上 wget 安裝依賴 rpm ivh libev 4.15 1.el6.rf.x86 64.rpm yum install perl dbi yu...