1, 加锁,然后全备份数据,可以用mysqldump,也可以使用其他的工具:

[root@localhost data]# mysqldump --all-databases > /root/all_databases.sql

2,修改my.cnf文件为你想要的大小

innodb_data_home_dir=/tmp/mysql-5.6/data
innodb_data_file_path=ibdata1:200M:autoextend:max:2G

注: ibdata1有最小限制

• For an innodb_page_size value of 16KB or less, the minimum file size is 3MB.
• For an innodb_page_size value of 32KB, the minimum file size is 6MB.
• For an innodb_page_size value of 64KB, the minimum file size is 12MB.

3, 删除ibdata1和ib_logfile0,ib_logfile1,ib_logfile2

[root@localhost data]# ls
a.sql b.sql ib_logfile0 itdb localhost-relay-bin.index mysql-bin.000001 mysql-bin.000004 mysql-bin.000007 percona test
auto.cnf db2.sql ib_logfile1 localhost.localdomain.pid master.info mysql-bin.000002 mysql-bin.000005 mysql-bin.000008 performance_schema
books ibdata1 ib_logfile2 localhost-relay-bin.000008 mysql mysql-bin.000003 mysql-bin.000006 mysql-bin.index relay-log.info [root@localhost data]#
[root@localhost data]# rm -rf ibdata1
[root@localhost data]# rm -rf ib_log* [root@localhost data]# ls
a.sql books db2.sql localhost.localdomain.pid localhost-relay-bin.index mysql mysql-bin.000002 mysql-bin.000004 mysql-bin.000006 mysql-bin.000008 percona relay-log.info
auto.cnf b.sql itdb localhost-relay-bin.000008 master.info mysql-bin.000001 mysql-bin.000003 mysql-bin.000005 mysql-bin.000007 mysql-bin.index performance_schema test
[root@localhost data]#

4,重启mysql,此时发现ibdata1变成我们想要的大小了;

[root@localhost data]# service mysqld restart
Shutting down MySQL.... SUCCESS!
Starting MySQL... SUCCESS!
[root@localhost data]# du -sh ibdata1
201M ibdata1
[root@localhost data]#

5, 登陆mysql,删除数据库,此时发现无法删除;因为数据字典所在的表空间被删了;

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| books |
| itdb |
| mysql |
| percona |
| performance_schema |
| test |
+--------------------+
7 rows in set (0.00 sec) mysql> drop database books;
ERROR 1010 (HY000): Error dropping database (can't rmdir './books', errno: 39)
mysql>

此时把database文件夹移走;performance_schema不要动,其他的都移走

root@localhost data]# ls
auto.cnf ibdata1 ib_logfile1 itdb localhost-relay-bin.000004 master.info mysql-bin.000001 mysql-bin.000003 mysql-bin.index performance_schema test
books ib_logfile0 ib_logfile2 localhost.localdomain.pid localhost-relay-bin.index mysql mysql-bin.000002 mysql-bin.000004 percona relay-log.info
[root@localhost data]# mkdir /bak
[root@localhost data]# mv itdb books mysql percona test /bak
[root@localhost data]# ls
auto.cnf ib_logfile0 ib_logfile2 localhost-relay-bin.000004 master.info mysql-bin.000002 mysql-bin.000004 performance_schema
ibdata1 ib_logfile1 localhost.localdomain.pid localhost-relay-bin.index mysql-bin.000001 mysql-bin.000003 mysql-bin.index relay-log.info
[root@localhost data]#

移完之后,查看系统只有information_schema和performance_schema2个库;
然后进行恢复数据

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| performance_schema |
+--------------------+
2 rows in set (0.00 sec) mysql>
[1]+ Stopped mysql (wd: /tmp/mysql-5.6/data)
(wd now: ~)
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# mysql -e "source /root/all_databases.sql" > source.log

