2
3
4
6 mysqlcheck - a table maintenance and repair program
7
9 mysqlcheck [options] [db_name [tbl_name ...]]
10
12 The mysqlcheck client checks, repairs, optimizes, and analyzes tables.
13
14 mysqlcheck is similar in function to myisamchk, but works differently.
15 The main operational difference is that mysqlcheck must be used when
16 the mysqld server is running, whereas myisamchk should be used when it
17 is not. The benefit of using mysqlcheck is that you do not have to stop
18 the server to check or repair your tables.
19
20 mysqlcheck uses the SQL statements CHECK TABLE, REPAIR TABLE, ANALYZE
21 TABLE, and OPTIMIZE TABLE in a convenient way for the user. It
22 determines which statements to use for the operation you want to
23 perform, and then sends the statements to the server to be executed.
24 For details about which storage engines each statement works with, see
25 the descriptions for those statements in Chapter 13, SQL Statement
26 Syntax.
27
28 The MyISAM storage engine supports all four statements, so mysqlcheck
29 can be used to perform all four operations on MyISAM tables. Other
30 storage engines do not necessarily support all operations. In such
31 cases, an error message is displayed. For example, if test.t is a
32 MEMORY table, an attempt to check it produces this result:
33
34 shell> mysqlcheck test t
35 test.t
36 note : The storage engine for the table doesn't support check
37
38 Caution
39 It is best to make a backup of a table before performing a table repair
40 operation; under some circumstances the operation might cause data
41 loss. Possible causes include but are not limited to filesystem errors.
42
43 There are three general ways to invoke mysqlcheck:
44
45 shell> mysqlcheck [options] db_name [tables]
46 shell> mysqlcheck [options] --databases db_name1 [db_name2 db_name3...]
47 shell> mysqlcheck [options] --all-databases
48
49 If you do not name any tables following db_name or if you use the
50 --databases or --all-databases option, entire databases are checked.
51
52 mysqlcheck has a special feature compared to other client programs. The
53 default behavior of checking tables (--check) can be changed by
54 renaming the binary. If you want to have a tool that repairs tables by
55 default, you should just make a copy of mysqlcheck named mysqlrepair,
56 or make a symbolic link to mysqlcheck named mysqlrepair. If you invoke
57 mysqlrepair, it repairs tables.
58
59 The following names can be used to change mysqlcheck default behavior:
60
61 ┌──────────────┬───────────────────────┐
62 │mysqlrepair │ The default option is │
63 │ │ --repair │
64 ├──────────────┼───────────────────────┤
65 │mysqlanalyze │ The default option is │
66 │ │ --analyze │
67 ├──────────────┼───────────────────────┤
68 │mysqloptimize │ The default option is │
69 │ │ --optimize │
70 └──────────────┴───────────────────────┘
71
72 mysqlcheck supports the following options:
73
74 · --help, -?
75
76 Display a help message and exit.
77
78 · --all-databases, -A
79
80 Check all tables in all databases. This is the same as using the
81 --databases option and naming all the databases on the command line.
82
83 · --all-in-1, -1
84
85 Instead of issuing a statement for each table, execute a single
86 statement for each database that names all the tables from that
87 database to be processed.
88
89 · --analyze, -a
90
91 Analyze the tables.
92
93 MySQL Enterprise. For expert advice on optimizing tables, subscribe to
94 the MySQL Network Monitoring and Advisory Service. For more information
95 see http://www.mysql.com/products/enterprise/advisors.html.
96
97 · --auto-repair
98
99 If a checked table is corrupted, automatically fix it. Any necessary
100 repairs are done after all tables have been checked.
101
102 · --character-sets-dir=path
103
104 The directory where character sets are installed. See Section 8.1,
105 “The Character Set Used for Data and Sorting”.
106
107 · --check, -c
108
109 Check the tables for errors. This is the default operation.
110
111 · --check-only-changed, -C
112
113 Check only tables that have changed since the last check or that
114 have not been closed properly.
115
116 · --check-upgrade, -g
117
118 Invoke CHECK TABLE with the FOR UPGRADE option to check tables for
119 incompatibilities with the current version of the server. This
120 option was added in MySQL 5.0.19.
121
122 · --compress
123
124 Compress all information sent between the client and the server if
125 both support compression.
126
127 · --databases, -B
128
129 Process all tables in the named databases. Normally, mysqlcheck
130 treats the first name argument on the command line as a database
131 name and following names as table names. With this option, it treats
132 all name arguments as database names.
133
134 · --debug[=debug_options], -# [debug_options]
135
136 Write a debugging log. A typical debug_options string is often
137 ´d:t:o,file_name'.
138
139 · --default-character-set=charset_name
140
141 Use charset_name as the default character set. See Section 8.1, “The
142 Character Set Used for Data and Sorting”.
143
144 · --extended, -e
145
146 If you are using this option to check tables, it ensures that they
147 are 100% consistent but takes a long time.
148
149 If you are using this option to repair tables, it runs an extended
150 repair that may not only take a long time to execute, but may
151 produce a lot of garbage rows also!
152
153 · --fast, -F
154
155 Check only tables that have not been closed properly.
156
157 · --force, -f
158
159 Continue even if an SQL error occurs.
160
161 · --host=host_name, -h host_name
162
163 Connect to the MySQL server on the given host.
164
165 · --medium-check, -m
166
167 Do a check that is faster than an --extended operation. This finds
168 only 99.99% of all errors, which should be good enough in most
169 cases.
170
171 · --optimize, -o
172
173 Optimize the tables.
174
175 · --password[=password], -p[password]
176
177 The password to use when connecting to the server. If you use the
178 short option form (-p), you cannot have a space between the option
179 and the password. If you omit the password value following the
180 --password or -p option on the command line, you are prompted for
181 one.
182
183 Specifying a password on the command line should be considered
184 insecure. See Section 6.6, “Keeping Your Password Secure”.
185
186 · --port=port_num, -P port_num
187
188 The TCP/IP port number to use for the connection.
189
190 · --protocol={TCP|SOCKET|PIPE|MEMORY}
191
192 The connection protocol to use.
193
194 · --quick, -q
195
196 If you are using this option to check tables, it prevents the check
197 from scanning the rows to check for incorrect links. This is the
198 fastest check method.
199
200 If you are using this option to repair tables, it tries to repair
201 only the index tree. This is the fastest repair method.
202
203 · --repair, -r
204
205 Perform a repair that can fix almost anything except unique keys
206 that are not unique.
207
208 · --silent, -s
209
210 Silent mode. Print only error messages.
211
212 · --socket=path, -S path
213
214 For connections to localhost, the Unix socket file to use, or, on
215 Windows, the name of the named pipe to use.
216
217 · --ssl*
218
219 Options that begin with --ssl specify whether to connect to the
220 server via SSL and indicate where to find SSL keys and certificates.
221 See Section 6.7.3, “SSL Command Options”.
222
223 · --tables
224
225 Overrides the --databases or -B option. All name arguments following
226 the option are regarded as table names.
227
228 · --use-frm
229
230 For repair operations on MyISAM tables, get the table structure from
231 the .frm file so that the table can be repaired even if the .MYI
232 header is corrupted.
233
234 · --user=user_name, -u user_name
235
236 The MySQL username to use when connecting to the server.
237
238 · --verbose, -v
239
240 Verbose mode. Print information about the various stages of program
241 operation.
242
243 · --version, -V
244
245 Display version information and exit.
246
248 Copyright 1997-2007 MySQL AB
249
250 This documentation is NOT distributed under a GPL license. Use of this
251 documentation is subject to the following terms: You may create a
252 printed copy of this documentation solely for your own personal use.
253 Conversion to other formats is allowed as long as the actual content is
254 not altered or edited in any way. You shall not publish or distribute
255 this documentation in any form or on any media, except if you
256 distribute the documentation in a manner similar to how MySQL
257 disseminates it (that is, electronically for download on a Web site
258 with the software) or on a CD-ROM or similar medium, provided however
259 that the documentation is disseminated together with the software on
260 the same medium. Any other use, such as any dissemination of printed
261 copies or use of this documentation, in whole or in part, in another
262 publication, requires the prior written consent from an authorized
263 representative of MySQL AB. MySQL AB reserves any and all rights to
264 this documentation not expressly granted above.
265
266 Please email <docs@mysql.com> for more information.
267
269 For more information, please refer to the MySQL Reference Manual, which
270 may already be installed locally and which is also available online at
271 http://dev.mysql.com/doc/.
272
274 MySQL AB (http://www.mysql.com/). This software comes with no
275 warranty.
276
277
278
279MySQL 5.0 07/04/2007 MYSQLCHECK(1)