If you use the InnoDB storage engine for (some of) your MySQL tables, you’ve probably already came across a problem with its default configuration. As you may have noticed in your MySQL’s data directory (in Debian/Ubuntu – /var/lib/mysql) lies a file called ‘ibdata1′. It holds almost all the InnoDB data (it’s not a transaction log) of the MySQL instance and could get quite big. By default this file has a initial size of 10Mb and it automatically extends. Unfortunately, by design InnoDB data files cannot shrinked. That’s why DELETEs, TRUNCATEs, DROPs, etc. can’t will not reclaim the space used by the file. Instead any freed regions are marked as unused and can be used later. Theoretically speaking the file could reach the maximum size allowed by the filesystem if no limit is set in the my.cnf file (in Debian/Ubuntu it’s located in /etc/mysql/my.cnf). Guess what ? It’s not set by default. However you can configure your InnoDB engine as described MySQL’s Reference Manual. Additionally you can force the server to create an *.ibd for each newly created InnoDB table by using the ‘innodb_file_per_table‘ option (quite intuitive, huh ?
).
As mentioned above, you cannot shrink InnoDB data files. Additionally, you cannot make much changes in the settings of a InnoDB data file. So if you haven’t configured InnoDB properly right after the installation, you’ll probably have a pretty large ibdata1 file. There are three ways to reclaim your free space, but before doing so backup your whole MySQL data directory… just in case. And don’t forget to stop any services using MySQL databases.
In order to use the first two methods you should have a list of all InnoDB tables in your MySQL instance. You can easily create one if your MySQL version is 5.0+ by using the special database called ‘INFORMATION SCHEMA‘. Just invoke this query:
SELECT `TABLE_SCHEMA`,`TABLE_NAME` FROM TABLES WHERE ENGINE = ‘InnoDB’;
Changing Table Engines
1. Invoke ‘ALTER TABLE `table_name` ENGINE=MyISAM‘ for each InnoDB table;
2. Stop the MySQL server;
3. Remove InnoDB data files;
4. Make the appropriate changes in your my.cnf;
5. Start the server again;
6. Invoke ‘ALTER TABLE `table_name` ENGINE=InnoDB‘ for those tables again;
Note: Any foreign key information is lost when changing the engine to MyISAM. You should save the output of ‘SHOW CREATE TABLE `table_name`‘ for each of those tables and recreate the foreign keys manually. So, that method sucks !
Dump InnoDB Tables
1. Use mysqldump to dump all InnoDB tables, for example:
mysqldump ––add-drop-table ––extended-insert ––disable-keys ––quick ‘db_name’ ––tables ‘tbl_name’ > ‘db_name.tbl_name.sql’
2. Drop those tables using:
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE db_name.tbl_name;
DROP TABLE db_name1.tbl_name1;
–– DROP other tables here…
SET FOREIGN_KEY_CHECKS=1;
3. Stop the MySQL server;
4. Remove InnoDB data files;
5. Make the appropriate changes in my.cnf;
6. Start the MySQL server;
7. Re-import the tables. You’d better get into the ‘mysql’ console and issue the following commands:
SET FOREIGN_KEY_CHECKS=0;
SOURCE db_name.tbl_name.sql;
SOURCE db_name1.tbl_name1.sql;
–– SOURCE other files here…
SET FOREIGN_KEY_CHECKS=1;
Note: This method is quite tedious too as you have to keep track on all tables and all dumped files… Yeah, I don’t like it either.
Dump the Whole Database
In fact, this is the method I used to solve the problem. It requires much more space and time but it’s maybe the easiest one. So here it is:
1. Dump all databases by calling:
/usr/bin/mysqldump ––extended-insert ––all-databases ––add-drop-database ––disable-keys ––flush-privileges ––quick ––routines ––triggers > all-databases.sql
2. Stop the MySQL server;
3. Rename or remove (in case you’ve already backed it up) the MySQL data directory and create an empty one with the same name and permissions;
4. Make the appropriate changes in my.cnf;
5. Re-initialize the database with the following command (replace the ‘mysqld‘ with the login of the user your MySQL server runs as) (10x, Påven):
sudo -u mysqld mysql_install_db
6. Start the MySQL server;
7. Get into the ‘mysql‘ console and type:
SET FOREIGN_KEY_CHECKS=0;
SOURCE all-databases.sql;
SET FOREIGN_KEY_CHECKS=1;
8. Restart the MySQL server. (10x, czaby)
At this point everything should be fine and you can test it by starting again the services that use MySQL. If not…
Troubleshoot Me
1. Stop the MySQL server;
2. Remove its data directory and put the backed up one (you’ve made a backup as mentioned above, haven’t you ?);
3. Start the MySQL server again;
4. Let me know what went wrong;
So… that’s it for today. Have fun !
分享到:
相关推荐
Copysets Reducing the Frequency of Data Loss in Cloud Storage,Copysets Reducing the Frequency of Data Loss in Cloud Storage
语言:English提供指向项目和管理区域的快速链接。这是针对具有管理员权限并访问许多不同的Jira项目的用户。Jira Ninja面向需要定期在多个项目之间切换的管理员和高级用户。扩展程序的建立是由于在Jira上浏览的无奈而...
提供项目和管理区域的快速链接。这是针对管理和访问许多不同Jira项目的用户。 Jira Ninja面向需要定期在多个项目之间切换的管理员和高级用户。 扩展程序的建立是由于在Jira上浏览的无奈而造成的。...
一篇发表在USENIX Security'15会议上的论文LinkDroid: Reducing Unregulated Aggregation of App Usage Behaviors。这篇文章对APP之间通过信息链接造成的隐私泄漏问题进行了研究,并提出了保护方案 。 Abstract & ...
MySQL Stored Procedure Programming Advance Praise for MySQL Stored Procedure Programming Preface Objectives of This Book Structure of This Book What This Book Does Not Cover Conventions ...
1. **连续集成的基本概念** - CI的核心理念在于频繁地将代码合并到主分支,并通过自动化测试和构建过程来快速反馈问题,从而保证代码的质量和稳定性。 - 实践CI的关键步骤包括版本控制系统的选择、构建脚本的编写...
本文主要基于Martin Fowler的文章《Reducing Coupling》,探讨面向对象设计中的耦合问题以及如何有效降低耦合度,提高软件的设计质量。 #### 二、耦合的定义及其类型 耦合是指两个或多个模块之间存在的依赖关系。...
批量规范化对加速和改进深部模型的训练是非常有效的。但是,当训练小批量或不包含独立样本时,其有效性会降低。我们假设这是由于模型层对小批量中所有示例的依赖性,以及在训练和推理之间产生的不同激活。...
**Oriented Speckle Reducing Anisotropic Diffusion (OSRAD) 算法详解** 在图像处理领域,Oriented Speckle Reducing Anisotropic Diffusion(OSRAD)算法是一种有效的图像去斑技术,特别适用于含有散斑噪声的医学...
**Oriented Speckle Reducing Anisotropic Diffusion (OSRAD) 算法详解** 在图像处理领域,Oriented Speckle Reducing Anisotropic Diffusion(OSRAD)算法是一种有效的图像去斑技术,尤其适用于医学超声图像处理。...
2024 MCM Problems Problem A: Resource Availability and Sex Ratios Problem B: Searching for Submersibles Problem C: Momentum in Tennis Problem C: Data ...Problem F: Reducing Illegal Wildlife Trade
1. 能够学习非线性关系的数据 2. 能够学习高维度数据的低维度表示 3. 能够处理大规模数据 4. 能够实现数据的可视化和分类 结论 神经网络在降维数据中的应用是一种强大且有效的方法。通过使用autoencoder,神经网络...
1. **计算均值与方差**:对每个批次的数据,计算其在该层的激活值的均值和方差。 2. **标准化**:将每个激活值减去均值并除以方差,这样就使得数据在该层的分布接近标准正态分布,减少了内部协变量漂移。 3. **缩放...
从给定的文件信息来看,标题“通过神经网络降低数据维度”与部分描述及内容存在主题上的不匹配,描述和内容更多地涉及了光学、非线性光学效应以及表面二次谐波生成(SHG)的研究,而非神经网络或数据降维。...
作者:Hinton, GE (Hinton, G. E.); Salakhutdinov, RR (Salakhutdinov, R. R.) SCIENCE 卷: 313 期: 5786 页: 504-507 DOI: 10.1126/science.1127647 出版年: JUL 28 2006
for r = 1:1:imageSize(1) for c = 1:1:imageSize(2) img(r, c) = fix(double(image(r, c)) / num) * 255 / (level - 1); end end end ``` 这段代码的关键部分在于`fix(double(image(r, c)) / num)`,这里使用...
在本文中,将要探讨的是如何使用神经网络来降低数据的维度,这项研究由G.E.Hinton和R.R.Salakhutdinov共同撰写,并发表在《Science》杂志上。文章发表于2006年,并且文章引用标识为DOI: 10.1126/science.***。...