Home Database Mysql Tutorial MySQL数据库的无缝迁移

MySQL数据库的无缝迁移

Jun 07, 2016 pm 03:13 PM
linux mysql database Community migrate Enter

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 mysql数据库的无缝迁移问题? 问:在平时的开始过程中,由于经常“需求理解,架构设计,需求变更”等多种原因,导致系统运行一段时间后,数据库的表结构需要变更,如何实现尽量短的停机,实现无缝的

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  mysql数据库的无缝迁移问题?

  问:在平时的开始过程中,由于经常“需求理解,架构设计,需求变更”等多种原因,导致系统运行一段时间后,数据库的表结构需要变更,如何实现尽量短的停机,实现无缝的迁移?

  我开玩笑说,最好的解决办法就是不迁移。不迁移肯定最好,这要依赖于非常好的设计,在前期架构设计的时候能够考虑到需求可能的变更,数据库设计也可以根据业务来进行一定程度的抽象。这可能有点太理想,不过迁移数据,始终是个不可避免的问题。下面说下一般的迁移方案。

  定点停机迁移

  就像那位朋友说的,在一个月黑风高的夜晚,停掉应用,用事先写好的迁移程序,把mysql 数据库数据迁移到新结构的mysql数据库中。完成后,切换应用。最大的缺点就是随着数据量的增加停机时间会变得非常长。

  mysql binlog方案

  mysql的迁移可以考虑mysql的主从复制 replication的特性,解析binlog日志出来,然后根据新的业务特点设计的数据库结构,把数据写入到新的数据库,运行迁移过程不需要停机。在数据迁移基本上完成的时候,停掉前段应用,等待迁移全部完成,切换应用到新库。停机时间非常短,只需要几乎1-2分钟或者更少。

  触发器方案

  备份老的mysql数据表结构到新的mysql数据库,在新库创建新的表结构,更改老的数据库表,创建触发器,让数据的写入的时候同时写入到的心的mysql表。dump老的mysql的数据,导入到新的mysql,这是新的mysql表结构的表应该已经有相应的数据了。然后开启主从复制,让其达到跟主库数据一致。切换应用,迁移到的方案。停机时间非常短,只需要几乎1-2分钟或者更少。

  mysql udf方案

  mysql的udf允许你开发自己的函数集成到mysql中,这样你可以很方便的在数据写入的时候同时写到的其他地方。缺点是开发成本大,需要对mysql udf有了解。也可以用现成的memcached_functions_mysql和lib_mysqludf_json来实现,你就不需要编写udf函数了,只需要实现一个memcached的服务端来接受数据,然后解析json到新的数据库就OK了。memcached协议非常简单,自己实现起来也很容易。这种方案的迁移时间也会非常短。

  中间件方案

  这种方案必须要你的应用连接数据使用了类似中间层的方案,你只需要在中间层增加同时往新库写数据就OK了。这种方案的依赖比较大,相信小一点的公司可能都没有条件。

  总结:要实现无缝迁移,成本和难度肯定会增加,这需要结合你的业务需要来具体实施。迁移方案需要进行充分的测试,以及考虑出错的回滚方案。

MySQL数据库的无缝迁移

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
4 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
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
MySQL: The Database, phpMyAdmin: The Management Interface MySQL: The Database, phpMyAdmin: The Management Interface Apr 29, 2025 am 12:44 AM

MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.

How to understand DMA operations in C? How to understand DMA operations in C? Apr 28, 2025 pm 10:09 PM

DMA in C refers to DirectMemoryAccess, a direct memory access technology, allowing hardware devices to directly transmit data to memory without CPU intervention. 1) DMA operation is highly dependent on hardware devices and drivers, and the implementation method varies from system to system. 2) Direct access to memory may bring security risks, and the correctness and security of the code must be ensured. 3) DMA can improve performance, but improper use may lead to degradation of system performance. Through practice and learning, we can master the skills of using DMA and maximize its effectiveness in scenarios such as high-speed data transmission and real-time signal processing.

How to handle high DPI display in C? How to handle high DPI display in C? Apr 28, 2025 pm 09:57 PM

Handling high DPI display in C can be achieved through the following steps: 1) Understand DPI and scaling, use the operating system API to obtain DPI information and adjust the graphics output; 2) Handle cross-platform compatibility, use cross-platform graphics libraries such as SDL or Qt; 3) Perform performance optimization, improve performance through cache, hardware acceleration, and dynamic adjustment of the details level; 4) Solve common problems, such as blurred text and interface elements are too small, and solve by correctly applying DPI scaling.

Steps to add and delete fields to MySQL tables Steps to add and delete fields to MySQL tables Apr 29, 2025 pm 04:15 PM

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

macOS and Linux: Compatibility and User Experience macOS and Linux: Compatibility and User Experience Apr 30, 2025 am 12:05 AM

macOS and Linux have their own advantages in compatibility and user experience. macOS has excellent compatibility within the Apple ecosystem, and the user experience is simple and intuitive; Linux has outstanding hardware compatibility and software flexibility. The user experience varies from distribution to distribution, emphasizing personalization and control.

How to uninstall MySQL and clean residual files How to uninstall MySQL and clean residual files Apr 29, 2025 pm 04:03 PM

To safely and thoroughly uninstall MySQL and clean all residual files, follow the following steps: 1. Stop MySQL service; 2. Uninstall MySQL packages; 3. Clean configuration files and data directories; 4. Verify that the uninstallation is thorough.

An efficient way to batch insert data in MySQL An efficient way to batch insert data in MySQL Apr 29, 2025 pm 04:18 PM

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

How to use MySQL functions for data processing and calculation How to use MySQL functions for data processing and calculation Apr 29, 2025 pm 04:21 PM

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

See all articles