文档章节

InnoDB Infrastructure Cleanup

perfectspr
 perfectspr
发布于 2014/11/11 10:52
字数 712
阅读 43
收藏 3

Here is a more complete answer with regard to InnoDB. It is a bit of a lengthy process, but can be worth the effort.

Keep in mind that /var/lib/mysql/ibdata1 is the busiest file in the InnoDB infrastructure. It normally houses six types of information:

InnoDB Architecture

InnoDB Architecture

Many people create multiple ibdata files hoping for better disk-space management and performance, however that belief is mistaken.

Can I run OPTIMIZE TABLE ?

Unfortunately, running OPTIMIZE TABLE against an InnoDB table stored in the shared table-space file ibdata1 does two things:

  • Makes the table’s data and indexes contiguous inside ibdata1

  • Makes ibdata1 grow because the contiguous data and index pages are appended to ibdata1

You can however, segregate Table Data and Table Indexes from ibdata1 and manage them independently.

Can I run OPTIMIZE TABLE with innodb_file_per_table ?

Suppose you were to add innodb_file_per_table to /etc/my.cnf (my.ini). Can you then just run OPTIMIZE TABLE on all the InnoDB Tables?

Good News : When you run OPTIMIZE TABLE with innodb_file_per_table enabled, this will produce a .ibd file for that table. For example, if you have table mydb.mytable witha datadir of /var/lib/mysql, it will produce the following:

  • /var/lib/mysql/mydb/mytable.frm

  • /var/lib/mysql/mydb/mytable.ibd

The .ibd will contain the Data Pages and Index Pages for that table. Great.

Bad News : All you have done is extract the Data Pages and Index Pages of mydb.mytable from living in ibdata. The data dictionary entry for every table, including mydb.mytable, still remains in the data dictionary (See the Pictorial Representation of ibdata1). YOU CANNOT JUST SIMPLY DELETE ibdata1 AT THIS POINT !!! Please note that ibdata1 has not shrunk at all.

InnoDB Infrastructure Cleanup

To shrink ibdata1 once and for all you must do the following:

  1. Dump (e.g., with mysqldump) all databases into a .sql text file (SQLData.sql is used below)

  2. Drop all databases (except for mysql and information_schema) CAVEAT : As a precaution, please run this script to make absolutely sure you have all user grants in place:

    mkdir /var/lib/mysql_grants
    cp /var/lib/mysql/mysql/* /var/lib/mysql_grants/.
    chown -R mysql:mysql /var/lib/mysql_grants
  3. Login to mysql and run SET GLOBAL innodb_fast_shutdown = 0; (This will completely flush all remaining transactional changes from ib_logfile0 and ib_logfile1)

  4. Shutdown MySQL

  5. Add the following lines to /etc/my.cnf (or my.ini on Windows)

    [mysqld]innodb_file_per_table
    innodb_flush_method=O_DIRECT
    innodb_log_file_size=1G
    innodb_buffer_pool_size=4G

    (Sidenote: Whatever your set for innodb_buffer_pool_size, make sure innodb_log_file_size is 25% of innodb_buffer_pool_size.

    Also: innodb_flush_method=O_DIRECT is not available on Windows)

  6. Delete ibdata* and ib_logfile*, Optionally, you can remove all folders in /var/lib/mysql, except /var/lib/mysql/mysql.

  7. Start MySQL (This will recreate ibdata1 [10MB by default] and ib_logfile0 and ib_logfile1 at 1G each).

  8. Import SQLData.sql

Now, ibdata1 will still grow but only contain table metadata because each InnoDB table will exist outside of ibdata1. ibdata1 will no longer contain InnoDB data and indexes for other tables.

For example, suppose you have an InnoDB table named mydb.mytable. If you look in /var/lib/mysql/mydb, you will see two files representing the table:

  • mytable.frm (Storage Engine Header)

  • mytable.ibd (Table Data and Indexes)

With the innodb_file_per_table option in /etc/my.cnf, you can run OPTIMIZE TABLE mydb.mytable and the file /var/lib/mysql/mydb/mytable.ibd will actually shrink.

I have done this many times in my career as a MySQL DBA. In fact, the first time I did this, I shrank a 50GB ibdata1 file down to only 500MB!

Give it a try. If you have further questions on this, just ask. Trust me; this will work in the short term as well as over the long haul.

CAVEAT

At Step 6, if mysql cannot restart because of the mysql schema begin dropped, look back at Step 2. You made the physical copy of the mysql schema. You can restore it as follows:

mkdir /var/lib/mysql/mysql
cp /var/lib/mysql_grants/* /var/lib/mysql/mysql
chown -R mysql:mysql /var/lib/mysql/mysql

Go back to Step 6 and continue


本文转载自:http://stackoverflow.com/questions/3927690/howto-clean-a-mysql-innodb-storage-engine

共有 人打赏支持
perfectspr
粉丝 5
博文 43
码字总数 1198
作品 0
大连
技术主管
私信 提问
MariaDB 10.2.14 发布,新增磁盘空间监视插件

MariaDB 10.2.14 发布了。MariaDB 主要由开源社区在维护,采用 GPL 授权许可。 MariaDB 的目的是完全兼容 MySQL,包括 API 和命令行。 Notable Changes Added the DISKS plugin, for monito...

mia0x75
2018/03/28
1K
0
MySQL 5.5.29/5.1.67 发布

MySQL 5.5.29/5.1.67发布。2012-12-21 之前的版本是2012-09-28的5.5.28/5.1.66.其他产品线是2012-03-22的5.0.96 下载: ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.5/mysql-5.......

fei
2012/12/21
3.2K
4
mysql innodb断电恢复,不支持innodb,表空间丢失

mysql innodb断电恢复,不支持innodb,表空间丢失 一、需求 在办公网络中有一测试pc,跑mysql服务,周末大厦停电,导致mysql 异常; 具体表象为不支持innodb Current database: kkyoo_ucente...

xiaomaimai
2018/06/26
0
0
mysql自动重启 有时重启后程序连接不上求教啊

160108 9:10:46 InnoDB: Started; log sequence number 0 6784661 160108 9:10:46 [Note] Event Scheduler: Loaded 0 events 160108 9:10:46 [Note] /usr/libexec/mysqld: ready for connect......

hphper
2016/01/18
352
0
mysql-5.6.14-winx64 配置版 配置出现错误

my.ini 内容如下: [WinMySQLAdmin] Server=C:/Program Files/MySQL/bin/mysqld.exe [client] no-beep # pipe # socket=mysql port=3306 [mysql] # For advice on how to change settings p......

TimZhou
2013/10/19
1K
4

没有更多内容

加载失败,请刷新页面

加载更多

LIst的逆向遍历

public class list_demo { public static void main(String[] args) {// TODO Auto-generated method stub List list=new ArrayList<>(); list.add("a"); list.add("b");......

南桥北木
37分钟前
2
0
Linux下端口转发工具rinetd介绍

linux下简单好用的工具rinetd,实现端口映射/转发/重定向,针对TCP协议,不支持UDP。 官网地址 http://www.boutell.com/rinetd 里面介绍及使用齐全。 使用场景举例: 阿里云内网Redis连接问题...

ouhoo
50分钟前
4
0
Oracle学习日志-5(算数运算符,比较运算符和逻辑运算符)

因为有编程基础,所以对于这一章还是很好理解,只需要注意对NULL的运算。 操作的表格 算数运算符 查询商品名字和商品售价,并商品售价乘2 SELECT product_name,sale_price * 2 AS "sale_pri...

白话
今天
1
0
搜索引擎(Lucene介绍、分词器详解)

Lucene介绍 Lucene简介 最受欢迎的java开源全文搜索引擎开发工具包。提供了完整的查询引擎和索引引擎,部分文本分词引擎(英文与德文两种西方语言)。Lucene的目的是为软件开发人员提供一个简...

这很耳东先生
今天
4
0
quartz详细介绍

quartz常用api Scheduler 调度程序交互的主要API。 Job 希望由调度程序执行的组件实现的接口。 JobDetail 用于定义作业的实例。 JobDataMap 可以包含不限量的序列化数据,在job运行的时候可以...

大笨象会跳舞吧
今天
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部