Home Database Mysql Tutorial MySQL自动备份策略的方案

MySQL自动备份策略的方案

Jun 07, 2016 pm 05:31 PM
o database

直接拷贝mysql的数据目录。缺点,你不能去操作正在运行的mysql服务器(在拷贝的过程中有用户通过应用程序访问更新数据,这样就无法

目前几种流行的MySQL自动备份方式:

一、逻辑备份:使用mysql自带的mysqldump工具进行备份。备份成sql文件形式。

优点:最大好处是能够与正在运行的mysql自动协同工作,

在运行期间可以确保备份是当时的点,它会自动将对应操作的表锁定,不允许其他用户修改(只能访问)。可能会阻止修改操作。sql文件通用方便移植。

缺点:备份的速度比较慢。如果是数据量很多的时候。就很耗时间。如果数据库服务器处在提供给用户服务状态,在这段长时间操作过程中,意味着要锁定表(一般是读锁定,只能读不能写入数据)。那么服务就会影响的。

备注:所谓的与mysql服务器能够自动协同工作,实际上是指加参数来控制mysql服务器,比如锁定所有表只能进行读,不能进行写操作。

  • --lock-all-tables
  • 二、物理备份:直接拷贝mysql的数据目录。缺点,你不能去操作正在运行的mysql服务器(在拷贝的过程中有用户通过应用程序访问更新数据,这样就无法备份当时的数据)可能无法移植到其他机器上去。

    直接拷贝只适用于myisam类型的表。这种类型的表是与机器独立的。但实际情况是,你设计数据库的时候不可能全部使用myisam类型表。你也不可能:因为myisam类型表与机器独立,方便移植,于是就选择这种表,这并不是选择它的理由。

    更多的情况是,你会根据业务特点(比如你需要支持事务机制就必须使用innodb),查询速度和服务性能来选择表类型的。

    必须保证表不被使用中。

    如果服务器在你则正在拷贝一个表时改变它,拷贝就失去意义。

    如果数据库表在文件系统备份过程中被修改,进入备份的表文件主语不一致的状态,而对以后的恢复表将失去意义。

    保证你的拷贝完整性的最好方法是:关闭服务器,拷贝文件,然后重启服务器。

    或者是,要锁定对应的表(对前端用户造成访问问题)。

    解释直接拷贝文件,为什么不具备可移植性?

    Mysqldump 产生可移植到其他机器、甚至具有不同硬件结构的机器上的文本文件。直接拷贝文件不能够移植到其他机器上,,除非要拷贝的表使用MyISAM 存储格式。ISAM 表只能在具有相同硬件结构的机器之间进行拷贝。例如,将文件从S PARC 的Solaris 机器拷贝到Intel 的Solaris 机器(或者相反)是行不通的。由MySQL3.23 引进的MyISAM 表存储格式可以解决这个问题,因为该格式与机器独立。因此,如果以下两个条件都满足的话,直接拷贝文件可以移植到具有不同硬件结构的机器上:即另一台机器上也必须运行MySQL3.23 以上的版本,并且文件必须表示成MyISAM 表,而不是ISAM 表。

    三、双机热备份:mysql数据库没有增量备份的机制。当数据量太大的时候备份是一个很大的问题。还好mysql数据库提供了一种主从备份的机制(也就是双机热备)。

    优点:适合数据量大的时候。现在明白了。大的互联网公司对于mysql数据备份,都是采用热机备份。搭建多台数据库服务器,进行主从复制。

    主从复制经常遇到的问题就是,如何保证数据不堵塞,不延迟。这个问题还是可以容忍的,有一些方案可以改善。毕竟有得有失的。这已经是很省心省力的方式了。

    ================================================

    我目前应该使用什么样的备份策略的权衡:

    物理备份,恢复快,当然最好是存储在一个机器上。我现在是用物理备份还是逻辑备份为好呢?

    考虑到以后会迁移平台。为了保证通用性。恢复速度1分钟左右的差距我是可以容忍的。所以我为了跨平台,我更加愿意使用逻辑备份。存储sql文件形式。

    双热机备份方式,目前硬件没有多个。技术人员有限,需要人力去维护,比较麻烦。所以排除在外。

    相关阅读:

    Linux下通过mysqldump备份MySQL数据库成sql文件

    Linux中使用mysqldump对MySQL数据库进行定时备份

    使用MySQLDumper备份与恢复数据

    MySQL开源备份工具Xtrabackup备份部署

    MySQL Xtrabackup备份和恢复

    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

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    1 months ago By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Best Graphic Settings
    1 months ago By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. How to Fix Audio if You Can't Hear Anyone
    1 months ago By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Chat Commands and How to Use Them
    1 months 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)

    iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

    Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

    Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

    How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

    How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

    To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

    How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

    Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

    How to install and register the btc trading app? How to install and register the btc trading app? Feb 21, 2025 pm 07:09 PM

    This article will provide a detailed introduction to how to install and register a Bitcoin trading application. The Bitcoin trading app allows users to manage and trade cryptocurrencies such as Bitcoin. The article guides users through the installation and registration process step by step, including downloading applications, creating accounts, performing identity verification, and first deposit. The goal of the article is to provide beginners with clear and easy-to-understand guidelines to help them easily enter the world of Bitcoin trading.

    How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

    JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

    How does Go WebSocket integrate with databases? How does Go WebSocket integrate with databases? Jun 05, 2024 pm 03:18 PM

    How to integrate GoWebSocket with a database: Set up a database connection: Use the database/sql package to connect to the database. Store WebSocket messages to the database: Use the INSERT statement to insert the message into the database. Retrieve WebSocket messages from the database: Use the SELECT statement to retrieve messages from the database.

    PHP Database Connection Pitfalls: Avoid Common Mistakes and Misunderstandings PHP Database Connection Pitfalls: Avoid Common Mistakes and Misunderstandings Jun 05, 2024 pm 10:21 PM

    To avoid PHP database connection errors, follow best practices: check for connection errors and match variable names with credentials. Use secure storage or environment variables to avoid hardcoding credentials. Close the connection after use to prevent SQL injection and use prepared statements or bound parameters.

    See all articles