环境准备:
系统: Centos 7.3
[root@ localhost backup]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
# 创建备份的目录
mkdir /backup
# 备份命令
mysqldump -uroot -p123 test > /backup/test.sql
cd /backup/
[root@ localhost backup]# ls
test.sql
[root@ localhost backup]# more test.sql
-- MySQL dump 10.14 Distrib 5.5.64-MariaDB, for Linux (x86_64)
--
-- Host: localhost Database: test
-- ------------------------------------------------------
-- Server version 5.5.64-MariaDB
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
模拟数据库被删除恢复数据
[root@ localhost backup]# mysql -uroot -p123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| szm |
| test |
| testdb |
+--------------------+
6 rows in set (0.00 sec)
MariaDB [(none)]> drop database test;
Query OK, 1 row affected (0.06 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| szm