mysqldump是mysql/mariadb为备份数据库和表提供的实用程序。一般来说,我们会定期对数据库进行完整的转储并保存。但有时我们需要从备份中恢复单个或两个表。问题是如何从完整备份文件中恢复特定表?本篇文章将介绍从完整的数据库备份文件中提取表备份。此外,我们还可以在每个表中提取单个文件中的所有表备份。
第1步:下载MySQL dump拆分脚本
在单独的表特定文件备份中拆分完整的mysqldump数据库备份文件。创建一个名为splitdb.sh的文件,并在其中复制下面的脚本。
#!/bin/bash #### # Split MySQL dump SQL file into one file per table # based on http://blog.tty.nl/2011/12/28/splitting-a-database-dump #### if [ $# -lt 1 ] ; then echo "USAGE $0 DUMP_FILE [TABLE]" exit fi if [ $# -ge 2 ] ; then csplit -s -ftable $1 "/-- Table structure for table/" "%-- Table structure for table `$2`%" "/-- Table structure for table/" "%40103 SET TIME_ZONE=@OLD_TIME_ZONE%1" else csplit -s -ftable $1 "/-- Table structure for table/" {*} fi [ $? -eq 0 ] || exit mv table00 head FILE=`ls -1 table* | tail -n 1` if [ $# -ge 2 ] ; then mv $FILE foot else csplit -b '%d' -s -f$FILE $FILE "/40103 SET TIME_ZONE=@OLD_TIME_ZONE/" {*} mv ${FILE}1 foot fi for FILE in `ls -1 table*`; do NAME=`head -n1 $FILE | cut -d$'x60' -f2` cat head $FILE foot > "$NAME.sql" done rm head foot table*
第2步:从dump中提取所有表
对于这个例子,有一个名为mydb.sql的转储文件,要想在每个表的小备份中拆分。为此,需要创建了一个新目录/ opt / splitdb,并在此目录中复制了名为splitDB.sh的脚本。现在使用以下命令提取单个备份文件中的所有表。
#cd / opt / splitdb #sh splitDB.sh mydb.sql
第3步:从dump中提取单个表
如果我们只想提取一个表,我们可以使用如下命令。例如,要想只拆分名为my_tbl1和my_tbl2的表。它将在当前目录中提取名为my_tbl1.sql和my_tbl2.sql的备份。
#cd / opt / splitdb #sh splitDB.sh mydb.sql my_tbl1 #sh splitDB.sh mydb.sql my_tbl2
本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注PHP中文网的MySQL教程视频栏目!
The above is the detailed content of How to extract table backup from full MySQL DB dump file. For more information, please follow other related articles on the PHP Chinese website!

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor
