Go to the first, previous, next, last section, table of contents.


9 How safe/stable is MySQL?

9.1 How stable is MySQL?

At TcX, MySQL has worked without any problems in our projects since mid-1996. When MySQL was released to a wider public, we noticed that there were some pieces of "untested code" that were quickly found by the new users who made queries in a different manner. Each new release has had fewer portability problems than the previous one, even though each has had many new features, and we hope that it will be possible to label one of the next releases 'stable'.

Each release of MySQL has been usable and there have been problems only when users start to use code from "the gray zones". Naturally, outside users can't know what the gray zones are; this section attempts to indicate those that are currently known.

Here we will try to clarify some issues and to answer some of the more important questions that seem to concern many people. This section has been put together from information gathered from the mailing list (which is very active in reporting bugs).

The basic questions this section answers are, "how stable is MySQL?" and, "can I depend on MySQL in this project?"

This is about the 3.21.x version of MySQL. All known and reported bugs are fixed in the latest version with the exception of the bugs listed in the BUGS file which are things that are "design"-related.

MySQL is written in multiple layers and different independent modules. Here is a list of the different modules and how well-tested each of them is:

The ISAM table handler -- Stable
This is how all the data are stored. In all MySQL releases there hasn't been a single (reported) bug in this code. The only known way to get a corrupted table is to kill the server in the middle of an update. Even that is unlikely to destroy any data beyond rescue, because all data is flushed to disk between each query. There hasn't been a single bug report about lost data because of bugs in MySQL, either.
The parser and lexical analyser -- Stable
There hasn't been a single reported bug in this system for a couple of months.
The C client code -- Stable
No known problems. In early 3.20 releases, there were some limitations in the send/receive buffer size. In 3.21.x, the send/receive buffer is now dynamic up to a default of 512K.
mysql, mysqladmin and mysqlshow -- Stable
The command line clients have had very few bugs.
mysqldump and mysqlimport -- Beta
Rewritten for 3.21.
Basic SQL -- Stable
The basic SQL function system and string classes and dynamic memory handling. Not a single reported bug on this system.
Query optimizer -- Gamma
Some changes in 3.21.
Range optimizer -- Alpha
Totally rewritten for 3.21.x
Join optimizer -- Gamma
Small changes for 3.21.
GROUP BY, ORDER BY and related function COUNT() -- Beta
Rewritten for 3.21 and throughly tested.
Locking -- Gamma
This is very system-dependent. On some systems there are big problems using standard OS locking (fcntl()). In these cases, you should run the MySQL daemon with the --skip-locking flag. Problems are known to occur on some Linux systems and on SunOS when using NFS-mounted file systems.
Linux threads -- Gamma
The only problem found has been with the fcntl() call, which is fixed by using the --skip-locking option to mysqld. Some people have reported lockup problems with the 0.5 release.
Solaris 2.5+ pthreads -- Stable
We use this for all our production work.
MIT-pthreads (Other systems) -- Beta
There have been no reported bugs since 3.20.15 and no known bugs since 3.20.16. On some systems, there is a "misfeature" where some operations are quite slow (a 1/20 second sleep is done between each query). Of course, MIT-pthreads may slow down everything a bit, but for index-based SELECT statements, a SELECT is usually done in one time frame so there shouldn't be a mutex locking/thread juggling.
Other thread implementions -- Alpha
The ports to other systems are still very new and may have bugs, either in MySQL but most often in the thread implementation itself.
LOAD DATA ..., INSERT ... SELECT -- Stable
Some people have thought they have found bugs here, but these have turned out to be misunderstandings. So check the manual before reporting bugs!
ALTER TABLE -- Gamma
Partly rewritten for 3.21.
DBD -- Beta
Now maintained by Jochen Wiedmann
mysqlaccess -- Beta
Written and maintained by Yves Carlier
The Technical Documentation -- Beta
It is improving.
MyODBC (uses ODBC SDK 2.5) -- Beta
It seems to work well with some programs.

TcX provides email support for paying customers, but the MySQL mailing list usually provides answers to common questions. Bugs are usually fixed right away with a patch; for serious bugs, there is almost always a new release.

9.2 Why are there is so many releases of MySQL?

Well, MySQL is evolving quite rapidly here at TcX and we want to share this with other MySQL users. We try to make a release when we have a very useful feature that others seem to have a need for.

We also try to help out users who request features that are easy to implement. We also take note on what our licensed users want to have and we especially take notes of what our extended email supported customers want and try to help them out.

No one has to download a new release. The News section will tell you if the new release has something you really want. See section D MySQL change history.

