资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

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文件,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。


网站栏目:mysql中怎么删除ibdata文件
浏览路径:http://www.cdkjz.cn/article/jcegop.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220