千家信息网

Mysql中误删ibdata ib_logfile等文件怎么办

发表于:2024-12-13 作者:千家信息网编辑
千家信息网最后更新 2024年12月13日,这篇文章主要介绍了Mysql中误删ibdata ib_logfile等文件怎么办,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。背景:误
千家信息网最后更新 2024年12月13日Mysql中误删ibdata ib_logfile等文件怎么办

这篇文章主要介绍了Mysql中误删ibdata ib_logfile等文件怎么办,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

背景:误删ibdata等文件

  1. [root@localhost /var/lib/mysql ]# rm -rf ib*

  2. ib_buffer_pool ibdata1 ib_logfile0 ib_logfile1 ibtmp1


此时不要惊慌,因为mysql还是在运行的,也行进行操作,,如果关了mysql那就没办法了,恢复步骤如下
1.关闭所有业务写入

  1. flush tables with read lock


2.查看mysql的pid号

  1. [root@localhost /var/lib/mysql ]# ps -ef | grep -i mysql

  2. root 386 1 0 May06 ? 00:00:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf

  3. mysql 491 386 0 May06 ? 00:16:13 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/usr/local/mariadb/demo --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/usr/local/mariadb/demo/mardb.err --pid-file=/usr/local/mariadb/demo/mardb.pid --socket=/usr/local/mariadb/demo/mardb.socket --port=3333

  4. root 14790 1 0 14:06 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql

  5. mysql 15010 14790 0 14:06 ? 00:00:05 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock

  6. root 18180 17974 0 15:03 pts/3 00:00:00 grep -i mysql

  7. [root@localhost /var/lib/mysql ]# netstat -nputl|grep -i mysql

  8. tcp 0 0 :::3333 :::* LISTEN 491/mysqld

  9. tcp 0 0 :::3306 :::* LISTEN 15010/mysqld



3 进入linux系统自带的虚拟目录proc查看文件是否还存在

  1. [root@localhost /var/lib/mysql ]# ll /proc/15010/fd | grep -i 'ib'
    lrwx------ 1 root root 64 May 12 15:03 10 -> /var/lib/mysql/ibtmp1 (deleted)
    lrwx------ 1 root root 64 May 12 15:03 3 -> /var/lib/mysql/ibdata1 (deleted)
    lrwx------ 1 root root 64 May 12 15:03 8 -> /var/lib/mysql/ib_logfile0 (deleted)
    lrwx------ 1 root root 64 May 12 15:03 9 -> /var/lib/mysql/ib_logfile1 (deleted)


4.输入命令让脏快速度刷新到磁盘

  1. mysql> set global innodb_max_dirty_pages_pct=0;


5 确保binlog pos和file不变

  1. mysql> show master status;

  2. +------------------+-----------+--------------+------------------+--------------------------------------------------+

  3. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

  4. +------------------+-----------+--------------+------------------+--------------------------------------------------+

  5. | mysql-bin.000176 | 449250839 | | | 6c8a10ed-ed0b-11e4-91eb-00163ec546ca:1-212063619 |

  6. +------------------+-----------+--------------+------------------+--------------------------------------------------+

  7. 1 row in set (0.00 sec)


