MySQL 不停服务来启用 innodb_file_per_table_MySQL
InnoDB 是一个非常不错的 MySQL 的存储引擎,目前使用非常广泛基本所有的网站和项目,我想都会优先选择这个,这个也有很好的诊断和微调的工具.我发现其中一个缺点,就是磁盘空间管理时设计非常低效.这个设计成给所有数据都存到 ibdata1 文件,所以这个文件的存储空间会不断的扩展.InnoDB 并不会收缩这些空间,就算你删除表和数据库.
所以我们需要注意我们的配置.最好一开始就使用 innodb_file_per_table 的选项.这样可以使得更加灵活性的给数据存到每个单表的数据库. 我非常不幸地, 最开始我的数据并没有考虑这个所以没有打开这个参数.后来我测试过,在之后打开这个参数根本不能生效.所以只能 dump 整个数据库,然后在启动这个参数后重新恢复数据库才行.这时我们在想有没有法子,不用关掉数据库的服务时就能完成这个工作.
目前看来只能使用 mysqldump 输出,然后才能恢复.所以我们只能使用 MySQL 的主从模式来切换,才能最大限度地减少停机时间.
所以,我使用的基本步骤是:
- 配置为当前的原始数据库为 Master 数据库.
- 使用 Xtrabackup 来备份你的原始数据库.
- 恢复你的备份和到第二个 MySQL 的实例上.
- 恢复,但不同步,然后运行 mysqldump 在第二个做为 Slave 的数据库上然后导出.
- 停止第二个数据库实例,并删除数据库.
- 创建一个新的数据库,使用前面导出的数据来恢复 MySQL 的实例,记得先要打开 innodb_file_per_table 的选项恢复.
- 配置这个数据库为 slave 然后运行复制.
- 当复制完成时,给这个 slave 切换成主,然后重新配置你的客户端使用这个实例
- 现在可以停止主数据库和删除它.
下面是详细的步骤
准备,配置数据库主从
这个看以前的 Blog 有讲怎么在线做 MySQL 的主从.接下来在 Slave 上做转换的操作
Dump 出 Slave 上的数据
假设你根据我以前的文章都做好了.现在配置好 slave 了.记得使用 innobackupex-1.5.1 -apply-log 恢复后,然后复制到数据库的目录.并修改权限.
这时记得先不要设置同步.直接启动数据后.直接使用 MySQL 的 mysqldump 来导出整个数据库.
123 |
service mysqld start
service mysqld stop
|
创建新的数据库
在新的机器上.安装新的数据库文件.只保留 dump_data.sql.然后使用 mysql_install_db 来建权限数据,MySQL 的数据库
1 |
|
创建新的配置文件
vim /etc/mysql/my.cnf
添加以下行到新的文件:
innodb_file_per_table = 1server-id = 2bin-log = 1
我在次声明,这是成功的关键,innodb_file_per_table 会让过一会导入的数据按表来存, binlog 是为了以后切主的时候使用.
启动 MySQL的并配置 Slave 的同步
先要启动数据库
1 | server mysqld start |
恢复导出的数据库
1 |
|
配置复制
因为刚导入数据库,所以要从现在开始复制,需要在主数据库上根据我以前的文章,给这个设置好权限,然后我们在 Slave 配置一下 slave 的设置
1234567 |
master_port=3306,
master_log_pos=3874; start slave;
|
这个中的 master_log_file 和 master_log_pos 是根据我以前文章刚开始使用 innobackupex 做主数据备份时 xtrabackup_binlog_info 中的信息
1 |
|
当MySQL显示 Seconds_Behind_Master: 0 时,这就 Slave 就同步的和主数据库一样了.
主从切换
现在备份完 Salve 也同步成和主一样,这时因为使用了 innodb_file_per_table 的参数,所以可以切成主了.直接在主数据库中锁一下数据库
1 |
|
然后查看主数据库的状态,写 binlog 到那个文件,什么位置了.
1 | SHOW master STATUS; |
接着到 Slavle 的数据库上看看是不同步到一样的状态了.
1 | SHOW slave STATUS /G; |
确保主从同步的一样后,先到 Slave 上停止 Slave 的复制变成新的 master,这时才方便切成主,所以要在新的 master上执行
1234 |
stop slave
reset slave reset maters
|
之所以要在新的master上执行change master to master_host=”及reset slave,主要是为了断开与老的master之间连接信息.
现在切完了,可以根据以前设置 msater 的经验来给原来的主数据库设置成这个的 slave .也可以给这个重新备份一个出来,在恢复了.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Websites for learning C language: 1. C Language Chinese Website; 2. Rookie Tutorial; 3. C Language Forum; 4. C Language Empire; 5. Script House; 6. Tianji.com; 7. Red and Black Alliance; 8, 51 Self-study network; 9. Likou; 10. C Programming. Detailed introduction: 1. C language Chinese website, which is a website dedicated to providing C language learning materials for beginners. It is rich in content, including basic grammar, pointers, arrays, functions, structures and other modules; 2. Rookie tutorials, This is a comprehensive programming learning website and more.

Share the simple and easy-to-understand PyCharm project packaging method. With the popularity of Python, more and more developers use PyCharm as the main tool for Python development. PyCharm is a powerful integrated development environment that provides many convenient functions to help us improve development efficiency. One of the important functions is project packaging. This article will introduce how to package projects in PyCharm in a simple and easy-to-understand way, and provide specific code examples. Why package projects? Developed in Python

Fermat's last theorem, about to be conquered by AI? And the most meaningful part of the whole thing is that Fermat’s Last Theorem, which AI is about to solve, is precisely to prove that AI is useless. Once upon a time, mathematics belonged to the realm of pure human intelligence; now, this territory is being deciphered and trampled by advanced algorithms. Image Fermat's Last Theorem is a "notorious" puzzle that has puzzled mathematicians for centuries. It was proven in 1993, and now mathematicians have a big plan: to recreate the proof using computers. They hope that any logical errors in this version of the proof can be checked by a computer. Project address: https://github.com/riccardobrasca/flt

Title: Learn more about PyCharm: An efficient way to delete projects. In recent years, Python, as a powerful and flexible programming language, has been favored by more and more developers. In the development of Python projects, it is crucial to choose an efficient integrated development environment. As a powerful integrated development environment, PyCharm provides Python developers with many convenient functions and tools, including deleting project directories quickly and efficiently. The following will focus on how to use delete in PyCharm

PyCharm is a powerful Python integrated development environment that provides a wealth of development tools and environment configurations, allowing developers to write and debug code more efficiently. In the process of using PyCharm for Python project development, sometimes we need to package the project into an executable EXE file to run on a computer that does not have a Python environment installed. This article will introduce how to use PyCharm to convert a project into an executable EXE file, and give specific code examples. head

Swap space plays an important role in Linux systems, especially when the system is low on memory. It acts as a backup memory storage space that helps the system run smoothly and maintain stability even under high load. This article provides you with a detailed guide to adding swap space on Ubuntu 22.04LTS to ensure that your system performance is optimized and can handle various workloads. Understanding Swap Space Swap space provides virtual memory that is used to supplement the system's physical RAM. When the system is low on RAM, the kernel swaps data to disk to prevent out-of-memory and system crashes. Linux systems commonly use swap space to handle this situation. Run multiple memory-intensive applications simultaneously to process very large files or data

As we all know, if the system disk occupied is too large after the system installation is completed, it may cause system lags, delays, and even file loss. Therefore, before you install the win11 system, you need to know how much C drive space is required to upgrade win11. Let’s take a look with the editor. How much C drive space is required to upgrade win11: Answer: Upgrading win11 requires 20-30GB of C drive space. 1. According to Microsoft’s win11 configuration requirements, you can see that win11 installation requires 64GB of hard drive space. 2. But in fact, generally speaking, there is no need for such a large space. 3. According to feedback from users who have already installed win11, the win11 upgrade requires about 20-30GB of C drive space. 4. But if our door only has

PyCharm is a powerful Python integrated development environment (IDE) that provides rich functions to help developers write and manage Python projects more efficiently. In the process of developing projects using PyCharm, sometimes we need to delete some projects that are no longer needed to free up space or clean up the project list. This article will detail how to delete projects in PyCharm and provide specific code examples. How to delete a project Open PyCharm and enter the project list interface. In the project list,
