您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關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文件,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。