您的位置:首页 > 数据库 > MySQL

mysqlidxchk查看mysql未使用索引官方文档

2011-09-15 19:15 435 查看

mysqlidxchk Documentation

mysqlidxchk (MySQL Index Checker) checks MySQL databases/tables for unused indexes. To accomplish this task, mysqlidxchk requires one or more log files which can be any number and combination of slow, general, and "raw" log files. mysqlidxchk then compares the indexes used by the queries from the log files to all existing indexes in the database schema and reports which indexes in the database schema are not used.

The completeness of mysqlidxchk's unused index report is related to the representativeness of the queries from the log files for the entire database schema. For example, if no queries use database x, then mysqlidxchk may report that all indexes for all tables in database x are unused. These details are discussed further in the Guide To Using mysqlidxchk.

A Note About Options

Technically, command line options are in the form --option, but -option works too. All options can be abbreviated if the abbreviation is unique. For example, option --host can be abbreviated --ho but not --h because --h is ambiguous: it could mean --host or --help.

Options

--user USER
--password
--host ADDRESS
--port PORT
--socket SOCKET
--no-mycnf
--help (-?)
These options mimic most standard applications. --password can take the password on the command line like "--password FOO". Using --password alone without giving a password on the command line causes mysqlidxchk to prompt for a password. --no-mycnf makes mysqlidxchk not read ~/.my.cnf which it does by default otherwise. --user and --password always override values from ~/.my.cnf.
--debugUsing --debug causes mysqlidxchk to print a lot of extra debugging information about what it is doing internally. In release versions of mysqlidxchk, debugging information does not include log parsing information. For more information about release verses debug versions of mysqlidxchk, read mysqlidxchk Bugs & Problems.
--general (-g) LOG
--slow (-s) LOG
--raw (-r) LOG
mysqlidxchk can read and combine multiple MySQL slow and general logs, as well as "raw" logs. Raw logs are simply files with ;\n (semi-colon new-line) terminated SQL statements. At least one log file must be given. Multiple log files can be specified like: "-g log1,log2,log3 -s slow_queries.log".

By default, only SELECT, UPDATE and USE db statements are read; all other statements are discarded.

General logs and raw logs are more reliable than slow logs because general logs always contain an equivalent "USE db" statement, and a "USE db" statement can and should be added to raw logs. Slow logs, however, may or may not contain a "USE db." If not, mysqlidxchk tries to discover which database a query belongs to. The database discovery process is discussed in the Guide To Using mysqlidxchk.
--grep Pgrep and save only those statements which match Perl regex pattern P.
--databases (-D) DBy default mysqlidxchk uses and reports on every index in every table in every database. However, there are times when you may wish to only consider a limited number of databases. The --databases option causes mysqlidxchk to only report on the given databases D (where D is a comma-separated list of database names without any spaces). Queries which use databases not given in D are silently discarded.
--show-used (-su)By default mysqlidxchk only reports unused indexes. --show-used causes mysqlidxchk to show all indexes both unused and used. Used indexes have a number in parenthesis beside them, like (7), where '7' is the number of unique queries that use that index.
--ignore-update (-iu)mysqlidxchk transforms UPDATE statements into SELECT statements by dropping the SET clause and adding "SELECT * FROM". For example, "UPDATE table SET col = 1 WHERE something IS NULL" becomes "SELECT * FROM table WHERE something IS NULL". --ignore-update causes mysqlidxchk to silently discard all UPDATE statements.
--no-db-discovery (-ndd)If a query does not have a database, mysqlidxchk attempts to discover the query's appropriate database. --no-db-discovery prevents mysqlidxchk from this attempt. Queries without databases will not be EXPLAINed.

The database discovery process is discussed in the Guide To Using mysqlidxchk.
--no-discovery-report (-ndr)While attempting to discover databases for queries without databases, mysqlidxchk prints extra information about its successes and failures. --no-discovery-report suppress this extra information. Database discovery will still be attempted with this option.

What To Do About Bug and Errors

If mysqlidxchk will not work for you, please read the brief guide to submitting bug and problem reports : mysqlidxchk Bugs & Problems本文出自 “openpy” 博客,请务必保留此出处http://openpy.blog.51cto.com/2798268/1572330
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: