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 filenameunzip test.zipunzip test.zip -d new_dir
tar格式linux文档打包格式,耗用CPU和时间少,只打包,不压缩tar -cvf test.tar dirtar -xvf test.tartar -xvf test.tar -C new_dir
tar.gz格式常用,耗用cpu一版,压缩率理想tar -zcvf test.tar.gz filenametar -zxvf test.tar.gztar -zxvf test.tar.gz -C new_dir
tar.bz2格式压缩率最高,耗用cpu和时间多tar -jcvf test.tar.bz2 filenametar -jxvf test.tar.bz2tar -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

转载于:https://my.oschina.net/yueshengwujie/blog/3098865

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值