【MySQL】mysql数据库备份实战-mysqldump

前言

正好要对阿里云服务器的数据库进行备份,趁着这个机会我们一起来探讨下mysqldump的备份方式

mysql备份工具的使用

作用:
MySQL数据库自带的一个很好用的备份命令。是逻辑备份,导出 的是SQL语句。也就是把数据从MySQL库中以逻辑的SQL语句的形式直接输出或生成备份的文件的过程。

1. 备份整个数据库
[root@xinsz08 backup]# mysql -p   #进入数据库
Enter password: 

查看现在有哪些数据库需要备份
MariaDB [(none)]> show databases;
±-------------------+
| Database |
±-------------------+
| Wecenter |
| bbs |
| blog |
| information_schema |
| mysql |
| performance_schema |
| webdb |
±-------------------+
7 rows in set (0.01 sec)

MariaDB [(none)]>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

现在我们要备份的数据库有blog数据库,webdb数据库

进入到保存备份数据的目录

[root@xinsz08 backup]# cd backup/

 
 
  • 1

开始备份

[root@xinsz08 backup]# mysqldump -uroot -p blog >blog202007302109.sql
[root@xinsz08 backup]# mysqldump -uroot -p webdb > wedb202007302109.sql
Enter password: 

 
 
  • 1
  • 2
  • 3

查看备份好的数据:
[

root@xinsz08 backup]# ll -h
total 11M
-rw-r--r-- 1 root root 361K Jul 30 21:10 blog202007302109.sql
-rw-r--r-- 1 root root  11M Jul 30 21:33 wedb202007302109.sql
[root@xinsz08 backup]# 

 
 
  • 1
  • 2
  • 3
  • 4
  • 5

一个11M,一个361K,都不是很大,其中361K的是今天刚建好的个人站。

2. 备份多个数据库
[root@xinsz08 backup]# mysqldump -uroot -p --datadases blog, webdb > back.sql

 
 
  • 1
3. 备份所有数据库
[root@xinsz08 backup]# mysqldump -uroot -p --all-databases > databaseall-20200730all.sql
Enter password: 
[root@xinsz08 backup]# ll -h
total 23M
-rw-r--r-- 1 root root 361K Jul 30 21:10 blog202007302109.sql
-rw-r--r-- 1 root root  12M Jul 30 21:37 databaseall-20200730all.sql
-rw-r--r-- 1 root root  11M Jul 30 21:33 wedb202007302109.sql

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
总结

本文是在操作过程中随时做的记录,事实上是有脚本随时生成备份的,这个我们会在后面的篇章里来详细介绍关于mysql和shell脚本的内容

                                </div><div data-report-view="{&quot;mod&quot;:&quot;1585297308_001&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/xinshuzhan/article/details/107701328&quot;,&quot;extend1&quot;:&quot;pc&quot;,&quot;ab&quot;:&quot;new&quot;}"><div></div></div>
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-e0530931f4.css" rel="stylesheet">
                            </div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值