mysqlcheck 是 MySQL 自带的一个工具,作用就是
保养
表,其实就是检查,分析,修复和优化了。下面来介绍 mysqlcheck 工具的简单使用,官方文档在这里
以下的例子都是基于 MySQL 5.6 版本运行状态下(mysqlcheck是个在线工具), 不同的存储引擎对于这个命令的支持程度不同(指的是 check, repair, analyze, optimize),下面内容偏于操作,主要基于 innodb 引擎。
提示:OPTIMIZE 在大表时候可能会消耗很多时间,不清楚原理情况下请谨慎使用!!! innodb 一般不用 OPTIMIZE,请参见 Using MySQL OPTIMIZE tables? For InnoDB? Stop
检查特定的表
注意在shell中执行,不是在mysql的交互环境下
如果应用中提示某个表坏了,使用下面的命令来检查。
$ mysqlcheck -c newmandela order -uroot -pEnter password: newmandela.order OK
newmandela 是库名, order是表名,还需要输入用户名和密码
检查一个库中的所有表
$ mysqlcheck -c newmandela -uroot -p Enter password: newmandela.account OK newmandela.alarm OK newmandela.alarm_settings OK newmandela.auth_group OK newmandela.auth_group_permissions OK newmandela.auth_permission OK...
检查所有库中的所有表
全部的库和表都检查一遍了。
$mysqlcheck -c --all-databases -uroot -p Enter password: apmonitor.acinfo OK apmonitor.apdailysts OK apmonitor.apinfo OK apmonitor.apmonthsts OK apmonitor.apscanlog OK apmonitor.auth_group OK...
如果只想检查某几个库呢? 可以使用 –databases 参数
$ mysqlcheck -c --databases newmandela radius -uroot -p Enter password: newmandela.account OK newmandela.alarm OK newmandela.alarm_settings OK newmandela.auth_group OK...
使用 mysqlcheck 分析表
$ mysqlcheck -a radius payment_transactionrecord -uroot -pEnter password: radius.payment_transactionrecord Table is already up to date
上面的命令 用来分析 radius 库的 payment_transactionrecord
表, -a
表示 analyze
使用 mysqlcheck 优化表
# mysqlcheck -o radius payment_transactionrecord -uroot -pEnter password: radius.payment_transactionrecord OK
-o
代表 optimize ,这里是优化 radius 库的 payment_transactionrecord
表
使用 mysqlcheck 修复表
# mysqlcheck -r radius payment_transactionrecord -uroot -pEnter password: radius.payment_transactionrecord OK
-r
代表 repair ,这里是 修复 radius 库的 payment_transactionrecord
表
检查,优化,修复表组合命令
# mysqlcheck -uroot -p --auto-repair -c -o newmandelaError: mysqlcheck doesn't support multiple contradicting commands.
上面的命令报错了,去掉 -c
# mysqlcheck -uroot -p --auto-repair -o newmandelaEnter password: newmandela.account note : Table does not support optimize, doing recreate + analyze instead status : OK newmandela.alarm note : Table does not support optimize, doing recreate + analyze instead status : OK newmandela.alarm_settings note : Table does not support optimize, doing recreate + analyze instead status : OK
每张表都出现了 Table does not support optimize, doing recreate + analyze instead
, 代表什么意思呢? 它的意思不是说 innodb 引擎不支持 优化,
mysqlcheck 常用选项
A, –all-databases
表示所有库-a, –analyze
分析表-o, –optimize
优化表-r, –repair
修复表错误-c, –check
检查表是否出错–auto-repair
自动修复损坏的表-B, –databases
选择多个库-1, –all-in-1
Use one query per database with tables listed in a comma separated way-C, –check-only-changed
检查表最后一次检查之后的变动-g, –check-upgrade
Check for version dependent changes in the tables-F, –fast
Check tables that are not closed properly–fix-db-names
Fix DB names–fix-table-names
Fix table names-f, –force
Continue even when there is an error-e, –extended
Perform extended check on a table. This will take a long time to execute.-m, –medium-check
Faster than extended check option, but does most checks-q, –quick
Faster than medium check option
以上是怎样使用Mysqlcheck来检查和修复, 优化表的详解的详细内容。更多信息请关注PHP中文网其他相关文章!

MySQL使用的是GPL许可证。1)GPL许可证允许自由使用、修改和分发MySQL,但修改后的分发需遵循GPL。2)商业许可证可避免公开修改,适合需要保密的商业应用。

选择InnoDB而不是MyISAM的情况包括:1)需要事务支持,2)高并发环境,3)需要高数据一致性;反之,选择MyISAM的情况包括:1)主要是读操作,2)不需要事务支持。InnoDB适合需要高数据一致性和事务处理的应用,如电商平台,而MyISAM适合读密集型且无需事务的应用,如博客系统。

在MySQL中,外键的作用是建立表与表之间的关系,确保数据的一致性和完整性。外键通过引用完整性检查和级联操作维护数据的有效性,使用时需注意性能优化和避免常见错误。

MySQL中有四种主要的索引类型:B-Tree索引、哈希索引、全文索引和空间索引。1.B-Tree索引适用于范围查询、排序和分组,适合在employees表的name列上创建。2.哈希索引适用于等值查询,适合在MEMORY存储引擎的hash_table表的id列上创建。3.全文索引用于文本搜索,适合在articles表的content列上创建。4.空间索引用于地理空间查询,适合在locations表的geom列上创建。

toCreateAnIndexinMysql,usethecReateIndexStatement.1)forasingLecolumn,使用“ createIndexIdx_lastNameEnemployees(lastName); 2)foracompositeIndex,使用“ createIndexIndexIndexIndexIndexDx_nameOmplayees(lastName,firstName,firstName);” 3)forauniqe instex,creationexexexexex,

MySQL和SQLite的主要区别在于设计理念和使用场景:1.MySQL适用于大型应用和企业级解决方案,支持高性能和高并发;2.SQLite适合移动应用和桌面软件,轻量级且易于嵌入。

MySQL中的索引是数据库表中一列或多列的有序结构,用于加速数据检索。1)索引通过减少扫描数据量提升查询速度。2)B-Tree索引利用平衡树结构,适合范围查询和排序。3)创建索引使用CREATEINDEX语句,如CREATEINDEXidx_customer_idONorders(customer_id)。4)复合索引可优化多列查询,如CREATEINDEXidx_customer_orderONorders(customer_id,order_date)。5)使用EXPLAIN分析查询计划,避

在MySQL中使用事务可以确保数据一致性。1)通过STARTTRANSACTION开始事务,执行SQL操作后用COMMIT提交或ROLLBACK回滚。2)使用SAVEPOINT可以设置保存点,允许部分回滚。3)性能优化建议包括缩短事务时间、避免大规模查询和合理使用隔离级别。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

Atom编辑器mac版下载
最流行的的开源编辑器

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

禅工作室 13.0.1
功能强大的PHP集成开发环境