前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MySQL误删除文件场景

MySQL误删除文件场景

作者头像
bisal
发布2023-11-04 09:30:09
3220
发布2023-11-04 09:30:09
举报
文章被收录于专栏:bisal的个人杂货铺

同事反馈说某个测试的MySQL数据库误删除了ibdata1文件,导致库启动不了,而且没做备份,能不能恢复?

如果误删除文件,但是数据库没进行过重启,只要删除的文件句柄还在系统中,就可以进行恢复,可以参考《Linux恢复误删文件的操作》。但是这套环境中,数据库进程已经被删除了,lsof未找到误删除的文件。

而且服务器无任何的备份,所以这条路关闭。

经过确认,可以不要这些数据了,能启动就行。

如果不管ibdata1,直接启动数据库,会提示如下错误,

代码语言:javascript
复制
2023-11-01T05:16:55.058805Z mysqld_safe Logging to '/mysql/3306/log/mysql-error.log'.
2023-11-01T05:16:55.082918Z mysqld_safe Starting mysqld daemon with databases from /mysql/3306/data
2023-11-01T05:16:55.088486Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2023-11-01T05:16:55.088539Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2023-11-01T13:16:55.237280+08:00 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2023-11-01T13:16:55.237309+08:00 0 [Note] /usr/local/mysql7/bin/mysqld (mysqld 5.7.32-log) starting as process 46374 ...
2023-11-01T13:16:55.250775+08:00 0 [Note] InnoDB: PUNCH HOLE support available
2023-11-01T13:16:55.250793+08:00 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2023-11-01T13:16:55.250798+08:00 0 [Note] InnoDB: Uses event mutexes
2023-11-01T13:16:55.250801+08:00 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2023-11-01T13:16:55.250804+08:00 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2023-11-01T13:16:55.250807+08:00 0 [Note] InnoDB: Using Linux native AIO
2023-11-01T13:16:55.250975+08:00 0 [Note] InnoDB: Number of pools: 1
2023-11-01T13:16:55.251057+08:00 0 [Note] InnoDB: Using CPU crc32 instructions
2023-11-01T13:16:55.252307+08:00 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2023-11-01T13:16:55.258902+08:00 0 [Note] InnoDB: Completed initialization of buffer pool
2023-11-01T13:16:55.262430+08:00 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2023-11-01T13:16:55.276886+08:00 0 [ERROR] InnoDB: The Auto-extending innodb_system data file './ibdata1' is of a different size 0 pages (rounded down to MB) than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero) pages!
2023-11-01T13:16:55.276904+08:00 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2023-11-01T13:16:55.888909+08:00 0 [ERROR] Plugin 'InnoDB' init function returned error.
2023-11-01T13:16:55.888944+08:00 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2023-11-01T13:16:55.888949+08:00 0 [ERROR] Failed to initialize builtin plugins.
2023-11-01T13:16:55.888952+08:00 0 [ERROR] Aborting


2023-11-01T13:16:55.888967+08:00 0 [Note] Binlog end
2023-11-01T13:16:55.889025+08:00 0 [Note] Shutting down plugin 'CSV'
2023-11-01T13:16:55.889192+08:00 0 [Note] /usr/local/mysql7/bin/mysqld: Shutdown complete

MySQL 5.7,如果同时删除ib_logfile0、ib_logfile1,启动数据库,是可以自动创建这三个文件的,

