首页 > 数据库 >MySQL: 备份 & 导入备份

MySQL: 备份 & 导入备份

时间:2022-11-09 19:02:02浏览次数:40  
标签:set 备份 MySQL 导入 +----------+ mysql sec kaven


备份

​mysqldump​​​是​​MySQL​​​自带的逻辑备份工具。它的备份原理是通过协议连接到​​MySQL​​​数据库,将需要备份的数据查询出来,将查询出的数据转换成对应的​​insert​​​语句,当需要还原这些数据时,只要执行这些​​insert​​语句,即可将对应的数据还原。

进入​​MySQL​​:

[root@MiWiFi-R1CM-srv ~]# mysql -uroot -p -h127.0.0.1 -P3306
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

查询​​MySQL​​版本:

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.27 |
+-----------+
1 row in set (0.00 sec)

备份​​kaven​​数据库。

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| kaven |
| mysql |
| performance_schema |
| sys |
| user |
+--------------------+
6 rows in set (0.00 sec)

mysql> use kaven;
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> show tables;
+-----------------+
| Tables_in_kaven |
+-----------------+
| category |
| product |
+-----------------+
2 rows in set (0.00 sec)
mysql> select count(*) from category;
+----------+
| count(*) |
+----------+
| 163 |
+----------+
1 row in set (0.11 sec)
mysql> select count(*) from product;
+----------+
| count(*) |
+----------+
| 497235 |
+----------+
1 row in set (1.62 sec)

这是一个商品数据库(先不纠结数据库名称是否规范)。

mysql> select detail, price, image_url  from product limit 1;
+---------------------------------------------------------------------------------------------------------+---------+----------------------------------------------------------------------------------------------------+
| detail | price | image_url |
+---------------------------------------------------------------------------------------------------------+---------+----------------------------------------------------------------------------------------------------+
| 八核处理器,5000mAh超大电池,配备22.5W超级快充~【play5T活力版,正在热销中】 | 1199.00 | https://xxx.com/z7/jfs/q1/904751/09/16896/87334/320ba745E85c55a96/z56ui9r0zzu8opl0.jpg |
+---------------------------------------------------------------------------------------------------------+---------+----------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
  • 导出表结构不导出数据:​​mysqldump -d kaven -uroot -p > kaven.sql​
  • MySQL: 备份 & 导入备份_dba

  • 导出数据不导出表结构:​​mysqldump -t kaven -uroot -p > kaven.sql​
  • MySQL: 备份 & 导入备份_dba_02

  • 导出数据和表结构:​​mysqldump kaven -uroot -p > kaven.sql​
  • MySQL: 备份 & 导入备份_oracle_03


  • MySQL: 备份 & 导入备份_dba_04

其他选项和参数就不介绍了,用到再去查即可。

导入备份

创建一个新的数据库。

[root@MiWiFi-R1CM-srv ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 33
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database goods;
Query OK, 1 row affected (0.21 sec)

mysql> exit
Bye

导入备份数据。

[root@MiWiFi-R1CM-srv ~]# mysql -uroot -p goods < kaven.sql 
Enter password:
[root@MiWiFi-R1CM-srv ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 39
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| goods |
| information_schema |
| kaven |
| mysql |
| performance_schema |
| sys |
| user |
+--------------------+
7 rows in set (0.09 sec)

mysql> use goods;
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> show tables;
+-----------------+
| Tables_in_goods |
+-----------------+
| category |
| product |
+-----------------+
2 rows in set (0.00 sec)

mysql> select count(*) from category;
+----------+
| count(*) |
+----------+
| 163 |
+----------+
1 row in set (0.05 sec)

mysql> select count(*) from product;
+----------+
| count(*) |
+----------+
| 497235 |
+----------+
1 row in set (1.61 sec)

这样就导入备份成功了。


标签:set,备份,MySQL,导入,+----------+,mysql,sec,kaven
From: https://blog.51cto.com/u_15870611/5838300

相关文章

  • Spring Boot:The new driver class is com.mysql.cj.jdbc.Driver
    以前使用的是​​5.1.31​​​的​​mysql​​​驱动,后面使用​​SpringBoot​​​默认的​​mysql​​驱动,启动就报错了:Loadingclass`com.mysql.jdbc.Driver'.Thisis......
  • mysqldump备份报错 'max_allowed_packet'
    1.mysqldump备份报错[root@176-238bin]#./mysqldump-uroot-p'123456'--default-character-set=utf8--opt-R-Econfluence>/data/backup/20221109/confluence202......
  • Mysql
    主从复制1.什么是主从复制主从复制是将主数据库的DDL、DML操作通过binlog(二进制日志)的方式传输到从数据库上,然后将这些日志重新执行。2.主从复制的作用数据备份读写......
  • centos使用lftp备份文件
    一直以来项目的文件没有备份,最近需要增加备份,本来以为备份是IT的工作,结果IT说工作忙,拖了半个月给分配完ftp服务器后说不给备份,需要我们开发自己备份。。。我特么***对于ft......
  • 视频融合平台EasyCVR如何调用数据库导入导出接口?具体操作步骤是什么?
    EasyCVR视频融合平台部署轻快灵活,支持视频汇聚管理,可提供的视频功能包括:视频监控、直播录像、云存储、检索回看、智能告警、平台级联等。  有用户提出需求,想要定时保......
  • 视频融合平台EasyCVR如何调用数据库导入导出接口?
    EasyCVR视频融合平台部署轻快灵活,支持视频汇聚管理,可提供的视频功能包括:视频监控、直播录像、云存储、检索回看、智能告警、平台级联等。有用户提出需求,想要定时保存数据库,......
  • mysql批量制造数据
    DELIMITER$$CREATEPROCEDUREprocess_test3()BEGINDECLAREyouridINT;SETyourid=100000;WHILEyourid<2000000DOINSERTINTOtt(order_no)VALUES(yourid)......
  • VS_QT——连接MySQL数据库
    原文链接连接2链接3           ......
  • mysql rpm安装
    目录mysqlrpm安装安装包下载安装mysqlmysqlrpm安装安装包下载官网:https://dev.mysql.com/downloads/mysql/下载完成后你应该拥有下面四个包文件安装mysql//安装......
  • mysql mysqldump常见报错
    目录mysqlmysqldump常见报错ERROR2006(HY000)atline5922:MySQLserverhasgoneawaymysqlmysqldump常见报错ERROR2006(HY000)atline5922:MySQLserverha......