Home Database Mysql Tutorial MySQL逻辑备份恢复方法简单总结

MySQL逻辑备份恢复方法简单总结

Jun 07, 2016 pm 05:27 PM
mysql backup mysql backup and restore

一、Mysql逻辑备份 1. 使用mysqldump命令生成INSERT语句备份 此方法类似于Oracle的expdp\exp工具 语法如下: mysqldump [argum

一、Mysql逻辑备份
 
 
 
1. 使用mysqldump命令生成INSERT语句备份
 
此方法类似于Oracle的expdp\exp工具
 
语法如下:
 
mysqldump [arguments] > file_name.sql
 
 
 
使用帮助:
 
[root@gc ~]# mysqldump

Usage: mysqldump [OPTIONS] database [tables]
 
OR    mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
 
OR    mysqldump [OPTIONS] --all-databases [OPTIONS]
 
For more options, use mysqldump --help
 
 
 
备份实例:
 
备份所有数据库
 
# mysqldump -uroot -proot --all-database > /tmp/dumpback/alldb.sql
 
 
 
备份某些数据库
 
# mysqldump -uroot -proot --database sqoop hive > /tmp/dumpback/sqoop_hive.sql

 
 
备份某数据库中的表
 
# mysqldump -uroot -proot sqoop tb1 > /tmp/dumpback/sqoop_tb1.sql
 
 
 
查看备份内容:
 
[root@gc dumpback]# more sqoop_tb1.sql

-- MySQL dump 10.13  Distrib 5.5.24, for Linux (x86_64)
 
--
 
-- Host: localhost    Database: sqoop
 
-- ------------------------------------------------------
 
-- Server version      5.5.24
 
 
 
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
 
......
 
--
 
-- Table structure for table `tb1`
 
--
 
DROP TABLE IF EXISTS `tb1`;
 
/*!40101 SET @saved_cs_client    = @@character_set_client */;
 
/*!40101 SET character_set_client = utf8 */;
 
CREATE TABLE `tb1` (
 
  `table_schema` varchar(64) CHARACTER SET utf8 NOT NULL DEFAULT '',
 
  `table_name` varchar(64) CHARACTER SET utf8 NOT NULL DEFAULT '',
 
  `table_type` varchar(64) CHARACTER SET utf8 NOT NULL DEFAULT ''
 
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
/*!40101 SET character_set_client = @saved_cs_client */;
 
 
 
--
 
-- Dumping data for table `tb1`
 
--
 
 
 
LOCK TABLES `tb1` WRITE;
 
/*!40000 ALTER TABLE `tb1` DISABLE KEYS */;
 
INSERT INTO `tb1` VALUES ('information_schema','CHARACTER_SETS','SYSTEM VIEW')
 
......
 
 
 
/*!40000 ALTER TABLE `tb1` ENABLE KEYS */;
 
UNLOCK TABLES;
 
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
 
.....
 
 
 
-- Dump completed on 2013-03-25 18:26:53
 
 
 
注意事项:
 
如何保证数据备份的一致性?
 
要想保证数据的一致性可以通过以下两种方法做到:
 
第一、同一时刻取出所有数据
 
对于事务支持的存储引擎,如Innodb 或者BDB 等,可以通过控制将整个备份过程在同一个事务中,使用“--single-transaction”选项。
 
例如:
 
# mysqldump --single-transaction test > test_backup.sql

 
 
第二、数据库中的数据处于静止状态
 
通过锁表参数
 
--lock-tables 每次锁定一个数据库的表,此参数是默认为true(见上面备份内容实例);
 
--lock-all-tables 一次锁定所有的表,适用于dump的表分别处于各个不同的数据库中的情况

linux

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
How to backup and restore database after mysql installation How to backup and restore database after mysql installation Apr 08, 2025 am 11:45 AM

There is no absolutely optimal MySQL database backup and recovery solution, and it needs to be selected based on the amount of data, business importance, RTO and RPO. 1. Logical backup (mysqldump) is simple and easy to use, suitable for small databases, but slow and huge files; 2. Physical backup (xtrabackup) is fast, suitable for large databases, but is more complicated to use. The backup strategy needs to consider the backup frequency (RPO decision), backup method (data quantity and time requirement decision) and storage location (off-site storage is more secure), and regularly test the backup and recovery process to avoid backup file corruption, permission problems, insufficient storage space, network interruption and untested issues, and ensure data security.

How to use MySQL data backup and recovery tools for disaster recovery How to use MySQL data backup and recovery tools for disaster recovery Aug 02, 2023 am 09:06 AM

How to use MySQL data backup and recovery tools to achieve disaster recovery. Data backup and recovery are a very important part of the database management process. Backing up your data protects your database from accidental corruption, hardware failure, or other catastrophic events. As a popular relational database management system, MySQL provides some powerful tools to achieve data backup and recovery. This article will introduce how to use MySQL's data backup and recovery tools to achieve disaster recovery. MySQL data backup tool-mysql

How to effectively manage and maintain ibd files in MySQL database How to effectively manage and maintain ibd files in MySQL database Mar 16, 2024 am 11:21 AM

In the MySQL database, each InnoDB table corresponds to an .ibd file, which stores the table's data and indexes. Therefore, for the management and maintenance of MySQL database, the management of ibd files is also particularly important. This article will introduce how to effectively manage and maintain ibd files in a MySQL database and provide specific code examples. 1. Check and optimize table space First, we can check the disk space usage of the table using the following SQL statement: SELECTTAB

Multiple backup solutions for MySql: How to efficiently create and restore MySQL backups Multiple backup solutions for MySql: How to efficiently create and restore MySQL backups Jun 15, 2023 pm 03:28 PM

MySql is a commonly used relational database management system that is widely used in various business and application scenarios. For MySQL backup issues, the selection and execution method of the backup plan are crucial. In this article, we will introduce various backup options and how to create and restore MySQL backups efficiently. 1. Selection of backup plan In the process of selecting a MySQL backup plan, you should choose a backup plan that suits you based on the business scenario and actual situation. Cold backup The so-called cold backup is to complete the MySQL database.

MySql database backup: How to achieve efficient MySQL database backup and recovery MySql database backup: How to achieve efficient MySQL database backup and recovery Jun 15, 2023 pm 11:37 PM

MySQL is one of the most widely used relational database management systems currently. Its efficiency and reliability make it the first choice for many enterprises and developers. But for various reasons, we need to back up the MySQL database. Backing up a MySQL database is not an easy task because once the backup fails, important data may be lost. Therefore, in order to ensure data integrity and recoverability, some measures must be taken to achieve efficient MySQL database backup and recovery. This article will introduce how to achieve

MySQL rolling backup techniques for data MySQL rolling backup techniques for data Jun 15, 2023 pm 07:47 PM

MySQL is a popular relational database that is widely used in various fields. However, like other applications, MySQL has risks such as data corruption, crashes, and malicious attacks. Therefore, backing up your data is crucial. Backups can provide security and some form of "undo" functionality to data, reducing or even eliminating instability and risk. The most common backup types are full backup and incremental backup. However, if you need frequent, real-time backups, rolling backups are a better approach. A rolling backup is when an acceptable

A comprehensive guide to MySQL backup and recovery A comprehensive guide to MySQL backup and recovery Jun 15, 2023 am 09:48 AM

MySQL is currently one of the most popular relational database management systems and is widely used in enterprise-level applications. Whether you are a developer or a data administrator, you need to understand the basic knowledge of MySQL backup and recovery. Backup and recovery not only help enterprises protect data, but also enable systems to respond quickly to adverse situations and restore them to normal operating conditions as much as possible. This article will detail the steps for MySQL backup and recovery and provide some best practices to help readers go further in protecting their MySQL databases.

Project experience summary of MySQL database backup and disaster recovery solutions Project experience summary of MySQL database backup and disaster recovery solutions Nov 02, 2023 pm 03:54 PM

Project experience summary of MySQL database backup and disaster recovery plan In the project, the database backup and disaster recovery plan is a very important work content. As a commonly used relational database management system, MySQL’s formulation and implementation of backup and disaster recovery plans are key to ensuring data security and availability. I have accumulated some experience in past project implementations and summarized them as follows. 1. Formulation of backup strategy Developing a reasonable backup strategy is crucial to the security of the database. Generally speaking, backup strategies need to consider the following:

See all articles