千家信息网

mysql中怎么删除ibdata文件

发表于:2025-11-09 作者:千家信息网编辑
千家信息网最后更新 2025年11月09日,本篇文章给大家分享的是有关mysql中怎么删除ibdata文件,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。在数据文件下的innodb
千家信息网最后更新 2025年11月09日mysql中怎么删除ibdata文件

本篇文章给大家分享的是有关mysql中怎么删除ibdata文件,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。


在数据文件下的innodb ibdata包括表空间:ibdata1,ibdata2,回滚日志ib_logfile0,ib_logfile1,ib_logfile2.
[root@localhost data]# ls
5k72 db-bin.000015 dbjijin-bin.000001 ibdata1 ib_logfile1 localhost-slow.log mysql.err test
auto.cnf db-bin.000016 dbjijin-bin.000002 ibdata2 ib_logfile2 monitor performance_schema test333
db-bin.000014 db-bin.index dbjijin-bin.index ib_logfile0 localhost.localdomain.pid mysql rrr ttt
[root@localhost data]#

现在删除这几个文件:

[root@localhost data]# rm -f ib*
[root@localhost data]# ls
5k72 db-bin.000015 dbjijin-bin.000001 localhost-slow.log mysql.err test
auto.cnf db-bin.000016 dbjijin-bin.000002 monitor performance_schema test333
db-bin.000014 db-bin.index dbjijin-bin.index localhost.localdomain.pid mysql rrr ttt
[root@localhost data]#

删除之后,数据库还可以正常工作,切记不要停止mysql服务,不然神仙也难救.....

先找到mysql的pid.
[root@localhost data]# netstat -ntlp|grep mysqld
tcp 0 0 :::3307 :::* LISTEN 4863/mysqld
tcp 0 0 :::3306 :::* LISTEN 2169/mysqld


第一个是我们需要的pid号,4863
通过pid号,找到相关的文件,红色标记的是我们需要的文件:
[root@localhost data]# ll /proc/4863/fd
total 0
lr-x------. 1 root root 64 Apr 24 10:58 0 -> /dev/null
l-wx------. 1 root root 64 Apr 24 10:58 1 -> /home/mysql3307/data/mysql.err
lrwx------. 1 root root 64 Apr 24 10:58 10 -> /home/mysql3307/data/ib_logfile0 (deleted)
lrwx------. 1 root root 64 Apr 24 10:58 11 -> /home/mysql3307/data/ib_logfile1 (deleted)
lrwx------. 1 root root 64 Apr 24 10:58 12 -> /home/mysql3307/data/ib_logfile2 (deleted)
.
..
...
lrwx------. 1 root root 64 Apr 24 10:58 4 -> /home/mysql3307/data/ibdata1 (deleted)
..
...
....
lrwx------. 1 root root 64 Apr 24 10:58 9 -> /home/mysql3307/data/ibdata2 (deleted)

这时,需要暂停前端的业务,也就是需要停止数据的写操作.
关闭业务,或者: flush tables with read lock;
然后把脏页尽快刷入到磁盘里,
mysql>set global innodb_max_dirty_pages_pct=0;
然后查看binlog日志写入情况,确保file和position的值没有变化
Your MySQL connection id is 7
Server version: 5.6.20-log Source distribution
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| db-bin.000016 | 3415 | | | |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| db-bin.000016 | 3415 | | | |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| db-bin.000016 | 3415 | | | |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| db-bin.000016 | 3415 | | | |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

然后查看innodb状态信息,确保脏页已经刷入磁盘.
mysql> show engine innodb status \G
************************** 1. row ***************************
Type: InnoDB
Name:
Status:
=====================================
2015-04-24 11:51:52 7f7038202700 INNODB MONITOR OUTPUT
------------
TRANSACTIONS
------------
Trx id counter 18696
Purge done for trx's n:o < 18696 undo n:o < 0 state: running but idle
##确保后台purge进程吧 undo log 全部清除掉,事务id要一致.

-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
## insert buffer 合并插入缓存等于1
---
LOG
---
Log sequence number 5196495
Log flushed up to 5196495
Pages flushed up to 5196495
Last checkpoint at 5196495
## 确保这4个值不会变

----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 1098907648; in additional pool allocated 0
Dictionary memory allocated 74136
Buffer pool size 65528
Free buffers 65121
Database pages 406
Old database pages 0
Modified db pages 0
## 确保脏页数据为0

--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Main thread process no. 1964, id 140119885477632, state: sleeping
Number of rows inserted 1, updated 0, deleted 0, read 4
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
## 确保插入,更新,删除为0


经过上面确认后,可以进行恢复操作了.复制上面表示部分数据到数据库目录:
[root@localhost fd]# cp 4 /home/mysql3307/data/ibdata1
[root@localhost fd]# cp 10 /home/mysql3307/data/ib_logfile0
[root@localhost fd]# cp 11 /home/mysql3307/data/ib_logfile1
[root@localhost fd]# cp 12 /home/mysql3307/data/ib_logfile2
给文件授权:
[root@localhost fd]# chown mysql:mysql /home/mysql3307/data/ib*

以上就是mysql中怎么删除ibdata文件,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注行业资讯频道。

文件 数据 业务 数据库 日志 更多 知识 磁盘 篇文章 部分 工作 实用 一致 也就是 事务 信息 前端 后台 就是 工作会 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 网络运营商网站服务器 数据库进阶学习 网络安全检查表及答案 网络技术上机实验心得 福建好的软件开发创新服务 法那克盾机服务器维修销售 学校网络安全发展规划与实践 软件开发协议及验收单 软件开发团队有人不写代码吗 网络安全岗位职业道德 服务器错误无法打开网页 家庭影视服务器的数据 建立和完善建设工程数据库 万达软件开发的啥项目 ukey网络安全认证失败 数据库动态更新方法周期 Iswine数据库 网络安全论文免费 世纪英梵网络技术有限公司官网 服务器管理口什么意思 巡警大队开展内部网络安全排查 服务器硬盘托架规格 网络安全人人有责主题班会 北京凤天优网络技术有限公司 焦作软件开发培训班 市网络安全支队有几人 西安软件开发两年薪资多少钱 杭州米达尔网络技术有限公司 网络技术人员个人简历 上海市人口普查数据库
0