当前位置: 首页 > news >正文

Mysql之备份(Mysqldump)

本篇文章旨在介绍Mysql的备份,借助mysqldump命令。

1.准备数据

准备一个数据库d1,表t1
表结构如下:

mysql> desc t1;
+-------+------------+------+-----+---------+----------------+
| Field | Type       | Null | Key | Default | Extra          |
+-------+------------+------+-----+---------+----------------+
| xh    | int        | NO   | PRI | NULL    | auto_increment |
| xm    | varchar(5) | YES  |     | NULL    |                |
+-------+------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

插入数据后,内容如下:

mysql> select * from t1;
+----+------+
| xh | xm   |
+----+------+
|  1 | zs   |
|  2 | ls   |
+----+------+
2 rows in set (0.00 sec)
2.实验开始
a-备份

mysqldump命令的格式:

mysqldump -h 127.0.0.1 -u root -p666 xxx > f:\数据库备份练习\xxx.sql
#127.0.0.1为ip地址
#root为用户名
#666为密码
#xxx为存储的数据库名
#>后为要存储的位置以及文件名

注意是在操作系统命令行输入,不是在mysql里。

[root@VM-4-9-centos ~]# mysqldump -u root -p d1 > d1.bak
Enter password:
[root@VM-4-9-centos ~]# ls
d1.bak 
b-还原

在还原前,我们需要先建立数据库。

#删除数据库
mysql> drop database d1;
Query OK, 1 row affected (0.03 sec)mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)#还原
[root@VM-4-9-centos ~]# mysql -u root -p d1 < d1.bak
Enter password:

查看还原效果:

mysql> use d1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> desc t1;
+-------+------------+------+-----+---------+----------------+
| Field | Type       | Null | Key | Default | Extra          |
+-------+------------+------+-----+---------+----------------+
| xh    | int        | NO   | PRI | NULL    | auto_increment |
| xm    | varchar(5) | YES  |     | NULL    |                |
+-------+------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)mysql> select * from t1;
+----+------+
| xh | xm   |
+----+------+
|  1 | zs   |
|  2 | ls   |
+----+------+
2 rows in set (0.00 sec)
c-原理
http://www.lryc.cn/news/194742.html

相关文章:

  • 算法leetcode|84. 柱状图中最大的矩形(rust重拳出击)
  • Java中通过List中的stream流去匹配相同的字段去赋值,避免for循环去查询数据库进行赋值操作
  • 开源酒店预订订房小程序源码系统+多元商户 前端+后端完整搭建教程 可二次开发
  • Leetcode 2906. Construct Product Matrix
  • 【Leetcode Sheet】Weekly Practice 11
  • 本地PHP搭建简单Imagewheel私人云图床,在外远程访问
  • Python图像处理进阶:Pillow库的中级应用
  • 多线程怎么共用一个事务
  • scrollIntoView使用与属性详解
  • 【LeetCode热题100】--169.多数元素
  • LeetCode 面试题 10.01. 合并排序的数组
  • 揭秘OLED透明拼接屏的参数规格:分辨率、亮度与透明度全解析
  • 竞赛选题 深度学习YOLOv5车辆颜色识别检测 - python opencv
  • linux U盘无法使用,提示“Partition table entries are not in disk order“
  • HDLbits: Fsm ps2
  • 【设计模式】八、桥接模式
  • 从零开始的stable diffusion
  • 【Qt之QString】数值与进制字符串间的转换详解
  • Pytest单元测试框架 —— Pytest+Allure+Jenkins的应用
  • 科普向丨语音芯片烧录工艺的要求
  • : 依赖: qtbase5-dev (= 5.12.8+dfsg-0ubuntu2.1) 但是它将不会被安装 或
  • Unity中Camera类实现坐标系转换的示例
  • vue-按键修饰符
  • [初始java]——java为什么这么火,java如何实现跨平台、什么是JDK/JRE/JVM
  • R语言手动绘制NHANSE数据基线表并聊聊NHANSE数据制作亚组交互效应表的问题(P for interaction)
  • C++引用(起别名)
  • Ubuntu:VS Code IDE安装ESP-IDF【保姆级】(草稿)
  • 子序列(All in All, UVa 10340)rust解法
  • AI时代,当项目经理遇到ChatGPT,插上腾飞的翅膀!
  • Springboot项目中加载Groovy脚本并调用其内部方代码实现