linux mysql 备份 压缩_linux中数据库5.7迁移记录、文件压缩和解压

背景:数据库表记录内容过多,使用navicat的数据同步功能耗时漫长

1、备份数据库

#备份命令,其中yuesheng_novel为需要备份的数据库名,备份到/usr/local目录下

[root@izwz98l0u5sq2hwfpuszvoz ~]# mysqldump -u root -p yuesheng_novel >/usr/local/yuesheng_novel.sql

Enter password:

2、压缩(带宽限制,不压缩,下载太久了)

#压缩命令,进入到文件所在目录,直接执行

[root@izwz98l0u5sq2hwfpuszvoz local]# tar -zcvf yuesheng_novel.tar.gz yuesheng_novel.sql

#压缩后,查看一下压缩结果,可以看到,329M压缩成了122M

[root@izwz98l0u5sq2hwfpuszvoz local]# du -sh * | sort -n

122M yuesheng_novel.tar.gz

329M yuesheng_novel.sql

3、使用FTP工具讲压缩文件下载到本地,然后上传到新的服务器

4、进入新服务器解压

#进入文件所在目录

[root@VM_0_12_centos ~]# cd /yuesheng/

[root@VM_0_12_centos yuesheng]# ls

yuesheng_novel.tar.gz

#使用解压命令解压,使用tar -zxvf yuesheng_novel.tar.gz -C new_dir,可以指定解压目录

[root@VM_0_12_centos yuesheng]# tar -zxvf yuesheng_novel.tar.gz

yuesheng_novel.sql

[root@VM_0_12_centos yuesheng]# ls

yuesheng_novel.sql yuesheng_novel.tar.gz

#查看解压结果

[root@VM_0_12_centos yuesheng]# du -sh * | sort -n

122M yuesheng_novel.tar.gz

329M yuesheng_novel.sql

5、建立同名数据库

6、备份恢复

#进入mysql

[root@VM_0_12_centos yuesheng]# mysql -u root -p

Enter password:

#选择数据库

mysql> use yuesheng_novel

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

#加载数据

mysql> source /yuesheng/yuesheng_novel.sql

#重新备份,做一次校验

[root@VM_0_12_centos yuesheng]# mysqldump -u root -p yuesheng_novel > /yuesheng/test.sql

Enter password:

[root@VM_0_12_centos yuesheng]# du -sh * | sort -n

122M yuesheng_novel.tar.gz

329M test.sql

329M yuesheng_novel.sql

扩展:文件压缩和解压

注:filename是待压缩全文件名,test为压缩后文件名,不含后缀,new_dir为解压路径,例如:/usr/local

格式

描述

压缩

解压

指定解压目录

zip格式

使用最多,跨平台,但是压缩率不高

zip -r test.zip filename

unzip test.zip

unzip test.zip -d new_dir

tar格式

linux文档打包格式,耗用CPU和时间少,只打包,不压缩

tar -cvf test.tar dir

tar -xvf test.tar

tar -xvf test.tar -C new_dir

tar.gz格式

常用,耗用cpu一版,压缩率理想

tar -zcvf test.tar.gz filename

tar -zxvf test.tar.gz

tar -zxvf test.tar.gz -C new_dir

tar.bz2格式

压缩率最高,耗用cpu和时间多

tar -jcvf test.tar.bz2 filename

tar -jxvf test.tar.bz2

tar -jxvf test.tar.bz2 -C new_dir

#linux使用zip压缩需要先yum安装依赖

yum install -y unzip zip

#未安装报错

-bash: zip: command not found

-bash: unzip: command not found

#使用tar.bz2压缩需要先yum安装依赖

yum -y install bzip2

#未安装报错

tar (child): bzip2: Cannot exec: No such file or directory

tar (child): Error is not recoverable: exiting now

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值