简体   繁体   English

MySQL InnoDB:如何完全清除所有剩余的事务更改

[英]MySQL InnoDB: how to completely flush all remaining transactional changes

I had to kill an alter table (copy to tmp table) process, because my server was running low on disk space. 我必须终止一个alter table(复制到tmp表)进程,因为我的服务器磁盘空间不足。 My ibdata file is now 40 GB big and there are just 8 GB disk space left (no, I can't add disk space atm and I can't use a ram disk, since the server only has 8 GB ram). 我的ibdata文件现在大40 GB,仅剩8 GB磁盘空间(不,我不能添加磁盘空间atm,并且我不能使用ram磁盘,因为服务器只有8 GB ram)。

From my understanding even I killed the alter table process MySQL will try to complete it as soon as there's enough disk space available. 据我了解,即使我杀死了alter table进程,只要有足够的磁盘空间,MySQL就会尝试完成它。

According to "show status like '%tmp%';" 根据“显示状态如'%tmp%';” there are 0 tmp tables and 5 tmp files. 有0个tmp表和5个tmp文件。

According to "SHOW ENGINE INNODB STATUS;" 根据《 SHOW ENGINE INNODB STATUS》; there is just one "transaction 0, not started" entry (and a few file I/O ones). 只有一个“事务0,未启动”条目(和一些文件I / O条目)。

According to the information schema my table is approx. 根据信息架构,我的表约为。 20 GB and my ibdata file is 40 GB (I just have a single InnoDB table on this database). 20 GB,我的ibdata文件是40 GB(此数据库上只有一个InnoDB表)。

Is there a way to flush all pending changes and/or delete all tmp tables (even show status does not list one)? 有没有办法刷新所有未决的更改和/或删除所有tmp表(即使show status也不列出其中一个)?

I also wondering why my innodb_buffer_pool_size is set to 8 GB (on a 8 GB ram server). 我也想知道为什么将我的innodb_buffer_pool_size设置为8 GB(在8 GB的ram服务器上)。 I did not alter any InnoDB settings and there are actually none in my my.cnf file, so this seems to be some default value? 我没有更改任何InnoDB设置,而且my.cnf文件中实际上没有任何设置,因此这似乎是一些默认值吗?

Thanks: Lars 谢谢:拉斯

You're right, even if you kill the ALTER TABLE , it continues to try to create a new copy of the table, and this operation is "killed" only after it has finished that step. 没错,即使您杀死ALTER TABLE ,它也会继续尝试创建表的新副本,并且只有在完成该步骤后,此操作才会被“杀死”。 There's no way to interrupt it, short of kill -9 on the mysqld process. 没有办法中断它, kill -9在mysqld进程中将kill -9 Note that it'll generate errors if it run out of disk space. 请注意,如果磁盘空间不足,它将产生错误。 I think it'll abort the ALTER TABLE at that time, clean up the temp table, and then finish. 我认为那时它将中止ALTER TABLE ,清理临时表,然后完成。

As for your question about flushing changes, there's no command to flush the work being done by ALTER TABLE . 至于您有关刷新更改的问题,没有命令可以刷新ALTER TABLE完成的工作。 For other types of changes, if you set global innodb_fast_shutdown=0 and then shut down mysqld, this will flush all dirty pages in the buffer pool, purge any garbage in the rollback segment, and merge any pending index changes in the change buffer. 对于其他类型的更改,如果set global innodb_fast_shutdown=0 ,然后关闭mysqld,这将刷新缓冲池中的所有脏页,清除回滚段中的所有垃圾,并合并更改缓冲区中所有未决的索引更改。 But this doesn't do anything for ALTER TABLE . 但这对ALTER TABLE没有任何作用。 I believe the result will be that the shutdown will wait until the ALTER TABLE is done. 我相信结果将是关闭将一直等到ALTER TABLE完成。

As for your question about the buffer pool, the default innodb_buffer_pool_size is 128MB, if you don't specify another value. 关于您关于缓冲池的问题,如果您未指定其他值,则默认的innodb_buffer_pool_size为128MB。 You must either have it set to 8GB in a config file. 您必须在配置文件中将其设置为8GB。 Note that Ubuntu supports a directory /etc/mysql/conf.d where multiple config files reside, and this can be set in any of these config files. 请注意,Ubuntu支持在目录/etc/mysql/conf.d中驻留多个配置文件,可以在任何这些配置文件中进行设置。


You may have a big ibdata1 file, with nothing taking up the extra space. 您可能有一个很大的ibdata1文件, 没有任何文件占用额外的空间。

Temporary tables are cleaned up when MySQL is done with them, but it may have increased the size of the ibdata1 file while it was in use. 当完成MySQL临时表时,它们会被清除,但是使用时ibdata1文件的大小可能会增加。 MySQL does not shrink the ibdata1 file, but it will reuse the allocated space for later data. MySQL不会收缩ibdata1文件,但是它将为以后的数据重用分配的空间。

Yes, the only way to shrink ibdata1 is to dump all your InnoDB data, shut down mysqld, physical rm the ibdata1 file, then start mysqld, then reimport your dumped data. 是的,萎缩ibdata1中的唯一方法是转储所有InnoDB的数据,关闭的mysqld,物理rm的ibdata1中的文件,然后启动mysqld,然后重新导入转储的数据。 This has been a major inconvenience for MySQL users for many years. 多年来,这一直是MySQL用户的主要不便。

Before you import your data, it's recommended to enable innodb_file_per_table so that you don't face this difficulty in the future. 导入数据之前,建议启用innodb_file_per_table以免将来再遇到此困难。 MySQL still needs an ibdata1 for global InnoDB data, but it should stay smaller. MySQL仍然需要一个ibdata1来存储全局InnoDB数据,但是它应该保持较小的大小。 And anytime you drop or alter any InnoDB table (temporary or not), it'll reclaim some disk space. 每当您删除或更改任何InnoDB表(临时或非临时表)时,它都会回收一些磁盘空间。 This is in fact enabled by default in MySQL 5.6. 实际上,默认情况下在MySQL 5.6中启用了此功能。


mysqld looks for a my.cnf in several places: mysqld在几个地方寻找my.cnf:

  1. /var/lib/mysql/my.cnf (the datadir) /var/lib/mysql/my.cnf(数据目录)
  2. /usr/my.cnf (the basedir) /usr/my.cnf(基于baseir)
  3. /etc/my.cnf /etc/my.cnf中

So check those locations for another my.cnf that has the mystery setting for innodb_buffer_pool_size=8G . 因此,请检查那些位置是否具有innodb_buffer_pool_size=8G ,该my.cnf具有innodb_buffer_pool_size=8G的神秘设置。

For lots of details on how MySQL finds the my.cnf, see http://dev.mysql.com/doc/refman/5.6/en/option-files.html 有关MySQL如何找到my.cnf的详细信息,请参见http://dev.mysql.com/doc/refman/5.6/en/option-files.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM