阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

mysqlcheck使用介绍 检查、修复、优化、分析表

195次阅读
没有评论

共计 5130 个字符,预计需要花费 13 分钟才能阅读完成。

MySQLcheck 使用介绍 检查、修复、优化、分析表,以下内容主要适用于 mysql 5.6,5.5 的版本可能有部分选项不可用。


通常使用该工具一般语法为:

  1. shell> mysqlcheck [options] db_name [tbl_name …]
  2. shell> mysqlcheck [options] –databases db_name …
  3. shell> mysqlcheck [options] –all-databases


比如对 mysql 库进行 mysqlcheck 操作:

  1. [op@sAno1y ~]$ mysqlcheck mysql -uroot -p
  2. Enter password:
  3. mysql.columns_priv OK
  4. mysql.db OK
  5. mysql.event OK
  6. mysql.func OK
  7. mysql.general_log OK
  8. mysql.help_category OK
  9. mysql.help_keyword OK
  10. mysql.help_relation OK
  11. mysql.help_topic OK
  12. mysql.innodb_index_stats OK
  13. mysql.innodb_table_stats OK
  14. mysql.ndb_binlog_index OK
  15. mysql.plugin OK
  16. mysql.proc OK
  17. mysql.procs_priv OK
  18. mysql.proxies_priv OK
  19. mysql.servers OK
  20. mysql.slave_master_info OK
  21. mysql.slave_relay_log_info OK
  22. mysql.slave_worker_info OK
  23. mysql.slow_log OK
  24. mysql.tables_priv OK
  25. mysql.time_zone OK
  26. mysql.time_zone_leap_second OK
  27. mysql.time_zone_name OK
  28. mysql.time_zone_transition OK
  29. mysql.time_zone_transition_type OK
  30. mysql.user OK


实际上该工具是为了方便用户使用,而使用了 CHECK TABLE、REPAIR TABLE、ANALYZE TABLE、OPTIMIZE TABLE 语句。

–analyze 选项:实际上是执行了 ANALYZE TABLE(支持 InnoDB,MyISAM,NDB)
–check 选项:实际上是执行了 CHECK TABLE(支持 InnoDB,MyISAM,ARCHIVE,CSV)
–optimize 选项:实际上执行了 OPTIMIZE TABLE(支持 InnoDB,MyISAM,ARCHIVE)
–repair 选项:实际上执行 REPAIR TABLE(支持 MyISAM,ARCHIVE,CSV)

一般情况不需要加这些选项,除非需要修复

其他修改选项:
–repair –quick 尝试快速修复
–repair 正常修复(除非快速修复失败)
–repair –force 强行修复

当然,在 mysqlcheck 时,每张表会被加上 READ LOCK。
该进程时,尤其是大表,将会变得十分耗时。
且该工具必须在 mysqld 服务运行的情况下使用。

此外,部分存储引擎的表是不被支持的:
我创了四张表,其存储引擎分别为 ARCHIVE、BLACKHOLE、MEMORY、MRG_MYISAM

  1. mysql> use test;
  2. Database changed
  3. mysql> show tables;
  4. ++
  5. | Tables_in_test |
  6. ++
  7. | archive_tb     |
  8. | blackhole_tb   |
  9. | memory_tb      |
  10. | mrg_myisam_tb  |
  11. ++
  12. 4 rows in set (0.00 sec)


然后 check 了一下,发现 blackhole 和 memory 是不被支持的,因为这两个存储引擎只存储.frm 的表定义在磁盘上。

  1. [op@sAno1y ~]$ mysqlcheck test -uroot -p
  2. Enter password:
  3. test.archive_tb OK
  4. test.blackhole_tb
  5. note : The storage engine for the table doesn’t support check
  6. test.memory_tb
  7. note : The storage engine for the table doesn’t support check
  8. test.mrg_myisam_tb OK



其他选项参考:

FormatDescriptionIntroduced
–all-databasesCheck all tables in all databases 
–all-in-1Execute a single statement for each database that names all the tables from that database 
–analyzeAnalyze the tables 
–auto-repairIf a checked table is corrupted, automatically fix it 
–bind-address=ip_addressUse specified network interface to connect to MySQL Server 
–character-sets-dir=pathDirectory where character sets are installed 
–checkCheck the tables for errors 
–check-only-changedCheck only tables that have changed since the last check 
–check-upgradeInvoke CHECK TABLE with the FOR UPGRADE option 
–compressCompress all information sent between client and server 
–databasesProcess all tables in the named databases 
–debug[=debug_options]Write a debugging log 
–debug-checkPrint debugging information when program exits 
–debug-infoPrint debugging information, memory, and CPU statistics when program exits 
–default-auth=pluginAuthentication plugin to use5.6.2
–default-character-set=charset_nameSpecify default character set 
–defaults-extra-file=file_nameRead option file in addition to usual option files 
–defaults-file=file_nameRead only named option file 
–defaults-group-suffix=strOption group suffix value 
–extendedCheck and repair tables 
–fastCheck only tables that have not been closed properly 
–fix-db-namesConvert database names to 5.1 format 
–fix-table-namesConvert table names to 5.1 format 
–forceContinue even if an SQL error occurs 
–helpDisplay help message and exit 
–host=host_nameConnect to MySQL server on given host 
–login-path=nameRead login path options from .mylogin.cnf5.6.6
–medium-checkDo a check that is faster than an –extended operation 
–no-defaultsRead no option files 
–optimizeOptimize the tables 
–password[=password]Password to use when connecting to server 
–pipeOn Windows, connect to server using named pipe 
–plugin-dir=pathDirectory where plugins are installed5.6.2
–port=port_numTCP/IP port number to use for connection 
–print-defaultsPrint defaults 
–protocol=typeConnection protocol to use 
–quickThe fastest method of checking 
–repairPerform a repair that can fix almost anything except unique keys that are not unique 
–secure-authDo not send passwords to the server in old (pre-4.1.1) format5.6.17
–shared-memory-base-name=nameThe name of shared memory to use for shared-memory connections 
–silentSilent mode 
–skip-database=db_nameOmit this database from performed operations5.6.11
–socket=pathFor connections to localhost, the Unix socket file to use 
–sslEnable SSL for connection 
–ssl-ca=file_namePath of file that contains list of trusted SSL CAs 
–ssl-capath=dir_namePath of directory that contains trusted SSL CA certificates in PEM format 
–ssl-cert=file_namePath of file that contains X509 certificate in PEM format 
–ssl-cipher=cipher_listList of permitted ciphers to use for SSL encryption 
–ssl-crl=file_namePath of file that contains certificate revocation lists5.6.3
–ssl-crlpath=dir_namePath of directory that contains certificate revocation list files5.6.3
–ssl-key=file_namePath of file that contains X509 key in PEM format 
–ssl-verify-server-certVerify server Common Name value in its certificate against host name used when connecting to server 
–tablesOverrides the –databases or -B option 
–use-frmFor repair operations on MyISAM tables 
–user=user_name,MySQL user name to use when connecting to server 
–verboseVerbose mode 
–versionDisplay version information and exit 
–write-binlogLog ANALYZE, OPTIMIZE, REPAIR statements to binary log. –skip-write-binlog adds NO_WRITE_TO_BINLOG to these statements.

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-09/146647.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计5130字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中