然后查看数据:

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| books |
| itdb |
| mysql |
| percona |
| performance_schema |
| test |
+--------------------+
7 rows in set (0.00 sec) mysql> use itdb
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> show tables;
+------------------+
| Tables_in_itdb |
+------------------+
| contact |
| customers |
| kepler_promotion |
| orderitems |
| orders |
| productnotes |
| products |
| shopping |
| tt |
| vendors |
+------------------+
mysql> select * from contact limit 5;
+----+---------+-------+------+---------------+
| id | user_id | name | ext | email |
+----+---------+-------+------+---------------+
| 0 | 0 | NULL | NULL | NULL |
| 1 | 1 | user1 | 2000 | user1@163.com |
| 2 | 2 | user2 | 2001 | user2@163.com |
| 3 | 3 | user3 | 2002 | user1@164.com |
| 4 | 4 | user4 | 2003 | user2@164.com |
+----+---------+-------+------+---------------+
5 rows in set (0.01 sec)

OK,完成;
重启下服务,查看错误日志,看是否有ERR;经查没有,OK,完成

2018-01-21 13:06:42 127993 [Note] Plugin 'FEDERATED' is disabled.
2018-01-21 13:06:42 127993 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-01-21 13:06:42 127993 [Note] InnoDB: The InnoDB memory heap is disabled
2018-01-21 13:06:42 127993 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-01-21 13:06:42 127993 [Note] InnoDB: Memory barrier is not used
2018-01-21 13:06:42 127993 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-01-21 13:06:42 127993 [Note] InnoDB: Using Linux native AIO
2018-01-21 13:06:42 127993 [Note] InnoDB: Using CPU crc32 instructions
2018-01-21 13:06:42 127993 [Note] InnoDB: Initializing buffer pool, size = 64.0M
2018-01-21 13:06:42 127993 [Note] InnoDB: Completed initialization of buffer pool
2018-01-21 13:06:42 127993 [Note] InnoDB: Highest supported file format is Barracuda.
2018-01-21 13:06:42 127993 [Note] InnoDB: 128 rollback segment(s) are active.
2018-01-21 13:06:42 127993 [Note] InnoDB: Waiting for purge to start
2018-01-21 13:06:42 127993 [Note] InnoDB: 5.6.36 started; log sequence number 1854145
2018-01-21 13:06:42 127993 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
2018-01-21 13:06:42 127993 [Note] - '0.0.0.0' resolves to '0.0.0.0';
2018-01-21 13:06:42 127993 [Note] Server socket created on IP: '0.0.0.0'.
2018-01-21 13:06:42 127993 [Warning] Neither --relay-log nor --relay-log-index were used; so replication may break when this MySQL server acts as a slave and has his hostname changed!! Please use '--relay-log=localhost-relay-bin' to avoid this problem.
2018-01-21 13:06:42 127993 [Note] Event Scheduler: Loaded 0 events
2018-01-21 13:06:42 127993 [Note] /tmp/mysql-5.6/bin/mysqld: ready for connections.
Version: '5.6.36-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)
2018-01-21 13:06:42 127993 [Warning] Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
2018-01-21 13:06:42 127993 [Warning] Slave SQL: If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0
2018-01-21 13:06:42 127993 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.000003' at position 1205, relay log './localhost-relay-bin.000001' position: 4

我这是mysql 5.6版本,经测试mysql 5.7版本也是一样的方法,移动的时候多了个sys的库也要一起移走;其他一样;

如何清理ibdata1的更多相关文章

  1. 修改ibdata1大小的验证以及如何使用mysqld_multi管理多实例

    修改ibdata1大小的验证 ibdata是共享表空间,在MySQL初始化的时候就生成了. 但很多童鞋会看到网上各种大神的调优建议,在MySQL已经初始化的情况下,修改配置文件中innodb_data ...

  2. 二进制日志BINARY LOG清理

    mysql> show master logs; +------------------+-----------+ | Log_name | File_size | +------------- ...

  3. mysql中ibdata1过大的问题

    ibdata1文件是什么? 答: ibdata1是一个用来构建innodb系统表空间的文件,这个文件包含了innodb表的元数据.撤销记录.修改buffer和双写buffer.如果file-per-t ...

  4. Discuz论坛黑链清理教程

    本人亲测有效,原创文章哦~~~ 论坛黑链非常的麻烦,如果你的论坛有黑链,那么对不起,百度收录了你的黑链,不会自动删除,需要你手动去清理. 什么是黑链 黑链,顾名思义,就是一些赌博网站的外链,这些黑链相 ...

  5. Windows更新清理工具 (winsxs 清理工具)

    Windows 更新清理工具是一款效果非常显著的Windows7.Windows8操作系统清理优化工具!经常安装系统的朋友相比有所体会,刚刚安装完成的Win7.Win8其实占的空间并不大,去掉页面文件 ...

  6. 如何在删除ibdata1和ib_logfile的情况下恢复MySQL数据库

    昨天,有个朋友对公司内部使用的一个MySQL实例开启binlog,但是在启动的过程中失败了(他也没提,为何会失败),在启动失败后,他删除了ibdata1和ib_logfile,后来,能正常启动了,但所 ...

  7. 如何在Windows Server 2008 R2没有磁盘清理工具的情况下使用系统提供的磁盘清理工具

    今天,刚好碰到服务器C盘空间满的情况,首先处理了临时文件和有关的日志文件后空间还是不够用,我知道清理C盘的方法有很多,但今天只分享一下如何在Windows Server 2008 R2没有磁盘清理工具 ...

  8. 跨平台日志清理工具 Log-Cutter v2.0.1 正式发布

    Log-Cutter 是JessMA开源组织开发的一个简单实用的日志切割清理工具.对于服务器的日常维护来说,日志清理是非常重要的事情,如果残留日志过多则严重浪费磁盘空间同时影响服务的性能.如果用手工方 ...

  9. 解决Android后台清理APP后,程序自动重启的问题

    最近解决了一个Android APP的bug,发现APP在被后台清理后,会自动重启.现象很奇怪,有的手机(HTC)后台清理后,程序会再次重启,而有的手机(小米)则不会.猜想可能是小米手机内部做了处理, ...

随机推荐

  1. mysql 查询中文数据

    select * from comm_user WHERE length(tags)!=CHAR_LENGTH(tags)

  2. 《C# 爬虫 破境之道》:第二境 爬虫应用 — 第三节:处理压缩数据

    续上一节内容,本节主要讲解一下Web压缩数据的处理方法. 在HTTP协议中指出,可以通过对内容压缩来减少网络流量,从而提高网络传输的性能. 那么问题来了,在HTTP中,采用的是什么样的压缩格式和机制呢 ...

  3. border 边框

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  4. JavaScript(1)---绑定事件、解除绑定事件

    JavaScript(1)---绑定事件.解除绑定事件 一.事件概述 1.事件的几个概念 · 事件 指的是文档或者浏览器窗口中发生的一些特定交互瞬间.我们可以通过侦听器(或者处理程序)来预定事件,以便 ...

  5. 第二阶段冲刺个人任务——six

    今日任务: 搭建网络服务器,上传数据库及程序. 昨日成果: 合并程序(统计团队博客).

  6. Redis(八):zset/zadd/zrange/zrembyscore 命令源码解析

    前面几篇文章,我们完全领略了redis的string,hash,list,set数据类型的实现方法,相信对redis已经不再神秘. 本篇我们将介绍redis的最后一种数据类型: zset 的相关实现. ...

  7. 一步一步安装配置Ceph分布式存储集群

    Ceph可以说是当今最流行的分布式存储系统了,本文记录一下安装和配置Ceph的详细步骤. 提前配置工作 从第一个集群节点开始的,然后逐渐加入其它的节点.对于Ceph,我们加入的第一个节点应该是Moni ...

  8. Word Embeddings: Encoding Lexical Semantics(译文)

    词向量:编码词汇级别的信息 url:http://pytorch.org/tutorials/beginner/nlp/word_embeddings_tutorial.html?highlight= ...

  9. 项目SpringMVC+Spring+Mybatis 整合环境搭建(1)-> Spring+Mybatis搭建

    目录结构 第一步:web.xml 先配置contextConfigLocation 对应的application-context.xml文件 打开webapp\WEB-INF\web.xml, 配置s ...

  10. LeetCode 380. Insert Delete GetRandom O(1) 常数时间插入、删除和获取随机元素(C++/Java)

    题目: Design a data structure that supports all following operations in averageO(1) time. insert(val): ...