6.查看engine innodb的信息

  1. 如:

  2. mysql> show engine innodb status\G;
    *************************** 1. row ***************************
    Type: InnoDB
    Name:
    Status:
    =====================================
    2016-05-12 15:25:55 0x7f7692d0e700 INNODB MONITOR OUTPUT
    =====================================
    Per second averages calculated from the last 10 seconds
    -----------------
    BACKGROUND THREAD
    -----------------
    srv_master_thread loops: 35 srv_active, 0 srv_shutdown, 585 srv_idle
    srv_master_thread log flush and writes: 620
    ----------
    SEMAPHORES
    ----------
    OS WAIT ARRAY INFO: reservation count 17
    OS WAIT ARRAY INFO: signal count 15
    RW-shared spins 0, rounds 63, OS waits 6
    RW-excl spins 0, rounds 11, OS waits 0
    RW-sx spins 0, rounds 0, OS waits 0
    Spin rounds per wait: 63.00 RW-shared, 11.00 RW-excl, 0.00 RW-sx
    ------------
    TRANSACTIONS
    ------------
    Trx id counter 3625
    Purge done for trx's n:o < 3625 undo n:o < 0 state: running but idle ==确认后台进程吧undo log全部清除掉,事物id要一致
    History list length 71
    LIST OF TRANSACTIONS FOR EACH SESSION:
    ---TRANSACTION 421622043023184, not started
    0 lock struct(s), heap size 1136, 0 row lock(s)
    --------
    FILE I/O
    --------
    I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
    I/O thread 1 state: waiting for completed aio requests (log thread)
    I/O thread 2 state: waiting for completed aio requests (read thread)
    I/O thread 3 state: waiting for completed aio requests (read thread)
    I/O thread 4 state: waiting for completed aio requests (read thread)
    I/O thread 5 state: waiting for completed aio requests (read thread)
    I/O thread 6 state: waiting for completed aio requests (write thread)
    I/O thread 7 state: waiting for completed aio requests (write thread)
    I/O thread 8 state: waiting for completed aio requests (write thread)
    I/O thread 9 state: waiting for completed aio requests (write thread)
    Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
    ibuf aio reads:, log i/o's:, sync i/o's:
    Pending flushes (fsync) log: 0; buffer pool: 0
    459 OS file reads, 134 OS file writes, 55 OS fsyncs
    0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
    -------------------------------------
    INSERT BUFFER AND ADAPTIVE HASH INDEX
    -------------------------------------
    Ibuf: size 1, free list len 0, seg size 2, 0 merges ===合并插入 insert buffer为1
    merged operations:
    insert 0, delete mark 0, delete 0
    discarded operations:
    insert 0, delete mark 0, delete 0
    Hash table size 34679, node heap has 0 buffer(s)
    Hash table size 34679, node heap has 0 buffer(s)
    Hash table size 34679, node heap has 0 buffer(s)
    Hash table size 34679, node heap has 0 buffer(s)
    Hash table size 34679, node heap has 0 buffer(s)
    Hash table size 34679, node heap has 0 buffer(s)
    Hash table size 34679, node heap has 0 buffer(s)
    Hash table size 34679, node heap has 0 buffer(s)
    0.00 hash searches/s, 0.00 non-hash searches/s
    ---
    LOG
    ---
    Log sequence number 14905664
    Log flushed up to 14905664
    Pages flushed up to 14905664
    Last checkpoint at 14905655 ===确保三个日志记录不再变化
    0 pending log flushes, 0 pending chkp writes
    55 log i/o's done, 0.00 log i/o's/second
    ----------------------
    BUFFER POOL AND MEMORY
    ----------------------
    Total large memory allocated 137428992
    Dictionary memory allocated 371621
    Buffer pool size 8192
    Free buffers 7862
    Database pages 330
    Old database pages 0
    Modified db pages 0 ====确认脏页书数量为0
    Pending reads 0
    Pending writes: LRU 0, flush list 0, single page 0
    Pages made young 0, not young 0
    0.00 youngs/s, 0.00 non-youngs/s
    Pages read 296, created 34, written 72
    0.00 reads/s, 0.00 creates/s, 0.00 writes/s
    No buffer pool page gets since the last printout
    Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
    LRU len: 330, unzip_LRU len: 0
    I/O sum[0]:cur[0], unzip sum[0]:cur[0]
    --------------
    ROW OPERATIONS
    --------------
    0 queries inside InnoDB, 0 queries in queue
    0 read views open inside InnoDB
    Process ID=19640, Main thread ID=140146326370048, state: sleeping
    Number of rows inserted 34, updated 0, deleted 0, read 9
    0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s ===确保插入 更新 删除为0
    ----------------------------
    END OF INNODB MONITOR OUTPUT
    ============================


    1 row in set (0.00 sec)


    ERROR:
    No query specified



6.将文件恢复并修改权限

  1. [root@localhost /proc/15010/fd ]# cp 10 /var/lib/mysql/ibtmp1

  2. [root@localhost /proc/15010/fd ]# cp 3 /var/lib/mysql/ibdata1

  3. [root@localhost /proc/15010/fd ]# cp 8 /var/lib/mysql/ib_logfile0

  4. [root@localhost /proc/15010/fd ]# cp 9 /var/lib/mysql/ib_logfile1

  5. [root@localhost /proc/15010/fd ]# chown mysql.mysql /var/lib/mysql/ibtmp1

  6. [root@localhost /proc/15010/fd ]# chown mysql.mysql /var/lib/mysql/ibdata1

  7. [root@localhost /proc/15010/fd ]# chown mysql.mysql /var/lib/mysql/ib_logfile*


7。重启mysql即可

感谢你能够认真阅读完这篇文章,希望小编分享的"Mysql中误删ibdata ib_logfile等文件怎么办"这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!

文件 篇文章 怎么办 一致 惊慌 三个 业务 事物 价值 信息 兴趣 办法 同时 后台 命令 数量 日志 更多 朋友 权限 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 广警网络安全提前批录取排名 一个公司如何设置数据库 杭州奕鸣网络技术有限公司 中国食品用香料数据库网址 学校计算机机房 网络安全 服务器开机选择计划内还是计划外 数据管理服务器编码 我的世界一句话把一个服务器崩掉 特定领域软件开发的设计及其应用 doris数据库部署 建立一个myNCBI数据库 三星8500服务器内存条 点电话显示服务器错误什么问题 山东省网络技术大赛 园区 网络安全有感500 南京市网络安全处处长 sql2000服务器配置 网络技术将如何改变能源产业 企业服务器搭建顺序 数据仓库是数据库吗 计算机网络技术的讲解 电子书网络安全通信协议 数据库技术报名条件 access数据库如何加列 网络安全细思极恐细节 阳山县网络安全宣传周 数据库表中查找字段 秋月之光服务器怎么全部对话 山东公安网安招聘网络安全 软件开发怎么找外包
0