当前位置:网站首页>mysql数据库压缩备份_Mysql备份压缩及恢复数据库方法总结
mysql数据库压缩备份_Mysql备份压缩及恢复数据库方法总结
2022-06-25 13:17:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
一般情况我们通过mysqldump来备份MySQL数据库,并上传至其它备份机器。如果数据库比较大,在备份传输的时候可能会慢,所以我们尽量让备份的文件小一些。
在写自动备份脚本时,最好把备份结果直接压缩,恢复时也可以直接由压缩备份恢复。下面介绍如何使用bzip2和gzip进行压缩mysql备份文件。
备份并用bzip压缩:
代码如下
mysqldump | bzip2 > outputfile.sql.bz2
从bzip2备份恢复:
代码如下
bunzip2 < outputfile.sql.bz2 | mysql < mysql options>
备份并用gzip压缩:
代码如下
mysqldump | gzip > outputfile.sql.gz
从gzip备份恢复:
gunzip < outputfile.sql.gz | mysql < mysql options>
补充本文章
备份指定数据库
代码如下
mysqldump -h hostname -u username -p databasename > db.sql不明确指定路径的话被分到用户工作目录:C:Documents and SettingsAdministrator
可以明确指定备份目录:
代码如下
mysqldump -u root -p mydb -h 192.168.14.204 > D:mydb.sql
说明:
-p之后不用输入密码,点击回车键之后才需要输入密码。
直接将MySQL数据库压缩备份
代码如下
mysqldump -h hostname -u username -p databasename | gzip > db.sql.gz
说明:
gzip是linux下的压缩工具,所以在windows环境下无法使用。
备份MySQL数据库某个(些)表
代码如下
mysqldump -h hostname -u username -p databasename table1 table2 > db.sql
同时备份多个MySQL数据库
代码如下
mysqldump -h hostname -u username -p –databases db1 db2 db3 > dbs.sql
备份服务器上所有数据库
代码如下
mysqldump –all-databases > allbackupfile.sql
测试:
代码如下
mysqldump –all-databases -u root -p > allbackupfile.sql
Enter password: ******windows下可以使用Mysql Query Browser的File–》Open Script来执行备份的脚本,同时也可以使用一下命令直接进行恢复:
代码如下
mysql -h hostname -u username -p databasename < backupfile.sql
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/151705.html原文链接:https://javaforall.cn
边栏推荐
- OpenStack学习笔记(二)
- turtlebot+lms111+gmapping实践
- On the compatibility of the disabled attribute of input on the mobile terminal
- Pointer, it has to say that the subject
- Leetcode: Sword finger offer II 091 Painting house [2D DP]
- 深入理解深度神经网络背后的数学(Mysteries of Neural Networks Part I)
- go---- mgo
- 使用调试工具调试博图TCP连接所遇到的问题
- OpenStack学习笔记-Glance组件深入了解
- Is it safe for Guosen Securities to open a stock account? Excuse me?
猜你喜欢

sql导入这样怎么解决

Some knowledge of the initial C language

戴尔电脑cpu温度过高怎么办

[pit avoidance means "difficult"] to realize editable drag and drop sorting of protable

【Proteus仿真】51单片机+DS1302+lcd1602显示

[pit avoidance refers to "difficult"] antd cascader implements new customized functions

Where can the brightness of win7 display screen be adjusted

Confusion caused by the ramp

学习编程的起点。

数据在内存中的存储相关内容
随机推荐
Regular match the phone number and replace the fourth to seventh digits of the phone number with****
##脚本编写ssh免密功能
初始c语言时的一些知识
Parabolic motion in unity 2D games
解决报错:Creating window glfw ERROR: GLEW initalization error: Missing GL version
Three lines of code to simply modify the project code of the jar package
哈希表、哈希冲突
数据在内存中的存储相关内容
Nova组件源码分析之冷迁移与Resize
Using swiper to realize seamless rotation of multiple slides
OpenStack学习笔记之-Nova组件深入了解
Rust, le meilleur choix pour un programmeur de démarrer une entreprise?
Implementation of a small book system
SSH secret free function for # scripting
Insight into heap and stack stored in new string() /string() in JS
Numpy库使用入门
Gorm---- Association query
Which Chinese virtual human is better? Sullivan, IDC: Xiaobing Baidu Shangtang ranks in the first echelon
Cesium model Daquan glb/glft format
Nova中的api