博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql共享表空间转独立表空间
阅读量:4498 次
发布时间:2019-06-08

本文共 3028 字,大约阅读时间需要 10 分钟。

使用innodb_export_import.py脚本:

 

安装MySQL-python模块:

shell > yum install MySQL-python -y 

步骤一:修改my.cnf文件

增加innodb_force_recovery = 4参数,重启mysql,阻塞所有读写操作,

步骤二:执行脚本导出innodb表的数据(脚本没有用户和密码选项,需要写在my.cnf文件中,即user=xxx和password=xxx参数):

shell > python innodb_export_import.py --export --dir=/data/mysql.bak --config=/usr/local/services/mysql/my.cnf

 

备份过程:

Getting a list of databases...

Checking for InnoDB tables...

Database performance_schema... No InnoDB tables

Database sbtest... Detected 1 InnoDB tables

Database test... No InnoDB tables

Database xiaoboluo... Detected 2 InnoDB tables

Dumping tables...

Dumped table xiaoboluo.t1 (1 / 3)

Dumped table xiaoboluo.t2 (2 / 3)

Dumped table sbtest.sbtest (3 / 3)

 

SUMMARY:

 

Tables Exported: 3

Tables Failed: 0

Databases Total: 2

Tables Total: 3

 

Log file: /data/mysql.bak/201510140221/innodb_export.log

Tables were dumped to: /data/mysql.bak/201510140221

 

此时可以查看export日志文件:

shell > cat /data/mysql.bak/201510140221/innodb_export.log

 

查看备份文件:

shell > ll /data/mysql.bak/201510140221/

总用量 12

-rw-r--r-- 1 root root  211 10月 14 02:21 innodb_export.log

drwxr-xr-x 2 root root 4096 10月 14 02:21 sbtest

drwxr-xr-x 2 root root 4096 10月 14 02:21 xiaoboluo

 

步骤三:停止mysql,在my.cnf中添加独立表空间参数:innodb_file_per_table=1,删掉my.cnf中的innodb_force_recovery=4参数,备份原来的数据目录,并删掉ibdata1和ib_logfile*文件,启动mysql

shell > cp -ar /data/mysql/data /data/mysql/data.bak

shell > rm -rf /data/mysql/data/ibdata1 /data/mysql/data/ib_logfile*

shell > service mysqld start

 

步骤四:并执行恢复innodb表操作:

shell > python innodb_export_import.py --import --dir=/data/mysql.bak/201510140221/ --config=/usr/local/services/mysql/my.cnf

 

Checking sbtest...

/var/lib/mysql/sbtest/sbtest.ibd

Imported table sbtest.sbtest

MySQL Error 1049: Unknown database '201510140246'

MySQL Error 1049: Unknown database '201510140253'

Checking xiaoboluo...

/var/lib/mysql/xiaoboluo/t1.ibd

Imported table xiaoboluo.t1

/var/lib/mysql/xiaoboluo/t2.ibd

Imported table xiaoboluo.t2

 

SUMMARY:

 

Tables Failed: 0

Tables Imported: 3

Databases Total: 4

Tables Total: 3

Tables Skipped: 0

 

Log file: /data/mysql.bak/201510140221/innodb_import.log

此时可以查看import日志:

shell > cat /data/mysql.bak/201510140221/innodb_import.log

 

步骤五:进行检测:

shell > python innodb_export_import.py --verify --dir=/data/mysql.bak/201510140221/ --config=/usr/local/services/mysql/my.cnf

Getting a list of databases...

Checking for InnoDB tables...

Database performance_schema... No InnoDB tables

Database sbtest... Detected 1 InnoDB tables

Database test... No InnoDB tables

Database xiaoboluo... Detected 2 InnoDB tables

Checking tables...

Checking xiaoboluo.t1...

Table xiaoboluo.t1 is OK

Checking xiaoboluo.t2...

Table xiaoboluo.t2 is OK

Checking sbtest.sbtest...

Table sbtest.sbtest is OK

 

SUMMARY:

 

Tables Ok: 3

Databases Total: 2

Tables Checked: 3

Tables Total: 3

Tables Bad: 0

 

Log file: /data/mysql.bak/201510140221/201510140259/innodb_check.log

此时可以查看check日志:

shell > cat /data/mysql.bak/201510140221/201510140259/innodb_check.log

 

参考链接:

除了这个方法,还可以使用mysqldump来备份数据

转载于:https://www.cnblogs.com/xiaoboluo768/p/5201875.html

你可能感兴趣的文章
【Java集合源码剖析】HashMap源码剖析
查看>>
openwrt固件支持3G和4G上网卡
查看>>
js2
查看>>
324. Wiggle Sort II
查看>>
129. Sum Root to Leaf Numbers
查看>>
Spark RDD详解
查看>>
[Codeforces Round #153 (Div. 2)]A. Little Xor
查看>>
AVFoundation 初识
查看>>
Web安全性测试
查看>>
Nginx+SignalR+Redis(一)windows
查看>>
整屏滚动
查看>>
Javascript的匿名函数与自执行
查看>>
.net中消息队列
查看>>
codeforces_1040_A Python练习
查看>>
用python处理文本数据 学到的一些东西
查看>>
UOJ #47.滑行的窗口
查看>>
P2504 聪明的猴子
查看>>
快速傅里叶变换(FFT)递归
查看>>
子窗口选择多值返回至父窗口的文本框中
查看>>
vi/vim编辑器必知必会(转)
查看>>