如何清理ibdata1
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的更多相关文章
- 修改ibdata1大小的验证以及如何使用mysqld_multi管理多实例
修改ibdata1大小的验证 ibdata是共享表空间,在MySQL初始化的时候就生成了. 但很多童鞋会看到网上各种大神的调优建议,在MySQL已经初始化的情况下,修改配置文件中innodb_data ...
- 二进制日志BINARY LOG清理
mysql> show master logs; +------------------+-----------+ | Log_name | File_size | +------------- ...
- mysql中ibdata1过大的问题
ibdata1文件是什么? 答: ibdata1是一个用来构建innodb系统表空间的文件,这个文件包含了innodb表的元数据.撤销记录.修改buffer和双写buffer.如果file-per-t ...
- Discuz论坛黑链清理教程
本人亲测有效,原创文章哦~~~ 论坛黑链非常的麻烦,如果你的论坛有黑链,那么对不起,百度收录了你的黑链,不会自动删除,需要你手动去清理. 什么是黑链 黑链,顾名思义,就是一些赌博网站的外链,这些黑链相 ...
- Windows更新清理工具 (winsxs 清理工具)
Windows 更新清理工具是一款效果非常显著的Windows7.Windows8操作系统清理优化工具!经常安装系统的朋友相比有所体会,刚刚安装完成的Win7.Win8其实占的空间并不大,去掉页面文件 ...
- 如何在删除ibdata1和ib_logfile的情况下恢复MySQL数据库
昨天,有个朋友对公司内部使用的一个MySQL实例开启binlog,但是在启动的过程中失败了(他也没提,为何会失败),在启动失败后,他删除了ibdata1和ib_logfile,后来,能正常启动了,但所 ...
- 如何在Windows Server 2008 R2没有磁盘清理工具的情况下使用系统提供的磁盘清理工具
今天,刚好碰到服务器C盘空间满的情况,首先处理了临时文件和有关的日志文件后空间还是不够用,我知道清理C盘的方法有很多,但今天只分享一下如何在Windows Server 2008 R2没有磁盘清理工具 ...
- 跨平台日志清理工具 Log-Cutter v2.0.1 正式发布
Log-Cutter 是JessMA开源组织开发的一个简单实用的日志切割清理工具.对于服务器的日常维护来说,日志清理是非常重要的事情,如果残留日志过多则严重浪费磁盘空间同时影响服务的性能.如果用手工方 ...
- 解决Android后台清理APP后,程序自动重启的问题
最近解决了一个Android APP的bug,发现APP在被后台清理后,会自动重启.现象很奇怪,有的手机(HTC)后台清理后,程序会再次重启,而有的手机(小米)则不会.猜想可能是小米手机内部做了处理, ...
随机推荐
- 【LC_Lesson3】---回文数的判别
判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向 ...
- docker-主从服务部署
欢迎访问我的博客http://www.liyblog.top 我的博客里会有更详细的信息,而且留言必回,手把手给你解释不懂的地方 1.mysql部署 mysql镜像拉取 docker pull ...
- ORM _meta
import os if __name__ == '__main__': os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'XadminDemon.se ...
- Jenkins-k8s-helm-harbor-githab-mysql-nfs微服务发布平台实战
基于 K8S 构建 Jenkins 微服务发布平台 实现汇总: 发布流程设计讲解 准备基础环境 K8s环境(部署Ingress Controller,CoreDNS,Calico/Flannel) 部 ...
- 7、python基本数据类型之散列类型
前言:python的基本数据类型可以分为三类:数值类型.序列类型.散列类型,本文主要介绍散列类型. 一.散列类型 内部元素无序,不能通过下标取值 1)字典(dict):用 {} 花括号表示,每一个元素 ...
- (转)宽字节编码类型的XSS
今晚又看了一遍PKAV-心上的瘦子写的xss腾讯系列的例子,收获挺大的,其中对宽字节注入有了更深的了解,又查找了一些相关的资料,整理一下,以备以后查阅 参考文档: http://book.2cto.c ...
- Windos下的一些命令集合
由于在CMD模式下(也就是命令行)有较多的有用的命令.以下是自己平时所记录下来的以帮助平时的任务. 1. 显示计算机的操作系统 wmic os get osarchitecture /value
- CF-528D Fuzzy Search(FFT字符串匹配)
Fuzzy Search 题意: 给定一个模式串和目标串按下图方式匹配,错开位置不多于k 解题思路: 总共只有\(A C G T\)四个字符,那么我们可以按照各个字符进行匹配,比如按照\(A\)进行匹 ...
- Warshall算法求传递闭包及具体实现
传递闭包 在数学中,在集合 X 上的二元关系 R 的传递闭包是包含 R 的 X 上的最小的传递关系. 例如,如果 X 是(生或死)人的集合而 R 是关系“为父子”,则 R 的传递闭包是关系“x 是 y ...
- Docker快速上手之搭建SpringBoot项目
Docker是基于Go语言实现的云开源项目. Docker的主要目标是“Build,Ship and Run Any App,Anywhere”,也就是通过对应用组件的封装.分发.部署.运行等生命周期 ...