【mysql案例】datadir所在分区空间不足导致无法查看表

本文记录了一次MySQL启动失败的问题排查过程,主要原因是数据目录所在磁盘空间不足,导致InnoDB日志文件创建失败。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#datadir所在分区空间不足导致无法查看表

120221 04:49:54 mysqld_safe Starting mysqld daemon with databases from /opt/mysql
120221  4:49:54 [Warning] The syntax '--log-slow-queries' is deprecated and will be removed in a future release. Please use '--slow-query-log'/'--slow-query-log-file' instead.
120221  4:49:54 [Note] Plugin 'FEDERATED' is disabled.
120221  4:49:54 InnoDB: The InnoDB memory heap is disabled
120221  4:49:54 InnoDB: Mutexes and rw_locks use InnoDB's own implementation
120221  4:49:54 InnoDB: Compressed tables use zlib 1.2.3
120221  4:49:54 InnoDB: Using Linux native AIO
120221  4:49:54 InnoDB: Initializing buffer pool, size = 128.0M
120221  4:49:54 InnoDB: Completed initialization of buffer pool
InnoDB: Error: auto-extending data file ./ibdata1 is of a different size
InnoDB: 15360 pages (rounded down to MB) than specified in the .cnf file:
InnoDB: initial 65536 pages, max 0 (relevant if non-zero) pages!
120221  4:49:54 InnoDB: Could not open or create data files.
120221  4:49:54 InnoDB: If you tried to add new data files, and it failed here,
120221  4:49:54 InnoDB: you should now edit innodb_data_file_path in my.cnf back
120221  4:49:54 InnoDB: to what it was, and remove the new ibdata files InnoDB created
120221  4:49:54 InnoDB: in this failed attempt. InnoDB only wrote those files full of
120221  4:49:54 InnoDB: zeros, but did not yet use them in any way. But be careful: do not
120221  4:49:54 InnoDB: remove old data files which contain your precious data!
120221  4:49:54 [ERROR] Plugin 'InnoDB' init function returned error.
120221  4:49:54 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
/usr/sbin/mysqld: Error writing file './slow_query.log' (Errcode: 28)
120221  4:49:54 [ERROR] Could not use slow_query.log for logging (error 28). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.
120221  4:49:54 [ERROR] Unknown/unsupported storage engine: INNODB
120221  4:49:54 [ERROR] Aborting


120221  4:49:54 [Note] /usr/sbin/mysqld: Shutdown complete


120221 04:49:54 mysqld_safe mysqld from pid file /opt/mysql/jsunsa.pid ended
120221 04:52:22 mysqld_safe Starting mysqld daemon with databases from /opt/mysql
120221  4:52:22 [Warning] The syntax '--log-slow-queries' is deprecated and will be removed in a future release. Please use '--slow-query-log'/'--slow-query-log-file' instead.
120221  4:52:22 [Note] Plugin 'FEDERATED' is disabled.
120221  4:52:22 InnoDB: The InnoDB memory heap is disabled
120221  4:52:22 InnoDB: Mutexes and rw_locks use InnoDB's own implementation
120221  4:52:22 InnoDB: Compressed tables use zlib 1.2.3
120221  4:52:22 InnoDB: Using Linux native AIO
120221  4:52:22 InnoDB: Initializing buffer pool, size = 128.0M
120221  4:52:22 InnoDB: Completed initialization of buffer pool
120221  4:52:23  InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 256 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB:120221  4:52:23  InnoDB: Error: Write to file ./ib_logfile0 failed at offset 0 0.
InnoDB: 1048576 bytes should have been written, only -1 were written.
InnoDB: Operating system error number 28.
InnoDB: Check that your OS and file system support files of this size.
InnoDB: Check also that the disk is not full or a disk quota exceeded.
InnoDB: Error number 28 means 'No space left on device'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/operating-system-error-codes.html
InnoDB: Error in creating ./ib_logfile0: probably out of disk space
120221  4:52:23 [ERROR] Plugin 'InnoDB' init function returned error.
120221  4:52:23 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
/usr/sbin/mysqld: Error writing file './slow_query.log' (Errcode: 28)
120221  4:52:23 [ERROR] Could not use slow_query.log for logging (error 28). Turning logging off for the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.
1120221 04:52:23 mysqld_safe mysqld from pid file /opt/mysql/jsunsa.pid ended

