Silent MyISAM Table Definition Changes and mysqldump

Posted in: Technical Track

The other day while trying to move a schema from one MySQL server to another, I encountered a very odd issue. The schema to be moved contained both MyISAM and InnoDB tables, so the only option I had was to dump the schema using mysqldump on the source server and import it on the destination server. The dump on the source server went fine with absolutely no issues but it failed to import into the second server, and the error message was:

Can't create/write to file ‘/disk1/activity.MYI’ (Errcode: 2)

This was an extremely odd message as the data directory on the destination server was properly setup in terms of ownership and permission. The source and destination MySQL servers have been running without issues for months. Prior to the error, four tables in the dump file were imported into the destination server without any issues whatsoever. Furthermore the source and destination server have the exact same operating system (down to the release and patch-set) and the version of MySQL running on both server was identical. This very much surprised me as mysqldump is suppose to be the safe and guaranteed way of moving MySQL data around.

I did some digging and found that the problem was that the MyISAM engine silently changed the table definition without any indications. This is not the usual ‘Silent Column Specification Changes’ that is a known issues with MySQL nor was cause by a MySQL version upgrade.  The root of the issue went back a few months ago when the source server ran low on disk space and as a result another volume was added. Some tables, including a few from the schema to be moved, were copied to the new volume and symlinked back to the original location. This was done entirely offline by first stopping MySQL, copying the files  to the new location, symlinking the files back to the original location, and starting MySQL again.

For the symlinked InnoDB tables (both the .ibd and .frm file were moved to the new location and symlinked back), there were absolutely no issues at all in MySQL and the dump. InnoDB happily told the underlying operating system, Linux in this case, to open the file and the operating system happily de-references the symlink. The symlinked MyISAM tables, on the other hand, worked properly in MySQL but due to the silent table definition changes made the dump unusable for import onto another MySQL server.  For each MyISAM table which was moved , all three files (the .MYD/.MYI/.frm files) corresponding to the table were moved and symlinked back.  However when MySQL started after the move/symlink process and accessed the symlinked MyISAM table the first time, it noticed the data file (the .MYD file) and index file (the .MYI file) had been moved and silently changed the table definition without any warning, error, or informational message of any kind.

The original table definition was below, of course with client details removed.



So when MySQL restarted and the symlinked MyISAM table was accessed,  the table definition to be the following:




As per the MySQL manual, the DATA DIRECTORY and INDEX DIRECTORY options point to the path of the .MYD and .MYI file respectively. It is possible to create a MyISAM table where the .MYD and .MYI file are in a non standard location by using the DATA DIRECTORY and INDEX DIRECTION options during during the creation of the table, however this only changes where the .MYD and .MYI files are stored. The .frm file, which contain the table definitions, cannot be moved to an alternative locations this way and is always stored in the original location.  Regardless of  these options, the symlinked MyISAM tables which caused this issue were not created using these options at all and in fact for these tables all three files, the .MYD/.MYI/.frm, was moved to the new location and symlinked back.

So when the table is dumped out to a file using mysqldump, the table definition is saved as it is to the dump file with the explicit path for the MYD and MYI file. The benefit is that if the dump can be restored on the original server, since it will properly place the MYD and MYI files ont he secoendary locations. However when the dump file is imported to the new server, MySQL will try to create the MYD and MYI file in the path specified in the table definition. Of course if on the new server the path doesn’t exist, an error occurs in the import.

Of course there are many solutions around this problem.

  • Never use symlinks at all, just switch to bigger disks all the time
  • We could not symlink individual tables but instead entire schemas, which would then not see this issue.
  • Another solution is to only symlink InnoDB tables, which are less intelligence in this manner.
  • Instead of dumping everything in one dump file, dump the data and the schema into separate files. The schema file should be fairly small and easily editable with Emacs.


Want to talk with an expert? Schedule a call with our team to get the conversation started.

4 Comments. Leave new

Sergei Golubchik
June 17, 2011 2:33 am

Heh, this isn’t “silent definition change” done by MySQL – it’s you who changed the definition. By simlinking you changed the definition as surely as you could’ve done with a hex editor. MySQL only shows the correct current definition of the table. If you edit the table outside of MySQL – well, MySQL isn’t a DWIM tool, unfortunately.

Singer Wang
June 20, 2011 2:43 pm

Sergei, I’ll disagree for 2 reasons and argue against it as well.

1) This change of the table definition only applies to MyISAM and not InnoDB/CSV/BerkelyDB engines.

2) If you were to drop the table and re-created it using the definition from ‘show create table’, the table will not be 100% reproduced. The .frm file, which was symlinked as well, will not be in the new table.


3) In other database, such as Oracle or PostgreSQL, this does not happen. If you were to shut-down the database and move/symlink data files, the database does not change its internal records of where the data files are.

Singer Wang
June 20, 2011 2:59 pm

Also its not listed anywhere in the manual that these changes will happen if you symlink.

Log Buffer #225, A Carnival of the Vanities for DBAs | The Pythian Blog
June 17, 2011 4:52 am

[…] Singer Wang encountered an odd issue while trying to move a schema from one MySQL server to another. […]


Leave a Reply

Your email address will not be published. Required fields are marked *