Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1
Note that a MySQL process, as shown on this process list, is different from a UNIX process. Although
there may only appear to be a single MySQL process if you run ps under a UNIX shell, MySQL may be
running many threads, as listed in the mysqladmin processlist command.
The list includes an Id for each thread, the User who initiated that thread, and the Host from which the
user is connected. db is the name of the database to which the user is connected.
Command gives information about the type of command being executed by the thread. It may be any
one of the following:
ƒ Sleep—Thread is waiting for user input, as most processes will normally be.
ƒ Processes—Thread is currently looking at the other threads that are running (as in
the second entry, which represents the mysqladmin processlist command
running).
ƒ Connect—Thread is currently receiving an incoming connection from a client.
ƒ Init DB—The thread is initializing the given database and preparing it for use. (Note
that a thread can switch between databases.)
ƒ Query—A query is currently being executed by the thread. You seldom see this
because queries typically take a very short time to run.
ƒ Field list—Thread is generating a list of fields in a table.
ƒ Create DB—Thread is currently creating a new database.
ƒ Drop DB—Thread is currently dropping a database.
ƒ Reload—Thread is currently reloading MySQL access tables.
ƒ Refresh—Thread is currently resetting log files and flushing caches.
ƒ Statistics—Thread is currently generating statistics.
ƒ Kill—Thread is currently terminating another thread.
ƒ Shutdown—Thread is in the process of terminating all other live threads and is about
to shut down the MySQL server.
ƒ Quit—Thread of quitting.

Fixing a Corrupted Database


A suspected database corruption needn't mean disaster. MySQL has anticipated this moment of terror that
comes to many a database administrator, and provided some tools for repairing damaged tables.
These tools come in the form of two utilities: isamchk and myasamchk.


Before looking at what these utilities do and how to invoke them, familiarize yourself with how MySQL
stores its data.

MySQL Data Structure


First, cd into the data directory for the small database called book, and then list what's there:


[root@tigger book]# ls -la
total 28
drwx------ 2 mysql mysql 4096 Feb 14 13:15.
drwxr-xr-x 11 mysql root 4096 Feb 15 13:24 ..
-rw-rw---- 1 mysql mysql 1015 Feb 14 15:16 customers.ISD
-rw-rw---- 1 mysql mysql 2048 Feb 14 15:16 customers.ISM
-rw-rw---- 1 mysql mysql 8682 Jan 31 19:13 customers.frm
There's just one table in the book database, called Customers. However, Customers has three files.
The .FRM file is the format file that contains the data structure itself. Don't try to view this file, it's not a
readable format.
The .ISD file holds the actual data, while the .ISM file contains information on keys and other internal
cross-references. This is the file that the isamchk and myasamchk utilities are most concerned about
repairing.
Try running isamchk -d to display information about the customers table:
[root@tigger book]# isamchk -d customers
ISAM file: customers
Data records: 15 Deleted blocks: 5
Recordlength: 220
Free download pdf