<think>嗯,用户想了解如何用SQL语句MySQL的表空间。首先,我得回忆一下MySQL中表空间的相关知识。表空间主要分为系统表空间和独立表空间,可能还有通用表空间之类的。系统表空间存储数据字典、Undo日志等信息,而独立表空间每个表单独一个.ibd文件。用户可能需要看这些信息,比如表的大小、数据文件的位置等。 接下来,用户需要的是具体的SQL语句。我记得在information_schema数据库中,有几个表可能有用,比如TABLES和FILES。TABLES表里有DATA_LENGTH和INDEX_LENGTH,可以计算表的大小。而FILES表可能有文件的具体路径和大小,但需要权限才能访问。 首先,我应该给出询单个表大小的语句。比如SELECT语句从TABLES中选取TABLE_NAME, DATA_LENGTH等字段,然后计算总大小。可能还要转换单位,比如用MB显示,这样用户更直观。 然后,可能需要看所有数据库的表空间情况,这时候需要汇总所有表的数据,按数据库分组。SUM函数加上GROUP BY TABLE_SCHEMA应该可以做到。 还有独立表空间的文件路径,可以通过SHOW VARIABLES LIKE 'datadir'获取数据目录,然后每个数据库的文件夹里会有表的.ibd文件。这个可能需要用语句拼接,或者在操作系统层面看,但用户可能希望用SQL解决,所以可能需要结合文件系统的信息。 另外,系统表空间的位置通常在datadir下的ibdata1文件,可以通过变量innodb_data_file_path看配置。可能需要用SHOW VARIABLES来获取这些信息。 还要注意权限问题,因为访问information_schema可能需要一定的权限。另外,不同版本的MySQL可能有差异,比如InnoDB的配置是否使用独立表空间由innodb_file_per_table控制,这个变量可能需要检。 用户可能还想知道如何优化或管理表空间,比如OPTIMIZE TABLE或者ALTER TABLE重建表,但问题主要是看,所以这部分可能作为附加信息提到。 需要确保提供的SQL语句正确,比如字段名是否正确,单位转换是否准确。例如,DATA_LENGTH的单位是字节,转换成MB需要除以1024两次。同时,处理四舍五入,使用ROUND函数。 另外,可能需要提醒用户,某些询如information_schema.FILES可能需要更高的权限,或者在某些托管环境中不可用。这时候可能需要替代方法,比如看文件系统。 最后,总结一下步骤,分点列出不同的方法,并解释每个方法的作用,让用户能根据需求选择。同时,补充注意事项,比如权限、版本差异等,确保用户在实际操作中不会遇到问题。</think>在 MySQL看表空间信息,可以通过以下 SQL 语句和系统表实现: --- ### **一、看单个表空间大小** ```sql SELECT TABLE_NAME AS `表名`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024, 2) AS `总空间(MB)`, ROUND(DATA_LENGTH / 1024 / 1024, 2) AS `数据空间(MB)`, ROUND(INDEX_LENGTH / 1024 / 1024, 2) AS `索引空间(MB)` FROM information_schema.TABLES WHERE TABLE_SCHEMA = '你的数据库名' AND TABLE_NAME = '你的表名'; ``` --- ### **二、看整个数据库表空间** ```sql SELECT TABLE_SCHEMA AS `数据库名`, SUM(DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024 AS `总空间(MB)` FROM information_schema.TABLES GROUP BY TABLE_SCHEMA; ``` --- ### **三、看独立表空间文件路径** ```sql -- 看数据存储目录 SHOW VARIABLES LIKE 'datadir'; -- 看独立表空间文件名(需要访问权限) SELECT FILE_NAME, ROUND(TOTAL_EXTENTS * EXTENT_SIZE / 1024 / 1024, 2) AS `文件大小(MB)` FROM information_schema.FILES WHERE FILE_TYPE = 'TABLESPACE' AND FILE_NAME LIKE '%你的表名%'; ``` --- ### **四、看系统表空间** ```sql -- 看系统表空间配置 SHOW VARIABLES LIKE 'innodb_data_file_path'; ``` --- ### **五、关键说明** 1. **系统表空间 vs 独立表空间** - `innodb_file_per_table=ON` 时,表使用独立的 `.ibd` 文件 - `innodb_file_per_table=OFF` 时,表数据存储在共享的 `ibdata1` 文件 2. **单位转换** `DATA_LENGTH` 和 `INDEX_LENGTH` 的单位是字节,除以 `1024^2` 转换为 MB 3. **物理文件定位** - 独立表空间文件路径:`${datadir}/数据库名/表名.ibd` - 系统表空间文件路径:`${datadir}/ibdata1` --- ### **六、注意事项** - 需要 `SELECT` 权限访问 `information_schema` - 精确计算表空间建议使用 `innodb` 引擎 - 大表询可能较慢,建议在非高峰时段操作 通过以上方法,可以全面了解 MySQL空间的使用情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值