代码语言:javascript
复制
2023-11-01T09:13:52.873672Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2023-11-01T09:13:52.873731Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2023-11-01T17:13:53.011913+08:00 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2023-11-01T17:13:53.011946+08:00 0 [Note] /usr/local/mysql7/bin/mysqld (mysqld 5.7.32-log) starting as process 95232 ...
2023-11-01T17:13:53.014739+08:00 0 [Note] InnoDB: PUNCH HOLE support available
2023-11-01T17:13:53.014758+08:00 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2023-11-01T17:13:53.014762+08:00 0 [Note] InnoDB: Uses event mutexes
2023-11-01T17:13:53.014766+08:00 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2023-11-01T17:13:53.014768+08:00 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2023-11-01T17:13:53.014771+08:00 0 [Note] InnoDB: Using Linux native AIO
2023-11-01T17:13:53.014911+08:00 0 [Note] InnoDB: Number of pools: 1
2023-11-01T17:13:53.015005+08:00 0 [Note] InnoDB: Using CPU crc32 instructions
2023-11-01T17:13:53.015890+08:00 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2023-11-01T17:13:53.020309+08:00 0 [Note] InnoDB: Completed initialization of buffer pool
2023-11-01T17:13:53.021508+08:00 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2023-11-01T17:13:53.032014+08:00 0 [Note] InnoDB: The first innodb_system data file 'ibdata1' did not exist. A new tablespace will be created!
2023-11-01T17:13:53.032158+08:00 0 [Note] InnoDB: Setting file './ibdata1' size to 12 MB. Physically writing the file full; Please wait ...
2023-11-01T17:13:53.107490+08:00 0 [Note] InnoDB: File './ibdata1' size is now 12 MB.
2023-11-01T17:13:53.107760+08:00 0 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2023-11-01T17:13:53.480921+08:00 0 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2023-11-01T17:13:54.438187+08:00 0 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2023-11-01T17:13:54.438251+08:00 0 [Warning] InnoDB: New log files created, LSN=45790
2023-11-01T17:13:54.438264+08:00 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2023-11-01T17:13:54.438329+08:00 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2023-11-01T17:13:54.505869+08:00 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2023-11-01T17:13:54.506059+08:00 0 [Note] InnoDB: Doublewrite buffer not found: creating new
2023-11-01T17:13:54.527522+08:00 0 [Note] InnoDB: Doublewrite buffer created
2023-11-01T17:13:54.531060+08:00 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2023-11-01T17:13:54.531078+08:00 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2023-11-01T17:13:54.531169+08:00 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-11-01T17:13:54.541415+08:00 0 [Note] InnoDB: Foreign key constraint system tables created
2023-11-01T17:13:54.541468+08:00 0 [Note] InnoDB: Creating tablespace and datafile system tables.
2023-11-01T17:13:54.542864+08:00 0 [Note] InnoDB: Tablespace and datafile system tables created.
2023-11-01T17:13:54.542889+08:00 0 [Note] InnoDB: Creating sys_virtual system tables.
2023-11-01T17:13:54.544077+08:00 0 [Note] InnoDB: sys_virtual table created
2023-11-01T17:13:54.544168+08:00 0 [Note] InnoDB: Waiting for purge to start
2023-11-01T17:13:54.594720+08:00 0 [Note] InnoDB: 5.7.32 started; log sequence number 0
2023-11-01T17:13:54.596887+08:00 0 [Warning] InnoDB: Cannot open table mysql/plugin from the internal data dictionary of InnoDB though the .frm file for the table exists. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
mysqld: Table 'mysql.plugin' doesn't exist
2023-11-01T17:13:54.596922+08:00 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2023-11-01T17:13:54.600988+08:00 0 [Warning] InnoDB: Cannot open table mysql/gtid_executed from the internal data dictionary of InnoDB though the .frm file for the table exists. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
mysqld: Table 'mysql.gtid_executed' doesn't exist
2023-11-01T17:13:54.601016+08:00 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2023-11-01T17:13:54.602556+08:00 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2023-11-01T17:13:54.602568+08:00 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2023-11-01T17:13:54.603431+08:00 0 [Warning] CA certificate ca.pem is self signed.
2023-11-01T17:13:54.603465+08:00 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2023-11-01T17:13:54.603546+08:00 0 [Note] Server hostname (bind-address): '*'; port: 3306
2023-11-01T17:13:54.603630+08:00 0 [Note] IPv6 is available.
2023-11-01T17:13:54.603640+08:00 0 [Note]   - '::' resolves to '::';
2023-11-01T17:13:54.603677+08:00 0 [Note] Server socket created on IP: '::'.
2023-11-01T17:13:54.604700+08:00 0 [Warning] Insecure configuration for --pid-file: Location '/mysql' in the path is accessible to all OS users. Consider choosing a different directory.
2023-11-01T17:13:54.604900+08:00 0 [Warning] InnoDB: Cannot open table mysql/server_cost from the internal data dictionary of InnoDB though the .frm file for the table exists. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
2023-11-01T17:13:54.604919+08:00 0 [Warning] Failed to open optimizer cost constant tables
2023-11-01T17:13:54.605366+08:00 0 [Warning] InnoDB: Cannot open table mysql/time_zone_leap_second from the internal data dictionary of InnoDB though the .frm file for the table exists. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
2023-11-01T17:13:54.605380+08:00 0 [Warning] Can't open and lock time zone table: Table 'mysql.time_zone_leap_second' doesn't exist trying to live without them
2023-11-01T17:13:54.605806+08:00 0 [Warning] InnoDB: Cannot open table mysql/servers from the internal data dictionary of InnoDB though the .frm file for the table exists. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
2023-11-01T17:13:54.605824+08:00 0 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
2023-11-01T17:13:54.605991+08:00 0 [Warning] InnoDB: Cannot open table mysql/slave_master_info from the internal data dictionary of InnoDB though the .frm file for the table exists. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
2023-11-01T17:13:54.606061+08:00 0 [Warning] InnoDB: Cannot open table mysql/slave_relay_log_info from the internal data dictionary of InnoDB though the .frm file for the table exists. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
2023-11-01T17:13:54.606113+08:00 0 [Warning] InnoDB: Cannot open table mysql/slave_master_info from the internal data dictionary of InnoDB though the .frm file for the table exists. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
2023-11-01T17:13:54.606122+08:00 0 [Warning] Info table is not ready to be used. Table 'mysql.slave_master_info' cannot be opened.
2023-11-01T17:13:54.606181+08:00 0 [Warning] InnoDB: Cannot open table mysql/slave_worker_info from the internal data dictionary of InnoDB though the .frm file for the table exists. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
2023-11-01T17:13:54.606230+08:00 0 [Warning] InnoDB: Cannot open table mysql/slave_relay_log_info from the internal data dictionary of InnoDB though the .frm file for the table exists. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
2023-11-01T17:13:54.606242+08:00 0 [Warning] Info table is not ready to be used. Table 'mysql.slave_relay_log_info' cannot be opened.
2023-11-01T17:13:54.606263+08:00 0 [Note] Failed to start slave threads for channel ''
2023-11-01T17:13:54.609674+08:00 0 [Note] Event Scheduler: Loaded 0 events
2023-11-01T17:13:54.618992+08:00 0 [Note] /usr/local/mysql7/bin/mysqld: ready for connections.
Version: '5.7.32-log'  socket: '/mysql/3306/tmp/mysql.sock'  port: 3306  MySQL Community Server (GPL)

因此针对MySQL 5.7,如果误删除ibdata1,不需要数据的前提下,可以再删除ib_logfile0、ib_logfile1,让MySQL可以自动创建这几个文件,带起数据库。

但同事用的MariaDB,删除这些文件,执行数据库启动的指令,虽然能自动创建这几个文件,但无法启动,提示如下错误,

代码语言:javascript
复制
systemctl status mariadb.service
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 三 2023-11-01 13:30:55 CST; 12s ago
  Process: 10099 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=1/FAILURE)
  Process: 10098 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS)
  Process: 10067 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 10098 (code=exited, status=0/SUCCESS)


11月 01 13:30:49 localhost.localdomain systemd[1]: Starting MariaDB database server...
11月 01 13:30:49 localhost.localdomain mariadb-prepare-db-dir[10067]: Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.
11月 01 13:30:49 localhost.localdomain mariadb-prepare-db-dir[10067]: If this is not the case, make sure the /var/lib/mysql is empty before running ...b-dir.
11月 01 13:30:49 localhost.localdomain mysqld_safe[10098]: 231101 13:30:49 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
11月 01 13:30:49 localhost.localdomain mysqld_safe[10098]: 231101 13:30:49 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
11月 01 13:30:55 localhost.localdomain systemd[1]: mariadb.service: control process exited, code=exited status=1
11月 01 13:30:55 localhost.localdomain systemd[1]: Failed to start MariaDB database server.
11月 01 13:30:55 localhost.localdomain systemd[1]: Unit mariadb.service entered failed state.
11月 01 13:30:55 localhost.localdomain systemd[1]: mariadb.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

登录数据库,说的是找不到sock,实际有这个文件,

代码语言:javascript
复制
[root@localhost ~]# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

我觉得应该比较接近答案了,但是受限于进度,还是重装了。

从这个引申出最重要的,无论什么库,建议还是做备份,无备份的库,就像是裸奔,存在各种风险。

如果您认为这篇文章有些帮助,还请不吝点下文章末尾的"点赞"和"在看",或者直接转发pyq,

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-11-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 MySQL
腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档