If there is, by any chance, a fatal bug in a release we will make a new release as soon as possible. We would like other companies to do this, too. :)

The 3.21.x version incorporates major portability changes for many different systems. When the 3.21 release is stable, we will remove the alpha/beta suffix and move active development to 3.22. Bugs will still be fixed in the stable version. We don't believe in a complete freeze, as this also leaves out bug fixes and things that "must be done". "Somewhat frozen" means that we may add small things that "almost surely will not affect anything that's already working".

If you are running an old system and want to upgrade, but don't want to take chances with 3.21, you should upgrade to 3.20.32. We have tried to fix only fatal bugs and make small, relatively safe changes in this version.

If you are trying MySQL for the first time, or have little time to test that MySQL works on your current system, you should use 3.21.

9.3 Checking a table for errors

If MySQL crashes or is terminated without all data having been written to disk (for example, if the computer is turned off), the tables may become corrupted. To check a table, use the following commands:

isamchk tbl_name
This finds 99.99% of all errors. What it can't find is corruption that involves ONLY the data file (which is very unusual). If you want to check a table you should normally run isamchk without options or with the --silent option.
isamchk -e tbl_name
This does a complete and thorough check of all data. It does a check-read of all keys for every row to check that they indeed point to the correct row. This may take a LONG time on a big table with many keys. isamchk will normally stop after the first error it finds. If you want to obtain more information, you can add the --verbose (-v) switch. This causes isamchk to keep going, up through a maximum of 20 errors. In normal usage, a simple isamchk (with no arguments other than the table name) is safe enough!
isamchk -e -i tbl_name
Like the previous command, but also prints some statistics.

At TcX, we run a cron job to check all our important tables once a week:

35 0 * * 0 /path/to/isamchk -s /path/to/dbs/*/*.ISM

This prints out information about crashed tables so we can examine and repair them when needed. The -s option causes isamchk to run in silent mode, printing messages only when errors occur.

As we haven't had any unexpectedly crashed tables (tables that become corrupted for reasons other than hardware trouble) for a couple of years now (this is really true), once a week is more than enough for us.

Of course, whenever the machine has done a reboot in the middle of an update, you usually need to check all the tables that could have been affected. (This is an "expected crashed table".)

We recommend that to start with, you execute isamchk -s each night on all tables that have been updated during the last 24 hours, until you come to trust MySQL as much as we do.

Naturally, you could add a test to safe_mysqld that runs isamchk to check all tables that have been modified during the last 24 hours if there is an old `.pid' file left after a reboot. The `.pid' file is removed by mysqld when it terminates normally. Its presence at system startup time indicates that mysqld terminated abnormally.

9.4 How to repair tables

The file format that MySQL uses to store data has been extensively tested, but there are always circumstances that may cause tables to become corrupted, such as the mysqld process being killed in the middle of a write, a hardware error or an unexpected shutdown of the computer.

The symptoms of a corrupted table are usually that queries abort unexpectedly and that you observe errors such as these:

In these cases, you must repair your tables. The isamchk external utility can usually detect and fix most things that go wrong. See section 13.2 The MySQL table check, optimize and repair program.

If you are going to use isamchk on very large files, you should first decide how much memory you want it to use. (isamchk runs faster with more memory.) For example, if you have more than 32M RAM, try:

shell> isamchk -O sortbuffer=16M -O keybuffer=16M \
           -O readbuffer=1M -O writebuffer=1M ....

The repair process involves up to four parts, described below. Before you begin, you should cd to the database directory and check the permissions of the table files. Make sure they are readable to the Unix user that mysqld runs as. If it turns out you need to modify files, they must also be writable to that user.

Each table tbl_name corresponds to three files:

File Purpose
`tbl_name.frm' Table definition (form) file
`tbl_name.ISD' Data file
`tbl_name.ISM' Index file

Part 1: Checking your tables

Part 2: Easy safe repair

Part 3: Difficult repair

Part 4: Very difficult repair

9.5 Is there anything special to do when upgrading/downgrading MySQL?

You can always move the MySQL form and data files between different versions on the same architecture as long as you have the same base version of MySQL. The current base version is 3. If you change the character set by recompiling MySQL (which may also change the sort order), you must run isamchk -r -q on all tables.

If you are paranoid and/or afraid of new versions, you can always rename your old mysqld to something like mysqld-'old-version-number'. If your new mysqld then does something unexpected you can simply shut it down and restart with your old mysqld!

When you do an upgrade you should, of course, also take a backup of your old databases. Sometimes it's good to be a little paranoid!

If, after an upgrade, you experience problems with recompiled client programs, like 'Commands out sync' or unexpected core dumps, you probably have included an old `mysql.h' file when compiling your programs. In this case you should check the date for your `mysql.h' file and `libmysql.a' library to verify that they are from the same MySQL distribution. If not, please recompile your programs!

9.5.1 Upgrading from a 3.21 version to 3.22

Nothing that affects compatibility has changed between 3.21 and 3.22. The only pitfall is that new tables that are created with DATE type columns will use the new way to store the date. You can't access these new fields from an old version of mysqld.

The C interface to mysql_real_connect() has changed. If you have an old client program that calls this function, you must place a 0 for the new DB argument (or recode the client to send the db element for faster connections).

9.5.2 Upgrading from a 3.20 version to 3.21

If you already have a version older than 3.20.28 running and want to switch to 3.21.# you need to do the following:

You can start the mysqld 3.21 server with safe_mysqld --old-protocol to use it with clients from the 3.20 distribution. In this case, the new client function mysql_errno() will not return any server error, only CR_UNKNOWN_ERROR, (but it works for client errors) and the server uses the old password() checking rather than the new one.

If you are NOT using the --old-protocol option to mysqld, you will need to make the following changes:

MySQL 3.20.28 and above can handle the new user table format without affecting clients. If you have a MySQL version earlier than 3.20.28, passwords will no longer work on it if you convert the user table. So to be safe, you should first upgrade to at least 3.20.28 and then upgrade to 3.21.#.

The new client code works with a 3.20.# mysqld server, so if you experience problems with 3.21.#, you can use the old 3.20.# server without having to recompile the clients again.

If you are not using the --old-protocol option to mysqld, old clients will issue the error message:

ERROR: Protocol mismatch. Server Version = 10 Client Version = 9

The new Perl DBI/DBD interface also supports the old mysqlperl interface. The only change you have to make if you use mysqlperl is to change the arguments to the connect() function. The new arguments are: host, database, user, password (the user and password arguments have changed places).

The following changes may affect queries in old applications:

9.5.3 Upgrading to another architecture

Currently the MySQL data (`*.ISD') and index (`*.ISD') files are architecture-dependent and in some case OS-dependent. If you want to move your applications to another machine that has a different architecture/OS than your current machine, you should use mysqldump.

By default, mysqldump will create a file full of SQL statements. You can then transfer the file to the other machine and feed it as input to the mysql client.

Try mysqldump --help to see what options are available. If you are moving the data to a newer version of MySQL, you should use mysqldump --opt with the newer version to get a fast, compact dump.

The easiest (although not the fastest) way to move a database between two machines is to run the following commands on the machine on which the database is located:

shell> mysqladmin -h 'other hostname' create db_name
shell> mysqldump --opt db_name \
        | mysql -h 'other hostname' db_name

If you want to copy a database from a remote machine over a slow network, you can use:

shell> mysqladmin create db_name
shell> mysqldump -h 'other hostname' --opt --compress db_name \
        | mysql db_name

You can also store the result in a file (compressed in this example):

shell> mysqldump --quick db_name | gzip > db_name.contents.gz

Transfer the file containing the database contents to the target machine and run these commands there:

shell> mysqladmin create db_name
shell> gunzip < db_name.contents.gz | mysql db_name

You can also use mysqldump and mysqlimport to accomplish the database transfer. For big tables, this is much faster than simply using mysqldump. In the commands shown below, PATH represents the full pathname of a directory you use to store the output from mysqldump.

First, create the directory for the output files and dump the database:

shell> mkdir PATH
shell> mysqldump --tab=PATH db_name

Then transfer the files in the PATH directory some corresponding directory on the target machine and load the files into MySQL there:

shell> mysqladmin create db_name
shell> cat PATH/*.sql | mysql db_name
shell> mysqlimport db_name PATH/*.txt

Also, don't forget to copy the mysql database, since that's where the privilege tables (user, db, host) are stored. You may have to use the MySQL user root on the new machine until you have the mysql database in place.

Finally (or immediately after you import the mysql database), execute mysqladmin reload on the new machine so that the server reloads the privileges information.

9.6 Year 2000 compliance

MySQL uses Unix time functions and has no problems with dates until 2069; All 2-digit years are regarded to be in the range 1970-2069, which means that if you store 01 in a year column, MySQL treats it as 2001. In MySQL 3.22, the new YEAR column type can store years 0 and 1901 to 2155 in 1 byte and display them using 2 or 4 digits.

The year 2000 is a problem only for old applications that have stored dates with 2 digits and manipulates the date in many different programs in with different functions. All MySQL date functions are stored in one file `sql/time.cc' and coded very carefully to be year 2000-safe.


Go to the first, previous, next, last section, table of contents.