1MYSQLCHECK(1) MySQL Database System MYSQLCHECK(1)
2
3
4
6 mysqlcheck - a table maintenance program
7
9 mysqlcheck [options] [db_name [tbl_name ...]]
10
12 The mysqlcheck client performs table maintenance: It checks, repairs,
13 optimizes, or analyzes tables.
14
15 Each table is locked and therefore unavailable to other sessions while
16 it is being processed, although for check operations, the table is
17 locked with a READ lock only (see Section 12.3.5, “LOCK TABLES and
18 UNLOCK TABLES Syntax”, for more information about READ and WRITE
19 locks). Table maintenance operations can be time-consuming,
20 particularly for large tables. If you use the --databases or
21 --all-databases option to process all tables in one or more databases,
22 an invocation of mysqlcheck might take a long time. (This is also true
23 for mysql_upgrade because that program invokes mysqlcheck to check all
24 tables and repair them if necessary.)
25
26 mysqlcheck is similar in function to myisamchk, but works differently.
27 The main operational difference is that mysqlcheck must be used when
28 the mysqld server is running, whereas myisamchk should be used when it
29 is not. The benefit of using mysqlcheck is that you do not have to stop
30 the server to perform table maintenance.
31
32 mysqlcheck uses the SQL statements CHECK TABLE, REPAIR TABLE, ANALYZE
33 TABLE, and OPTIMIZE TABLE in a convenient way for the user. It
34 determines which statements to use for the operation you want to
35 perform, and then sends the statements to the server to be executed.
36 For details about which storage engines each statement works with, see
37 the descriptions for those statements in Section 12.4.2, “Table
38 Maintenance Statements”.
39
40 The MyISAM storage engine supports all four maintenance operations, so
41 mysqlcheck can be used to perform any of them on MyISAM tables. Other
42 storage engines do not necessarily support all operations. In such
43 cases, an error message is displayed. For example, if test.t is a
44 MEMORY table, an attempt to check it produces this result:
45
46 shell> mysqlcheck test t
47 test.t
48 note : The storage engine for the table doesn´t support check
49
50 If mysqlcheck is unable to repair a table, see Section 2.4.4,
51 “Rebuilding or Repairing Tables or Indexes” for manual table repair
52 strategies. This will be the case, for example, for InnoDB tables,
53 which can be checked with CHECK TABLE, but not repaired with REPAIR
54 TABLE.
55
56 The use of mysqlcheck with partitioned tables is not supported before
57 MySQL 5.1.27.
58
59 Caution
60 It is best to make a backup of a table before performing a table
61 repair operation; under some circumstances the operation might
62 cause data loss. Possible causes include but are not limited to
63 file system errors.
64
65 There are three general ways to invoke mysqlcheck:
66
67 shell> mysqlcheck [options] db_name [tbl_name ...]
68 shell> mysqlcheck [options] --databases db_name ...
69 shell> mysqlcheck [options] --all-databases
70
71 If you do not name any tables following db_name or if you use the
72 --databases or --all-databases option, entire databases are checked.
73
74 mysqlcheck has a special feature compared to other client programs. The
75 default behavior of checking tables (--check) can be changed by
76 renaming the binary. If you want to have a tool that repairs tables by
77 default, you should just make a copy of mysqlcheck named mysqlrepair,
78 or make a symbolic link to mysqlcheck named mysqlrepair. If you invoke
79 mysqlrepair, it repairs tables.
80
81 The following names can be used to change mysqlcheck default behavior.
82
83 ┌──────────────┬───────────────────────┐
84 │mysqlrepair │ The default option is │
85 │ │ --repair │
86 ├──────────────┼───────────────────────┤
87 │mysqlanalyze │ The default option is │
88 │ │ --analyze │
89 ├──────────────┼───────────────────────┤
90 │mysqloptimize │ The default option is │
91 │ │ --optimize │
92 └──────────────┴───────────────────────┘
93
94 mysqlcheck supports the following options, which can be specified on
95 the command line or in the [mysqlcheck] and [client] option file
96 groups. mysqlcheck also supports the options for processing option
97 files described at Section 4.2.3.3.1, “Command-Line Options that Affect
98 Option-File Handling”.
99
100 · --help, -?
101
102 Display a help message and exit.
103
104 · --all-databases, -A
105
106 Check all tables in all databases. This is the same as using the
107 --databases option and naming all the databases on the command
108 line.
109
110 · --all-in-1, -1
111
112 Instead of issuing a statement for each table, execute a single
113 statement for each database that names all the tables from that
114 database to be processed.
115
116 · --analyze, -a
117
118 Analyze the tables.
119
120 · --auto-repair
121
122 If a checked table is corrupted, automatically fix it. Any
123 necessary repairs are done after all tables have been checked.
124
125 · --character-sets-dir=path
126
127 The directory where character sets are installed. See Section 9.5,
128 “Character Set Configuration”.
129
130 · --check, -c
131
132 Check the tables for errors. This is the default operation.
133
134 · --check-only-changed, -C
135
136 Check only tables that have changed since the last check or that
137 have not been closed properly.
138
139 · --check-upgrade, -g
140
141 Invoke CHECK TABLE with the FOR UPGRADE option to check tables for
142 incompatibilities with the current version of the server. This
143 option automatically enables the --fix-db-names and
144 --fix-table-names options. --check-upgrade was added in MySQL
145 5.1.7.
146
147 · --compress
148
149 Compress all information sent between the client and the server if
150 both support compression.
151
152 · --databases, -B
153
154 Process all tables in the named databases. Normally, mysqlcheck
155 treats the first name argument on the command line as a database
156 name and following names as table names. With this option, it
157 treats all name arguments as database names.
158
159 · --debug[=debug_options], -# [debug_options]
160
161 Write a debugging log. A typical debug_options string is
162 ´d:t:o,file_name´. The default is ´d:t:o´.
163
164 · --debug-check
165
166 Print some debugging information when the program exits. This
167 option was added in MySQL 5.1.21.
168
169 · --debug-info
170
171 Print debugging information and memory and CPU usage statistics
172 when the program exits. This option was added in MySQL 5.1.14.
173
174 · --default-character-set=charset_name
175
176 Use charset_name as the default character set. See Section 9.5,
177 “Character Set Configuration”.
178
179 · --defaults-extra-file=filename
180
181 Set filename as the file to read default options from after the
182 global defaults files has been read. Must be given as first
183 option.
184
185 · --defaults-file=filename
186
187 Set filename as the file to read default options from, override
188 global defaults files. Must be given as first option.
189
190 · --extended, -e
191
192 If you are using this option to check tables, it ensures that they
193 are 100% consistent but takes a long time.
194
195 If you are using this option to repair tables, it runs an extended
196 repair that may not only take a long time to execute, but may
197 produce a lot of garbage rows also!
198
199 · --fast, -F
200
201 Check only tables that have not been closed properly.
202
203 · --fix-db-names
204
205 Convert database names to 5.1 format. Only database names that
206 contain special characters are affected. This option was added in
207 MySQL 5.1.7.
208
209 · --fix-table-names
210
211 Convert table names to 5.1 format. Only table names that contain
212 special characters are affected. This option was added in MySQL
213 5.1.7. As of MySQL 5.1.23, this option also applies to views.
214
215 · --force, -f
216
217 Continue even if an SQL error occurs.
218
219 · --host=host_name, -h host_name
220
221 Connect to the MySQL server on the given host.
222
223 · --medium-check, -m
224
225 Do a check that is faster than an --extended operation. This finds
226 only 99.99% of all errors, which should be good enough in most
227 cases.
228
229 · --no-defaults
230
231 Do not read default options from any option file. This must be
232 given as the first argument.
233
234 · --optimize, -o
235
236 Optimize the tables.
237
238 · --password[=password], -p[password]
239
240 The password to use when connecting to the server. If you use the
241 short option form (-p), you cannot have a space between the option
242 and the password. If you omit the password value following the
243 --password or -p option on the command line, mysqlcheck prompts for
244 one.
245
246 Specifying a password on the command line should be considered
247 insecure. See Section 5.3.2.2, “End-User Guidelines for Password
248 Security”. You can use an option file to avoid giving the password
249 on the command line.
250
251 · --pipe, -W
252
253 On Windows, connect to the server via a named pipe. This option
254 applies only if the server supports named-pipe connections.
255
256 · --port=port_num, -P port_num
257
258 The TCP/IP port number to use for the connection.
259
260 · --protocol={TCP|SOCKET|PIPE|MEMORY}
261
262 The connection protocol to use for connecting to the server. It is
263 useful when the other connection parameters normally would cause a
264 protocol to be used other than the one you want. For details on the
265 allowable values, see Section 4.2.2, “Connecting to the MySQL
266 Server”.
267
268 · --print-defaults
269
270 Print the program argument list and exit. This must be given as
271 the first argument.
272
273 · --quick, -q
274
275 If you are using this option to check tables, it prevents the check
276 from scanning the rows to check for incorrect links. This is the
277 fastest check method.
278
279 If you are using this option to repair tables, it tries to repair
280 only the index tree. This is the fastest repair method.
281
282 · --repair, -r
283
284 Perform a repair that can fix almost anything except unique keys
285 that are not unique.
286
287 · --silent, -s
288
289 Silent mode. Print only error messages.
290
291 · --socket=path, -S path
292
293 For connections to localhost, the Unix socket file to use, or, on
294 Windows, the name of the named pipe to use.
295
296 · --ssl*
297
298 Options that begin with --ssl specify whether to connect to the
299 server via SSL and indicate where to find SSL keys and
300 certificates. See Section 5.5.6.3, “SSL Command Options”.
301
302 · --tables
303
304 Override the --databases or -B option. All name arguments following
305 the option are regarded as table names.
306
307 · --use-frm
308
309 For repair operations on MyISAM tables, get the table structure
310 from the .frm file so that the table can be repaired even if the
311 .MYI header is corrupted.
312
313 · --user=user_name, -u user_name
314
315 The MySQL user name to use when connecting to the server.
316
317 · --verbose, -v
318
319 Verbose mode. Print information about the various stages of program
320 operation.
321
322 · --version, -V
323
324 Display version information and exit.
325
326 · --write-binlog
327
328 This option is enabled by default, so that ANALYZE TABLE, OPTIMIZE
329 TABLE, and REPAIR TABLE statements generated by mysqlcheck are
330 written to the binary log. Use --skip-write-binlog to cause
331 NO_WRITE_TO_BINLOG to be added to the statements so that they are
332 not logged. Use the --skip-write-binlog when these statements
333 should not be sent to replication slaves or run when using the
334 binary logs for recovery from backup. This option was added in
335 MySQL 5.1.18.
336
338 Copyright 2007-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc.
339
340 This documentation is free software; you can redistribute it and/or
341 modify it only under the terms of the GNU General Public License as
342 published by the Free Software Foundation; version 2 of the License.
343
344 This documentation is distributed in the hope that it will be useful,
345 but WITHOUT ANY WARRANTY; without even the implied warranty of
346 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
347 General Public License for more details.
348
349 You should have received a copy of the GNU General Public License along
350 with the program; if not, write to the Free Software Foundation, Inc.,
351 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see
352 http://www.gnu.org/licenses/.
353
354
356 For more information, please refer to the MySQL Reference Manual, which
357 may already be installed locally and which is also available online at
358 http://dev.mysql.com/doc/.
359
361 Sun Microsystems, Inc. (http://www.mysql.com/).
362
363
364
365MySQL 5.1 04/06/2010 MYSQLCHECK(1)