博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysqldump备份单表数据
阅读量:6070 次
发布时间:2019-06-20

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

方法二、使用MySQL的SELECT INTO OUTFILE 备份语句(推荐)

在下面的例子中,生成一个文件,各值用逗号隔开。这种格式可以被许多程序使用。

SELECT  * INTO OUTFILE '/root/student_answer_block.text'  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'   LINES TERMINATED BY '\n'FROM  student_answer_blockWHERE  examination_id IN (    SELECT      ID    FROM      examinations    WHERE      STATISTIC_TRIGGERED = 'Y'    AND STATISTIC_DATE < DATE_SUB(CURDATE(), INTERVAL 1 MONTH)    AND ORG_NO IS NOT NULL    ORDER BY      STATISTIC_DATE DESC  );SELECT  * INTO OUTFILE '/root/student_question.text'  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'   LINES TERMINATED BY '\n'FROM  student_questionWHERE  examination_id IN (    SELECT      ID    FROM      examinations    WHERE      STATISTIC_TRIGGERED = 'Y'    AND STATISTIC_DATE < DATE_SUB(CURDATE(), INTERVAL 1 MONTH)    AND ORG_NO IS NOT NULL    ORDER BY      STATISTIC_DATE DESC  );

 

 

方法三、使用mysqldump

很奇妙的是我发现了mysqldump其实有个很好用的参数“—w”
帮助文档上说明:
-w, --where=name Dump only selected records. Quotes are mandatory.
Defaults to on; use --skip-lock-tables to disable

 

备份一个月前的数据: mysqldump -S /data/mysqldata/3307/mysql.sock -uroot -p --skip-lock-tables yeah100 student_answer_block --where "examination_id IN ( SELECT ID FROM examinations WHERE STATISTIC_TRIGGERED = 'Y' AND STATISTIC_DATE < DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND ORG_NO IS NOT NULL ORDER BY STATISTIC_DATE DESC )" > /tmp/student_answer_block.sqlmysqldump -S /data/mysqldata/3307/mysql.sock -uroot -p --skip-lock-tables yeah100 student_question --where "examination_id IN ( SELECT ID FROM examinations WHERE STATISTIC_TRIGGERED = 'Y' AND STATISTIC_DATE < DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND ORG_NO IS NOT NULL ORDER BY STATISTIC_DATE DESC )" > /tmp/student_question.sql

 

 

还原数据库方法:

mysql -S /data/mysqldata/3306/mysql.sock -uroot -p yeah100bakup < ./student_question.sql

 

转载于:https://www.cnblogs.com/ivan-yang/p/8399167.html

你可能感兴趣的文章
Linux 获取文件夹下的所有文件
查看>>
对 Sea.js 进行配置(一) seajs.config
查看>>
dom4j解析xml文件
查看>>
第六周
查看>>
斯坦福大学公开课机器学习:梯度下降运算的学习率a(gradient descent in practice 2:learning rate alpha)...
查看>>
解释一下 P/NP/NP-Complete/NP-Hard 等问题
查看>>
javafx for android or ios ?
查看>>
微软职位内部推荐-Senior Software Engineer II-Sharepoint
查看>>
sql 字符串操作
查看>>
【转】Android布局优化之ViewStub
查看>>
网络安全管理技术作业-SNMP实验报告
查看>>
根据Uri获取文件的绝对路径
查看>>
Fundebug前端JavaScript插件更新至1.6.0,新增test()方法用于测试
查看>>
Flutter 插件开发:以微信SDK为例
查看>>
.NET[C#]中NullReferenceException(未将对象引用到实例)是什么问题?如何修复处理?...
查看>>
复杂业务下,我们为何选择Akka作为异步通信框架?
查看>>
边缘控制平面Ambassador全解读
查看>>
Windows Phone 7 利用计时器DispatcherTimer创建时钟
查看>>
程序员最喜爱的12个Android应用开发框架二(转)
查看>>
vim学习与理解
查看>>