Chapter 11 Upgrading or Downgrading MySQL

Table of Contents

11.1 Upgrading MySQL
11.1.1 Changes Affecting Upgrades to 5.1
11.2 Downgrading MySQL
11.2.1 Changes Affecting Downgrades from MySQL 5.1
11.2.2 Downgrading from MySQL Enterprise Edition to MySQL Community Server
11.3 Checking Whether Tables or Indexes Must Be Rebuilt
11.4 Rebuilding or Repairing Tables or Indexes
11.5 Copying MySQL Databases to Another Machine

This section describes the steps to upgrade or downgrade a MySQL installation.

Upgrading is a common procedure, as you pick up bug fixes within the same MySQL release series or significant features between major MySQL releases. You perform this procedure first on some test systems to make sure everything works smoothly, and then on the production systems.

Downgrading is less common. Typically, you undo an upgrade because of some compatibility or performance issue that occurs on a production system, and was not uncovered during initial upgrade verification on the test systems. As with the upgrade procedure, perform and verify the downgrade procedure on some test systems first, before using it on a production system.

11.1 Upgrading MySQL

This section describes how to upgrade to a new MySQL version.

Supported Upgrade Methods

  • In-place Upgrade: Involves shutting down the old MySQL version, replacing the old MySQL binaries or packages with the new ones, restarting MySQL on the existing data directory, and running mysql_upgrade.

  • Logical Upgrade: Involves exporting existing data from the old MySQL version using mysqldump, installing the new MySQL version, loading the dump file into the new MySQL version, and running mysql_upgrade.

    Note

    MySQL recommends a mysqldump upgrade when upgrading from a previous release. For example, use this method when upgrading from 5.0 to 5.1.

For in-place and logical upgrade procedures, see Performing an In-place Upgrade, and Performing a Logical Upgrade.

If you run MySQL Server on Windows, see Section 5.9, “Upgrading MySQL Server on Microsoft Windows”.

Supported Upgrade Paths

Unless otherwise documented, the following upgrade paths are supported:

  • Upgrading from a release series version to a newer release series version is supported. For example, upgrading from 5.1.71 to 5.1.72 is supported. Skipping release series versions is also supported. For example, upgrading from 5.1.70 to 5.1.72 is supported.

  • Upgrading one release level is supported. For example, upgrading from 5.0 to 5.1 is supported. Upgrading to the latest release series version is recommended before upgrading to the next release level. For example, upgrade to the latest 5.0 release before upgrading to 5.1.

  • Upgrading more than one release level is supported, but only if you upgrade one release level at a time. For example, if you currently are running MySQL 4.1 and wish to upgrade to a newer series, upgrade to MySQL 5.0 first before upgrading to MySQL 5.1, and so forth. For information on upgrading to MySQL 5.0 see the MySQL 5.0 Reference Manual.

  • Direct upgrades that skip a release level (for example, upgrading directly from MySQL 4.1 to 5.1) are not recommended or supported.

The following conditions apply to all upgrade paths:

  • Upgrades between General Availability (GA) status releases are supported.

  • Upgrades between milestone releases (or from a milestone release to a GA release) are not supported.

  • For upgrades between versions of a MySQL release series that has reached GA status, you can move the MySQL format files and data files between different versions on systems with the same architecture. This is not necessarily true for upgrades between milestone releases. Use of milestone releases is at your own risk.

Before You Begin

Before upgrading, review the following information and perform the recommended steps:

  • Before upgrading, protect your data by creating a backup of your current databases and log files. The backup should include the mysql database, which contains the MySQL system tables. See Database Backup Methods.

  • Review the Release Notes which provide information about features that are new in the MySQL 5.1 or differ from those found in earlier MySQL releases. Some of these changes may result in incompatibilities.

  • Review Section 11.1.1, “Changes Affecting Upgrades to 5.1”. This section describes changes that may require action before or after upgrading.

  • Check Section 11.3, “Checking Whether Tables or Indexes Must Be Rebuilt”, to see whether changes to table formats or to character sets or collations were made between your current version of MySQL and the version to which you are upgrading. If such changes have resulted in an incompatibility between MySQL versions, you will need to upgrade the affected tables using the instructions in Section 11.4, “Rebuilding or Repairing Tables or Indexes”.

  • If you use replication, see Upgrading a Replication Setup, for information on upgrading your replication setup.

  • If you use XA transactions with InnoDB, run XA RECOVER before upgrading to check for uncommitted XA transactions. If results are returned, either commit or rollback the XA transactions by issuing an XA COMMIT or XA ROLLBACK statement.

  • If your MySQL installation contains a large amount of data that might take a long time to convert after an in-place upgrade, you might find it useful to create a dummy database instance for assessing what conversions might be needed and the work involved to perform them. Make a copy of your MySQL instance that contains a full copy of the mysql database, plus all other databases without data. Run your upgrade procedure on this dummy instance to see what actions might be needed so that you can better evaluate the work involved when performing actual data conversion on your original database instance.

  • Rebuilding and reinstalling the Perl DBD::mysql module whenever you install or upgrade to a new release of MySQL is recommended. The same applies to other MySQL interfaces as well, such as PHP mysql extensions and the Python MySQLdb module.

Performing an In-place Upgrade

This section describes how to perform an in-place upgrade. Review Before you Begin before proceeding.

Note

If you upgrade an installation originally produced by installing multiple RPM packages, upgrade all the packages, not just some. For example, if you previously installed the server and client RPMs, do not upgrade just the server RPM.

To perform an in-place upgrade:

  1. Review the changes described in Section 11.1.1, “Changes Affecting Upgrades to 5.1” for steps to be performed before upgrading.

  2. If you use InnoDB, configure MySQL to perform a slow shutdown by setting innodb_fast_shutdown to 0. For example:

    shell> bin/mysql -u root -ppassword --execute="set global innodb_fast_shutdown=0"

    With a slow shutdown, InnoDB performs a full purge and change buffer merge before shutting down, which ensures that data files are fully prepared in case of file format differences between releases.

  3. Shut down the old MySQL server. For example:

    shell> bin/mysqladmin -u root -ppassword shutdown
  4. Upgrade the MySQL binaries or packages in place (replace the old binaries with the new ones).

  5. Start the MySQL 5.1 server, using the existing data directory. For example:

    shell> bin/mysqld_safe --user=mysql --datadir=/path/to/existing-datadir
    
  6. Run mysql_upgrade. For example:

    shell> bin/mysql_upgrade -u root -ppassword

    mysql_upgrade examines all tables in all databases for incompatibilities with the current version of MySQL. mysql_upgrade also upgrades the system tables so that you can take advantage of new privileges or capabilities.

    Note

    mysql_upgrade does not upgrade the contents of the help tables. For upgrade instructions, see Server-Side Help.

Performing a Logical Upgrade

This section describes how to perform a logical upgrade. Review Before you Begin before proceeding.

To perform a logical upgrade:

  1. Review the changes described in Section 11.1.1, “Changes Affecting Upgrades to 5.1” for steps to be performed before upgrading.

  2. Export your existing data from the previous MySQL version:

    shell> mysqldump --add-drop-table --routines --events
        -> --all-databases --force > data-for-upgrade.sql
    
    Note

    Use the --routines and --events options with mysqldump (as shown above) if your databases include stored programs. The --all-databases option includes all databases in the dump, including the mysql database that holds the system tables.

  3. Shut down the old MySQL server. For example:

    shell> bin/mysqladmin -u root -ppassword shutdown
  4. Install MySQL 5.1. For installation instructions, see Chapter 1, Installing and Upgrading MySQL.

  5. Initialize a new data directory:

    shell> scripts/mysql_install_db --user=mysql --datadir=/path/to/5.1-datadir
    
  6. Start the MySQL 5.1 server, using the new data directory. For example:

    shell> bin/mysqld_safe --user=mysql --datadir=/path/to/5.1-datadir
    
  7. Load the previously created dump file into the new MySQL server. For example:

    shell> bin/mysql -u root -ppassword --execute="source data-for-upgrade.sql" --force
  8. Run mysql_upgrade. For example:

    shell> bin/mysql_upgrade -u root -ppassword

    mysql_upgrade examines all tables in all databases for incompatibilities with the current version of MySQL. mysql_upgrade also upgrades the system tables so that you can take advantage of new privileges or capabilities.

    Note

    mysql_upgrade does not upgrade the contents of the help tables. For upgrade instructions, see Server-Side Help.

  9. If you use InnoDB, configure MySQL to perform a slow shutdown by setting innodb_fast_shutdown to 0. For example:

    shell> bin/mysql -u root -ppassword --execute="set global innodb_fast_shutdown=0"
  10. Shut down and restart the MySQL server to ensure a clean shutdown and startup. For example:

    shell> bin/mysqladmin -u root -ppassword shutdown
    shell> bin/mysqld_safe --user=mysql --datadir=/path/to/5.1-datadir
    

Upgrade Troubleshooting

  • If problems occur, such as that the new mysqld server does not start or that you cannot connect without a password, verify that you do not have an old my.cnf file from your previous installation. You can check this with the --print-defaults option (for example, mysqld --print-defaults). If this command displays anything other than the program name, you have an active my.cnf file that affects server or client operation.

  • If, after an upgrade, you experience problems with compiled client programs, such as Commands out of sync or unexpected core dumps, you probably have used old header or library files when compiling your programs. In this case, check the date for your mysql.h file and libmysqlclient.a library to verify that they are from the new MySQL distribution. If not, recompile your programs with the new headers and libraries. Recompilation might also be necessary for programs compiled against the shared client library if the library major version number has changed (for example from libmysqlclient.so.15 to libmysqlclient.so.16.

  • If you have created a user-defined function (UDF) with a given name and upgrade MySQL to a version that implements a new built-in function with the same name, the UDF becomes inaccessible. To correct this, use DROP FUNCTION to drop the UDF, and then use CREATE FUNCTION to re-create the UDF with a different nonconflicting name. The same is true if the new version of MySQL implements a built-in function with the same name as an existing stored function. See Function Name Parsing and Resolution, for the rules describing how the server interprets references to different kinds of functions.

11.1.1 Changes Affecting Upgrades to 5.1

Before upgrading to MySQL 5.1, review the changes described in this section to identify upgrade issues that apply to your current MySQL installation and applications.

Note

In addition to the changes outlined in this section, review the Release Notes and other important information outlined in Before You Begin.

Changes marked as either Known issue or Incompatible change are incompatibilities with earlier versions of MySQL, and may require your attention before you upgrade. Our aim is to avoid these changes, but occasionally they are necessary to correct problems that would be worse than an incompatibility between releases. If any upgrade issue applicable to your installation involves an incompatibility that requires special handling, follow the instructions given in the incompatibility description. Sometimes this involves dumping and reloading tables, or use of a statement such as CHECK TABLE or REPAIR TABLE.

For dump and reload instructions, see Section 11.4, “Rebuilding or Repairing Tables or Indexes”. Any procedure that involves REPAIR TABLE with the USE_FRM option must be done before upgrading. Use of this statement with a version of MySQL different from the one used to create the table (that is, using it after upgrading) may damage the table. See REPAIR TABLE Syntax.

Configuration Changes

  • Before MySQL 5.1.11, to build MySQL from source with SSL support enabled, you would invoke configure with either the --with-openssl or --with-yassl option. In MySQL 5.1.11, those options both have been replaced by the --with-ssl option. By default, --with-ssl causes the bundled yaSSL library to be used. To select OpenSSL instead, give the option as --with-ssl=path, where path is the directory where the OpenSSL header files and libraries are located.

System Table Changes

  • After upgrading a 5.0 installation to 5.0.10 or above, it is necessary to upgrade your grant tables using mysql_upgrade. Otherwise, creating stored procedures and functions might not work. Running mysql_upgrade is part of the the in-place and logical upgrade procedures.

Server Changes

  • As of MySQL 5.1.9, the mysqld-max server is included in binary distributions. There is no separate MySQL-Max distribution. As of MySQL 5.1.12, there is no mysqld-max server at all in binary distributions. They contain a server that includes the features previously included in mysqld-max.

  • Known issue: As of MySQL 5.1.70, for new installations, the url columns in the mysql datatbase help tables are now created as type TEXT to accommodate longer URLs. For upgrades, mysql_upgrade does not update the columns. Modify them manually using these statements:

    ALTER TABLE mysql.help_category MODIFY url TEXT NOT NULL;
    ALTER TABLE mysql.help_topic MODIFY url TEXT NOT NULL;
    
  • Known issue: mysql_upgrade attempts to upgrade tables that are incompatible with the current version of MySQL. (It invokes mysqlcheck to check tables and, if necessary, repair them.) However this can fail for storage engines that do not support REPAIR TABLE, such as InnoDB, and leave tables in a nonupgradable state.

    To work around this problem, use ALTER TABLE tbl_name ENGINE=InnoDB to perform a null alter operation that rebuilds the table.

  • Known issue: After a binary upgrade to MySQL 5.1 from a MySQL 5.0 installation that contains ARCHIVE tables:

    • Before MySQL 5.1.42, accessing those tables will cause the server to crash, even if you have run mysql_upgrade or CHECK TABLE ... FOR UPGRADE.

    • As of MySQL 5.1.42, the server will not open 5.0 ARCHIVE tables at all.

    In either case, the solution is to use mysqldump to dump all 5.0 ARCHIVE tables before upgrading, and reload them into MySQL 5.1 after upgrading. This problem is fixed in MySQL 5.6.4: The server can open ARCHIVE tables created in MySQL 5.0. However, it remains the recommended upgrade procedure to dump 5.0 ARCHIVE tables before upgrading and reload them after upgrading.

  • Known issue: The fix for Bug #23491 introduced a problem with SHOW CREATE VIEW, which is used by mysqldump. This causes an incompatibility when upgrading from versions affected by that bug fix (MySQL 5.0.40 through 5.0.43, MySQL 5.1.18 through 5.1.19): If you use mysqldump before upgrading from an affected version and reload the data after upgrading to a higher version, you must drop and recreate your views.

  • Known issue: Dumps performed by using mysqldump to generate a dump file before the upgrade and reloading the file after upgrading are subject to the following problem:

    Before MySQL 5.0.40, mysqldump displays SPATIAL index definitions using prefix lengths for the indexed columns. These prefix lengths are accepted in MySQL 5.0, but not as of MySQL 5.1. If you use mysqldump from versions of MySQL older than 5.0.40, any table containing SPATIAL indexes will cause an error when the dump file is reloaded into MySQL 5.1 or higher.

    For example, a table definition might look like this when dumped in MySQL 5.0:

    CREATE TABLE `t` (
     `g` geometry NOT NULL,
     SPATIAL KEY `g` (`g`(32))
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1
    

    The SPATIAL index definition will not be accepted in MySQL 5.1. To work around this, edit the dump file to remove the prefix:

    CREATE TABLE `t` (
     `g` geometry NOT NULL,
     SPATIAL KEY `g` (`g`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1
    

    Dump files can be large, so it may be preferable to dump table definitions and data separately to make it easier to edit the definitions:

    shell> mysqldump --no-data other_args > definitions.sql
    shell> mysqldump --no-create-info other_args > data.sql
    

    Then edit definitions.sql before reloading definitions.sql and data.sql, in that order.

    If you upgrade to a version of MySQL 5.0 higher than 5.0.40 before upgrading to MySQL 5.1, this problem does not occur.

  • Known issue: Before MySQL 5.1.30, the CHECK TABLE ... FOR UPGRADE statement did not check for incompatible collation changes made in MySQL 5.1.24. (This also affects mysqlcheck and mysql_upgrade, which cause that statement to be executed.)

    Prior to the fix made in 5.1.30, a binary upgrade (performed without dumping tables with mysqldump before the upgrade and reloading the dump file after the upgrade) would corrupt tables. After the fix, CHECK TABLE ... FOR UPGRADE properly detects the problem and warns about tables that need repair.

    However, the fix is not backward compatible and can result in a downgrading problem under these circumstances:

    1. Perform a binary upgrade to a version of MySQL that includes the fix.

    2. Run CHECK TABLE ... FOR UPGRADE (or mysqlcheck or mysql_upgrade) to upgrade tables.

    3. Perform a binary downgrade to a version of MySQL that does not include the fix.

    The solution is to dump tables with mysqldump before the downgrade and reload the dump file after the downgrade. Alternatively, drop and recreate affected indexes.

  • Known issue: MySQL introduces encoding for table names that have non-ASCII characters (see Mapping of Identifiers to File Names). After a binary upgrade from MySQL 5.0 to 5.1 or higher, the server recognizes names that have non-ASCII characters and adds a #mysql50# prefix to them.

    As of MySQL 5.1.31, mysql_upgrade encodes these names by executing the following command:

    mysqlcheck --all-databases --check-upgrade --fix-db-names --fix-table-names
    

    Prior to MySQL 5.1.31, mysql_upgrade does not execute this command, so you should execute it manually if you have database or table names that contain nonalphanumeric characters.

    Prior to MySQL 5.1.23, the mysqlcheck command does not perform the name encoding for views. To work around this problem, drop each affected view and recreate it.

    mysqlcheck cannot fix names that contain literal instances of the @ character that is used for encoding special characters. If you have databases or tables that contain this character, use mysqldump to dump them before upgrading to MySQL 5.1, and then reload the dump file after upgrading.

  • Known issue: When upgrading from MySQL 5.0 to versions of 5.1 prior to 5.1.23, running mysqlcheck (or mysql_upgrade, which runs mysqlcheck) to upgrade tables fails for names that must be written as quoted identifiers. To work around this problem, rename each affected table to a name that does not require quoting:

    RENAME TABLE `tab``le_a` TO table_a;
    RENAME TABLE `table b` TO table_b;
    

    After renaming the tables, run the mysql_upgrade program. Then rename the tables back to their original names:

    RENAME TABLE table_a TO `tab``le_a`;
    RENAME TABLE table_b TO `table b`;
    
  • Known issue: In connection with view creation, the server created arc directories inside database directories and maintained useless copies of .frm files there. Creation and renaming procedures of those copies as well as creation of arc directories has been discontinued in MySQL 5.1.29.

    This change does cause a problem when downgrading to older server versions which manifests itself under these circumstances:

    1. Create a view v_orig in MySQL 5.1.29 or higher.

    2. Rename the view to v_new and then back to v_orig.

    3. Downgrade to an older 5.1.x server and run mysql_upgrade.

    4. Try to rename v_orig to v_new again. This operation fails.

    As a workaround to avoid this problem, use either of these approaches:

    • Dump your data using mysqldump before downgrading and reload the dump file after downgrading.

    • Instead of renaming a view after the downgrade, drop it and recreate it.

  • Incompatible change: Character set or collation changes may require table indexes to be rebuilt. In MySQL 5.1, these occurred in versions 5.1.21, 5.1.23, and 5.1.24. For details, see Section 11.3, “Checking Whether Tables or Indexes Must Be Rebuilt”.

  • Incompatible change: Prior to MySQL 5.1.51, if you flushed the logs using FLUSH LOGS or mysqladmin flush-logs and mysqld was writing the error log to a file (for example, if it was started with the --log-error option), it renames the current log file with the suffix -old, then created a new empty log file. This had the problem that a second log-flushing operation thus caused the original error log file to be lost unless you saved it under a different name. For example, you could use the following commands to save the file:

    shell> mysqladmin flush-logs
    shell> mv host_name.err-old backup-directory
    

    To avoid the preceding file-loss problem, no renaming occurs as of MySQL 5.1.51; the server merely closes and reopens the log file. To rename the file, you can do so manually before flushing. Then flushing the logs reopens a new file with the original file name. For example, you can rename the file and create a new one using the following commands:

    shell> mv host_name.err host_name.err-old
    shell> mysqladmin flush-logs
    shell> mv host_name.err-old backup-directory
    
  • Incompatible change: MySQL 5.1 implements support for a plugin API that enables the loading and unloading of components at runtime, without restarting the server. The MySQL Plugin API. The plugin API requires the mysql.plugin table. After upgrading from an older version of MySQL, you should run the mysql_upgrade command to create this table. See mysql_upgrade — Check and Upgrade MySQL Tables.

    Plugins are installed in the directory named by the plugin_dir system variable. This variable also controls the location from which the server loads user-defined functions (UDFs), which is a change from earlier versions of MySQL. That is, all UDF library files now must be installed in the plugin directory. When upgrading from an older version of MySQL, you must migrate your UDF files to the plugin directory.

  • Incompatible change: The table_cache system variable has been renamed to table_open_cache. Any scripts that refer to table_cache must be updated to use the new name.

  • Incompatible change: In MySQL 5.1.36, options for loading plugins such as pluggable storage engines were changed from boolean to tristate format. The implementations overlap, but if you previously used options of the form --plugin_name=0 or --plugin_name=1, you should instead use --plugin_name=OFF or --plugin_name=ON, respectively. For details, see Installing and Uninstalling Plugins.

  • Incompatible change: From MySQL 5.1.24 to 5.1.31, the UPDATE statement was changed such that assigning NULL to a NOT NULL column caused an error even when strict SQL mode was not enabled. The original behavior before MySQL 5.1.24 was that such assignments caused an error only in strict SQL mode, and otherwise set the column to the implicit default value for the column data type and generated a warning. (For information about implicit default values, see Data Type Default Values.)

    The change caused compatibility problems for applications that relied on the original behavior. It also caused replication problems between servers that had the original behavior and those that did not, for applications that assigned NULL to NOT NULL columns in UPDATE statements without strict SQL mode enabled. The change was reverted in MySQL 5.1.32 so that UPDATE again had the original behavior. Problems can still occur if you replicate between servers that have the modified UPDATE behavior and those that do not.

  • Incompatible change: As of MySQL 5.1.29, the default binary logging mode has been changed from MIXED to STATEMENT for compatibility with MySQL 5.0.

  • Incompatible change: In MySQL 5.1.25, a change was made to the way that the server handles prepared statements. This affects prepared statements processed at the SQL level (using the PREPARE statement) and those processed using the binary client/server protocol (using the mysql_stmt_prepare() C API function).

    Previously, changes to metadata of tables or views referred to in a prepared statement could cause a server crash when the statement was next executed, or perhaps an error at execute time with a crash occurring later. For example, this could happen after dropping a table and recreating it with a different definition.

    Now metadata changes to tables or views referred to by prepared statements are detected and cause automatic repreparation of the statement when it is next executed. Metadata changes occur for DDL statements such as those that create, drop, alter, rename, or truncate tables, or that analyze, optimize, or repair tables. Repreparation also occurs after referenced tables or views are flushed from the table definition cache, either implicitly to make room for new entries in the cache, or explicitly due to FLUSH TABLES.

    Repreparation is automatic, but to the extent that it occurs, performance of prepared statements is diminished.

    Table content changes (for example, with INSERT or UPDATE) do not cause repreparation, nor do SELECT statements.

    An incompatibility with previous versions of MySQL is that a prepared statement may now return a different set of columns or different column types from one execution to the next. For example, if the prepared statement is SELECT * FROM t1, altering t1 to contain a different number of columns causes the next execution to return a number of columns different from the previous execution.

    Older versions of the client library cannot handle this change in behavior. For applications that use prepared statements with the new server, an upgrade to the new client library is strongly recommended.

    Along with this change to statement repreparation, the default value of the table_definition_cache system variable has been increased from 128 to 256. The purpose of this increase is to lessen the chance that prepared statements will need repreparation due to referred-to tables/views having been flushed from the cache to make room for new entries.

    A new status variable, Com_stmt_reprepare, has been introduced to track the number of repreparations.

  • Incompatible change: The -, *, and / operators and the functions POW() and EXP() could misbehave when used with floating-point numbers. Previously they might return +INF, -INF, or NaN in cases of numeric overflow (including that caused by division by zero) or when invalid arguments were used. As of MySQL 5.1.24, NULL is returned in all such cases.

  • Incompatible change: As of MySQL 5.1.23, within a stored routine, it is no longer permissible to declare a cursor for a SHOW or DESCRIBE statement. This happened to work in some instances, but is no longer supported. In many cases, a workaround for this change is to use the cursor with a SELECT query to read from an INFORMATION_SCHEMA table that produces the same information as the SHOW statement.

  • Incompatible change: SHOW CREATE VIEW displays view definitions using an AS alias_name clause for each column. If a column is created from an expression, the default alias is the expression text, which can be quite long. As of MySQL 5.1.23, aliases for column names in CREATE VIEW statements are checked against the maximum column length of 64 characters (not the maximum alias length of 256 characters). As a result, views created from the output of SHOW CREATE VIEW fail if any column alias exceeds 64 characters. This can cause problems for replication or loading dump files. For additional information and workarounds, see Restrictions on Views.

  • Incompatible change: Several issues were identified for stored programs (stored procedures and functions, triggers, and events) and views containing non-ASCII symbols. These issues involved conversion errors due to incomplete character set information when translating these objects to and from stored format.

    To address these problems, the representation for these objects was changed in MySQL 5.1.21. However, the fixes affect all stored programs and views. (For example, you will see warnings about no creation context.) To avoid warnings from the server about the use of old definitions from any release prior to 5.1.21, you should dump stored programs and views with mysqldump after upgrading to 5.1.21 or higher, and then reload them to recreate them with new definitions. Invoke mysqldump with a --default-character-set option that names the non-ASCII character set that was used for the definitions when the objects were originally created, and the --routines, --events, and --triggers options to dump stored program definitions.

    Upgrading for triggers in particular must be handled carefully, for two reasons:

    • The output from mysqldump does not contain a DROP TRIGGER statement preceding each CREATE TRIGGER statement, so reloading the dump file will fail to re-create the triggers unless you manually drop them after generating the dump file and before reloading it.

    • If you are upgrading from a very old version of MySQL 5.0 (before 5.0.10), the trigger upgrade procedure is different because triggers for those versions were created using a different namespace (trigger names had to be unique per table, rather than per schema as is true now).

    Assuming that you are upgrading from MySQL 5.0.10 to 5.1.20 to MySQL 5.1.21 or later, use the following procedure to upgrade your triggers:

    • Use mysqldump to generate a dump file that contains the trigger definitions:

      mysqldump --triggers --no-create-db --no-data 
                --no-create-info --all-databases > triggers.sql
      

      You might need to add options to specify connection parameters, such as --user or --password. Also, if you are updating from a version of MySQL 5.1 older than 5.1.21, you may need to include a --default-character-set option that specifies the non-ASCII character set that was used for the definitions when the triggers were originally created.

      Otherwise, invoke mysqldump with exactly the preceding options to avoid generating a dump file that will not have the intended effect when reloaded. For example, if you omit the --no-create-db option, your databases will be removed and recreated with no contents when you reload the dump file.

    • Drop existing triggers. To see which triggers exist, use this statement:

      SELECT TRIGGER_SCHEMA, EVENT_OBJECT_TABLE, TRIGGER_NAME
      FROM INFORMATION_SCHEMA.TRIGGERS;
      

      To generate DROP TRIGGERS statements for the triggers, use this statement:

      SELECT CONCAT('DROP TRIGGER ', TRIGGER_SCHEMA, '.', TRIGGER_NAME, ';')
      FROM INFORMATION_SCHEMA.TRIGGERS
      INTO OUTFILE '/tmp/drop_triggers.sql';
      

      The statement uses INTO OUTFILE, so you must have the FILE privilege. The file will be created on the server host. Use a different file name if you like. To be 100% safe, inspect the trigger definitions in the drop_triggers.sql file, and perhaps make a backup of the file. Then execute the statements in the file:

      mysql --force < /tmp/drop_triggers.sql
      
    • Recreate the triggers by reloading the dump file created earlier:

      mysql --force < triggers.sql
      

    For upgrades from a version of MySQL older than 5.0.10 to MySQL 5.1.21 or later, use the following procedure to upgrade your triggers:

    1. Upgrade to MySQL 5.1 to be able to access trigger information in the INFORMATION_SCHEMA.TRIGGERS table. (This should work even for pre-5.0.10 triggers.)

    2. Dump all trigger definitions using the following SELECT statement:

      SELECT CONCAT('CREATE TRIGGER ', t.TRIGGER_SCHEMA, '.', t.TRIGGER_NAME,
                    ' ', t.ACTION_TIMING, ' ', t.EVENT_MANIPULATION, ' ON ',
                    t.EVENT_OBJECT_SCHEMA, '.', t.EVENT_OBJECT_TABLE,
                    ' FOR EACH ROW ', t.ACTION_STATEMENT, '//' )
      INTO OUTFILE '/tmp/triggers.sql'
      FROM INFORMATION_SCHEMA.TRIGGERS AS t;
      

      The statement uses INTO OUTFILE, so you must have the FILE privilege. The file will be created on the server host. Use a different file name if you like. To be 100% safe, inspect the trigger definitions in the triggers.sql file, and perhaps make a backup of the file.

    3. Stop the server and drop all triggers by removing all .TRG files in your database directories. Change location to your data directory and issue this command:

      shell> rm */*.TRG
      
    4. Start the server and re-create all triggers using the triggers.sql file:

      mysql> delimiter // ;
      mysql> source /tmp/triggers.sql //
      
    5. Use the SHOW TRIGGERS statement to check that all triggers were created successfully.

  • Incompatible change: As of MySQL 5.1.20, mysqld_safe supports error logging to syslog on systems that support the logger command. The new --syslog and --skip-syslog options can be used instead of the --log-error option to control logging behavior, as described in mysqld_safe — MySQL Server Startup Script.

    In 5.1.21 and up, the default is --skip-syslog, which is compatible with the default behavior of writing an error log file for releases prior to 5.1.20.

    In 5.1.20 only, the following conditions apply: 1) The default is to use syslog, which is not compatible with releases prior to 5.1.20. 2) Logging to syslog may fail to operate correctly in some cases. For these reasons, avoid using MySQL 5.1.20.

  • Incompatible change: As of MySQL 5.1.18, the plugin interface and its handling of system variables was changed. Command-line options such as --skip-innodb now cause an error if InnoDB is not built-in or plugin-loaded. You should use --loose-skip-innodb if you do not want any error even if InnoDB is not available. The --loose prefix modifier should be used for all command-line options where you are uncertain whether the plugin exists and when you want the operation to proceed even if the option is necessarily ignored due to the absence of the plugin. (For a description of how --loose works, see Using Options on the Command Line.)

  • Incompatible change: As of MySQL 5.1.15, InnoDB rolls back only the last statement on a transaction timeout. A new option, --innodb_rollback_on_timeout, causes InnoDB to abort and roll back the entire transaction if a transaction timeout occurs (the same behavior as in MySQL 4.1).

  • Incompatible change: As of MySQL 5.1.15, the following conditions apply to enabling the read_only system variable:

    • If you attempt to enable read_only while you have any explicit locks (acquired with LOCK TABLES or have a pending transaction, an error will occur.

    • If other clients hold explicit table locks or have pending transactions, the attempt to enable read_only blocks until the locks are released and the transactions end. While the attempt to enable read_only is pending, requests by other clients for table locks or to begin transactions also block until read_only has been set.

    • read_only can be enabled while you hold a global read lock (acquired with FLUSH TABLES WITH READ LOCK) because that does not involve table locks.

    Previously, the attempt to enable read_only would return immediately even if explicit locks or transactions were pending, so some data changes could occur for statements executing in the server at the same time.

  • Incompatible change: The number of function names affected by IGNORE_SPACE was reduced significantly in MySQL 5.1.13, from about 200 to about 30. (For details about IGNORE_SPACE, see Function Name Parsing and Resolution.) This change improves the consistency of parser operation. However, it also introduces the possibility of incompatibility for old SQL code that relies on the following conditions:

    • IGNORE_SPACE is disabled.

    • The presence or absence of whitespace following a function name is used to distinguish between a built-in function and stored function that have the same name (for example, PI() versus PI ()).

    For functions that are no longer affected by IGNORE_SPACE as of MySQL 5.1.13, that strategy no longer works. Either of the following approaches can be used if you have code that is subject to the preceding incompatibility:

    • If a stored function has a name that conflicts with a built-in function, refer to the stored function with a schema name qualifier, regardless of whether whitespace is present. For example, write schema_name.PI() or schema_name.PI ().

    • Alternatively, rename the stored function to use a nonconflicting name and change invocations of the function to use the new name.

  • Incompatible change: For utf8 columns, the full-text parser incorrectly considered several nonword punctuation and whitespace characters as word characters, causing some searches to return incorrect results. The fix involves a change to the full-text parser in MySQL 5.1.12, so as of 5.1.12, any tables that have FULLTEXT indexes on utf8 columns must be repaired with REPAIR TABLE:

    REPAIR TABLE tbl_name QUICK;
    
  • Incompatible change: Storage engines can be pluggable at runtime, so the distinction between disabled and invalid storage engines no longer applies. As of MySQL 5.1.12, this affects the NO_ENGINE_SUBSTITUTION SQL mode, as described in Server SQL Modes.

  • Incompatible change: The structure of FULLTEXT indexes has been changed in MySQL 5.1.6. After upgrading to MySQL 5.1.6 or greater, any tables that have FULLTEXT indexes must be repaired with REPAIR TABLE:

    REPAIR TABLE tbl_name QUICK;
    
  • Incompatible change: In MySQL 5.1.6, when log tables were implemented, the default log destination for the general query and slow query log was TABLE. As of MySQL 5.1.21, this default has been changed to FILE, which is compatible with MySQL 5.0, but incompatible with earlier releases of MySQL 5.1. If you are upgrading from MySQL 5.0 to 5.1.21 or higher, no logging option changes should be necessary. However, if you are upgrading from 5.1.6 through 5.1.20 to 5.1.21 or higher and were using TABLE logging, use the --log-output=TABLE option explicitly to preserve your server's table-logging behavior.

  • Incompatible change: In very old versions of MySQL (prior to 4.1), the TIMESTAMP data type supported a display width, which was silently ignored beginning with MySQL 4.1. This is deprecated in MySQL 5.1, and removed altogether in MySQL 5.5. These changes in behavior can lead to two problem scenarios when trying to use TIMESTAMP(N) columns with a MySQL 5.5 or later server:

    • When importing a dump file (for example, one created using mysqldump) created in a MySQL 5.0 or earlier server into a server from a newer release series, a CREATE TABLE or ALTER TABLE statement containing TIMESTAMP(N) causes the import to fail with a syntax error.

      To fix this problem, edit the dump file in a text editor to replace any instances of TIMESTAMP(N) with TIMESTAMP prior to importing the file. Be sure to use a plain text editor for this, and not a word processor; otherwise, the result is almost certain to be unusable for importing into the MySQL server.

    You should try to handle potential issues of these types proactively by updating with ALTER TABLE any TIMESTAMP(N) columns in your databases so that they use TIMESTAMP instead, before performing any upgrades.

  • Incompatible change: For ENUM columns that had enumeration values containing commas, the commas were mapped to 0xff internally. However, this rendered the commas indistinguishable from true 0xff characters in the values. This no longer occurs. However, the fix requires that you dump and reload any tables that have ENUM columns containing true 0xff in their values: Dump the tables using mysqldump with the current server before upgrading from a version of MySQL 5.1 older than 5.1.15 to version 5.1.15 or newer.

  • As of MySQL 5.1.12, the lc_time_names system variable specifies the locale that controls the language used to display day and month names and abbreviations. This variable affects the output from the DATE_FORMAT(), DAYNAME() and MONTHNAME() functions. See MySQL Server Locale Support.

  • As of MySQL 5.1.9, mysqld_safe no longer implicitly invokes mysqld-max if it exists. Instead, it invokes mysqld unless a --mysqld or --mysqld-version option is given to specify another server explicitly. If you previously relied on the implicit invocation of mysqld-max, you should use an appropriate option now. As of MySQL 5.1.12, there is no longer any separate mysqld-max server, so no change should be necessary.

SQL Changes

  • Known issue: Prior to MySQL 5.1.17, the parser accepted invalid code in SQL condition handlers, leading to server crashes or unexpected execution behavior in stored programs. Specifically, the parser permitted a condition handler to refer to labels for blocks that enclose the handler declaration. This was incorrect because block label scope does not include the code for handlers declared within the labeled block.

    As of 5.1.17, the parser rejects this invalid construct, but if you perform a binary upgrade (without dumping and reloading your databases), existing handlers that contain the construct still are invalid and should be rewritten even if they appear to function as you expect.

    To find affected handlers, use mysqldump to dump all stored procedures and functions, triggers, and events. Then attempt to reload them into an upgraded server. Handlers that contain illegal label references will be rejected.

    For more information about condition handlers and writing them to avoid invalid jumps, see DECLARE ... HANDLER Syntax.

  • Incompatible change: The parser accepted statements that contained /* ... */ that were not properly closed with */, such as SELECT 1 /* + 2. As of MySQL 5.1.23, statements that contain unclosed /*-comments now are rejected with a syntax error.

    This fix has the potential to cause incompatibilities. Because of Bug #26302, which caused the trailing */ to be truncated from comments in views, stored routines, triggers, and events, it is possible that objects of those types may have been stored with definitions that now will be rejected as syntactically invalid. Such objects should be dropped and re-created so that their definitions do not contain truncated comments.

  • Incompatible change: Multiple-table DELETE statements containing ambiguous aliases could have unintended side effects such as deleting rows from the wrong table. Examples:

    DELETE FROM t1 AS a2 USING t1 AS a1 INNER JOIN t2 AS a2;
    DELETE t1 AS a2 FROM t1 AS a1 INNER JOIN t2 AS a2;
    

    To avoid ambiguity, declaration of aliases other than in the table_references part of the statement should be avoided:

    DELETE FROM t1 USING t1 AS a1 INNER JOIN t2 AS a2;
    DELETE t1 FROM t1 AS a1 INNER JOIN t2 AS a2;
    

    As of MySQL 5.1.23, alias declarations outside the table_references part of the statement are disallowed for the USING variant of multiple-table DELETE syntax. (In MySQL 5.5, alias declarations outside table_references are disallowed for all multiple-table DELETE statements.) Statements containing aliases that are no longer permitted must be rewritten.

  • Incompatible change: As of MySQL 5.1.8, TYPE = engine_name is still accepted as a synonym for the ENGINE = engine_name table option but generates a warning. You should note that this option is not available in MySQL 5.1.7, and is removed altogether in MySQL 5.5 and produces a syntax error.

    TYPE has been deprecated since MySQL 4.0.

  • Incompatible change: MySQL 5.1.6 introduces the TRIGGER privilege. Previously, the SUPER privilege was needed to create or drop triggers. Now those operations require the TRIGGER privilege. This is a security improvement because you no longer need to grant users the SUPER privilege to enable them to create triggers. However, the requirement that the account named in a trigger's DEFINER clause must have the SUPER privilege has changed to a requirement for the TRIGGER privilege. When upgrading from a previous version of MySQL 5.0 or 5.1 to MySQL 5.1.6 or newer, be sure to update your grant tables by running mysql_upgrade. This will assign the TRIGGER privilege to all accounts that had the SUPER privilege. If you fail to update the grant tables, triggers may fail when activated. After updating the grant tables, you can revoke the SUPER privilege from those accounts that no longer otherwise require it.

  • Some keywords may be reserved in MySQL 5.1 that were not reserved in MySQL 5.0. See Keywords and Reserved Words.

  • The BACKUP TABLE, and RESTORE TABLE statements are deprecated. mysqldump or mysqlhotcopy can be used as alternatives.

  • The LOAD DATA FROM MASTER and LOAD TABLE FROM MASTER statements are deprecated. See LOAD DATA FROM MASTER Syntax, for recommended alternatives.

  • The INSTALL PLUGIN and UNINSTALL PLUGIN statements that are used for the plugin API are new. So is the WITH PARSER clause for FULLTEXT index creation that associates a parser plugin with a full-text index. The MySQL Plugin API.

SC API Changes

  • Incompatible change: As of MySQL 5.1.7, the mysql_stmt_attr_get() C API function returns a boolean rather than an unsigned int for STMT_ATTR_UPDATE_MAX_LENGTH. (Bug #16144)

11.2 Downgrading MySQL

This section describes how to downgrade to an older MySQL version.

Supported Downgrade Methods

Supported downgrade methods include:

  • In-place Downgrade: Involves shutting down the new MySQL version, replacing the new MySQL binaries or packages with the old ones, and restarting the old MySQL version on the new data files. In-place downgrades are supported for downgrades between GA versions within the same release series. For example, in-place downgrades are supported for downgrades from 5.1.73 to 5.1.72.

  • Logical Downgrade: Involves using mysqldump to dump all tables from the new MySQL version, and then loading the dump file into the old MySQL version. Logical downgrades are supported for downgrades between GA versions within the same release series and for downgrades between release levels. For example, logical downgrades are supported for downgrades from 5.1.73 to 5.1.72 and for downgrades from 5.1 to 5.0.

Supported Downgrade Paths

Unless otherwise documented, the following downgrade paths are supported:

  • Downgrading from a release series version to an older release series version is supported using all downgrade methods. For example, downgrading from 5.1.73 to 5.1.72 is supported. Skipping release series versions is also supported. For example, downgrading from 5.1.73 to 5.1.71 is supported.

  • Downgrading one release level is supported using the logical downgrade method. For example, downgrading from 5.1 to 5.0 is supported.

  • Downgrading more than one release level is supported using the logical downgrade method, but only if you downgrade one release level at a time. For example, you can downgrade from 5.1 to 5.0, and then to 4.1.

The following conditions apply to all downgrade paths:

  • Downgrades between General Availability (GA) status releases are supported.

  • Downgrades between milestone releases (or from a GA release to a milestone release) are not supported.

Before You Begin

Before downgrading, the following steps are recommended:

  • Review the Release Notes for the MySQL version you are downgrading from to ensure that there are no features or fixes that you really need.

  • Review Section 11.2.1, “Changes Affecting Downgrades from MySQL 5.1”. This section describes changes that may require action before or after downgrading.

    Note

    The downgrade procedures described in the following sections assume you are downgrading with data files created or modified by the newer MySQL version. However, if you did not modify your data after upgrading, downgrading using backups taken before upgrading to the new MySQL version is recommended. Many of the changes described in Section 11.2.1, “Changes Affecting Downgrades from MySQL 5.1” that require action before or after downgrading are not applicable when downgrading using backups taken before upgrading to the new MySQL version.

  • Always back up your current databases and log files before downgrading. The backup should include the mysql database, which contains the MySQL system tables. See Database Backup Methods.

  • Use of new features, new configuration options, or new configuration option values that are not supported by a previous release may cause downgrade errors or failures. Before downgrading, it is recommended that you reverse changes resulting from the use of new features and remove configuration settings that are not supported by the release you are downgrading to.

  • Check Section 11.3, “Checking Whether Tables or Indexes Must Be Rebuilt”, to see whether changes to table formats or to character sets or collations were made between your current version of MySQL and the version to which you are downgrading. If such changes have resulted in an incompatibility between MySQL versions, downgrade the affected tables using the instructions in Section 11.4, “Rebuilding or Repairing Tables or Indexes”.

  • If you use XA transactions with InnoDB, run XA RECOVER before downgrading to check for uncommitted XA transactions. If results are returned, either commit or rollback the XA transactions by issuing an XA COMMIT or XA ROLLBACK statement.

Performing an In-place Downgrade

In-place downgrades are supported for downgrades between GA status releases within the same release series. Review Before you Begin before proceeding.

To perform an in-place downgrade:

  1. Review the changes described in Section 11.2.1, “Changes Affecting Downgrades from MySQL 5.1” for steps to be performed before downgrading.

  2. If you use InnoDB, configure MySQL to perform a slow shutdown by setting innodb_fast_shutdown to 0. For example:

    shell> bin/mysql -u root -ppassword --execute="set global innodb_fast_shutdown=0"

    With a slow shutdown, InnoDB performs a full purge and change buffer merge before shutting down, which ensures that data files are fully prepared in case of file format differences between releases.

  3. Shut down the newer MySQL server. For example:

    shell> bin/mysqladmin -u root -ppassword shutdown
  4. Downgrade the MySQL binaries or packages in-place by replacing the newer binaries or packages with the older ones.

  5. Start the older (downgraded) MySQL server, using the existing data directory. For example:

    shell> bin/mysqld_safe --user=mysql --datadir=/path/to/existing-datadir
    
  6. Run mysql_upgrade. For example:

    shell> bin/mysql_upgrade -u root -ppassword

Performing a Logical Downgrade

Logical downgrades are supported for downgrades between releases within the same release series and for downgrades to the previous release level. Only downgrades between General Availability (GA) status releases are supported. Review Before you Begin before proceeding.

To perform a logical downgrade:

  1. Review the changes described in Section 11.2.1, “Changes Affecting Downgrades from MySQL 5.1” for steps to be performed before downgrading.

  2. Dump all databases. For example:

    shell> bin/mysqldump --add-drop-table --skip-events -u root -ppassword --all-databases --force > all_5_1_databases_dump.sql
  3. Shut down the newer MySQL server. For example:

    shell> bin/mysqladmin -u root -ppassword shutdown
  4. Initialize an older MySQL instance, with a new data directory. For example:

    shell> scripts/mysql_install_db --user=mysql
  5. Start the older MySQL server, using the new data directory. For example:

    shell> bin/mysqld_safe --user=mysql --datadir=/path/to/new-datadir
    
  6. Load the dump file into the older MySQL server. For example:

    shell> bin/mysql -u root -ppassword --execute="source all_5_1_databases_dump.sql" --force
  7. Run mysql_upgrade. For example:

    shell> bin/mysql_upgrade -u root -ppassword
  8. If you use InnoDB, configure MySQL to perform a slow shutdown by setting innodb_fast_shutdown to 0. For example:

    shell> bin/mysql -u root -ppassword --execute="set global innodb_fast_shutdown=0"
  9. Shut down and restart the MySQL server to ensure a clean shutdown and startup. For example:

    shell> bin/mysqladmin -u root -ppassword shutdown
    shell> bin/mysqld_safe --user=mysql --datadir=/path/to/new-datadir
    

Downgrade Troubleshooting

If you downgrade from one release series to another, there may be incompatibilities in table storage formats. In this case, use mysqldump to dump your tables before downgrading. After downgrading, reload the dump file using mysql or mysqlimport to re-create your tables. For examples, see Section 11.5, “Copying MySQL Databases to Another Machine”.

A typical symptom of a downward-incompatible table format change when you downgrade is that you cannot open tables. In that case, use the following procedure:

  1. Stop the older MySQL server that you are downgrading to.

  2. Restart the newer MySQL server you are downgrading from.

  3. Dump any tables that were inaccessible to the older server by using mysqldump to create a dump file.

  4. Stop the newer MySQL server and restart the older one.

  5. Reload the dump file into the older server. Your tables should be accessible.

11.2.1 Changes Affecting Downgrades from MySQL 5.1

Before downgrading from MySQL 5.1, review the changes described in this section. Some changes may require action before or after downgrading.

  • Partitioning.  MySQL 5.0 does not support user-defined partitioning. If a table was created as a partitioned table in 5.1 (or if an table created in a previous version of MySQL was altered to include partitions after an upgrade to 5.1), the table is accessible after downgrade only if you do one of the following:

    • Export the table using mysqldump and then drop it in MySQL 5.1; import the table again following the downgrade to MySQL 5.0.

    • Prior to the downgrade, remove the table's partitioning using ALTER TABLE table_name REMOVE PARTITIONING.

  • Event Scheduler.  MySQL 5.0 does not support scheduled events. If your databases contain scheduled event definitions, you should prevent them from being dumped when you use mysqldump by using the --skip-events option. (See mysqldump — A Database Backup Program.)

  • Stored routines.  MySQL 5.1.21 added a number of new columns to the mysql.proc table in which stored routine definitions are stored. If you are downgrading from MySQL 5.1.21 or later to MySQL 5.0, you cannot import the MySQL 5.1 routine definitions into MySQL 5.0.46 or earlier using the dump of mysql.proc created by mysqldump (such as when using the --all-databases option). Instead, you should run mysqldump --routines prior to performing the downgrade and run the stored routines DDL statements following the downgrade.

    See Bug #11986, Bug #30029, and Bug #30660, for more information.

  • Triggers.  Trigger creation requires the TRIGGER privilege as of MySQL 5.1. In MySQL 5.0, there is no TRIGGER privilege and SUPER is required instead. If you downgrade from MySQL 5.1 to 5.0, you will need to give the SUPER privilege to those accounts that had the TRIGGER privilege in 5.1.

11.2.2 Downgrading from MySQL Enterprise Edition to MySQL Community Server

This section describes the steps required to downgrade from MySQL Enterprise Edition to MySQL Community Edition. This can be done at any time, and is required at the expiration of a MySQL Enterprise Edition subscription if you wish to continue using MySQL Server.

When you perform such a downgrade, all commercially licensed components of the MySQL Enterprise Edition subscription must be uninstalled. These components and related considerations are described in the rest of this section.

Note

The issues described in this section are in addition to any that may be encountered as a result of any upgrade or downgrade of the MySQL Server version (such as between MySQL 5.1 and 5.0). Information about upgrading and downgrading between MySQL release series can be found elsewhere in this chapter; see Section 11.1, “Upgrading MySQL”, and Section 11.2, “Downgrading MySQL”.

MySQL Enterprise Database Server.  All commercial versions of MySQL Database Server must be uninstalled.

Commercially licensed extensions.  All commercially licensed MySQL Enterprise Database Server extensions must be uninstalled, including the MySQL High Availability extension. Following uninstallation of this extension, automated failover is no longer available.

MySQL Enterprise Backup.  MySQL Enterprise Backup must be uninstalled. Uninstalling this application has the effects listed here:

  • Automated backup scripts no longer work.

  • Existing backup images taken with MySQL Enterprise Backup can no longer be used for recovery.

  • Third-party integration with multimedia systems such as NetBackup, Tivoli, and Oracle Secure Backup no longer works.

MySQL Enterprise Monitor, MySQL Query Analyzer, agents.  MySQL Enterprise Monitor, MySQL Query Analyzer, and all server-side agents must be uninstalled. Uninstalling these applications and agents has the following effects:

  • Automated SNMP and SMTP alerts no longer work.

  • All historical MySQL, OS monitoring, query, and performance metrics as well as all trending data are lost.

  • All environment-specific monitoring templates, custom advisors, graphs and scripts are also lost.

11.3 Checking Whether Tables or Indexes Must Be Rebuilt

A binary upgrade or downgrade is one that installs one version of MySQL in place over an existing version, without dumping and reloading tables:

  1. Stop the server for the existing version if it is running.

  2. Install a different version of MySQL. This is an upgrade if the new version is higher than the original version, a downgrade if the version is lower.

  3. Start the server for the new version.

In many cases, the tables from the previous version of MySQL can be used without problem by the new version. However, sometimes changes occur that require tables or table indexes to be rebuilt, as described in this section. If you have tables that are affected by any of the issues described here, rebuild the tables or indexes as necessary using the instructions given in Section 11.4, “Rebuilding or Repairing Tables or Indexes”.

Table Incompatibilities

After a binary upgrade to MySQL 5.1 from a MySQL 5.0 installation that contains ARCHIVE tables:

  • Before MySQL 5.1.42, accessing those tables will cause the server to crash, even if you have run mysql_upgrade or CHECK TABLE ... FOR UPGRADE.

  • As of MySQL 5.1.42, the server will not open 5.0 ARCHIVE tables at all.

In either case, the solution is to use mysqldump to dump all 5.0 ARCHIVE tables before upgrading, and reload them into MySQL 5.1 after upgrading. This problem is fixed in MySQL 5.6.4: The server can open ARCHIVE tables created in MySQL 5.0. However, it remains the recommended upgrade procedure to dump 5.0 ARCHIVE tables before upgrading and reload them after upgrading.

Index Incompatibilities

If you perform a binary upgrade without dumping and reloading tables, you cannot upgrade directly from MySQL 4.1 to 5.1 or higher. This occurs due to an incompatible change in the MyISAM table index format in MySQL 5.0. Upgrade from MySQL 4.1 to 5.0 and repair all MyISAM tables. Then upgrade from MySQL 5.0 to 5.1 and check and repair your tables.

Modifications to the handling of character sets or collations might change the character sort order, which causes the ordering of entries in any index that uses an affected character set or collation to be incorrect. Such changes result in several possible problems:

  • Comparison results that differ from previous results

  • Inability to find some index values due to misordered index entries

  • Misordered ORDER BY results

  • Tables that CHECK TABLE reports as being in need of repair

The solution to these problems is to rebuild any indexes that use an affected character set or collation, either by dropping and re-creating the indexes, or by dumping and reloading the entire table. In some cases, it is possible to alter affected columns to use a different collation. For information about rebuilding indexes, see Section 11.4, “Rebuilding or Repairing Tables or Indexes”.

To check whether a table has indexes that must be rebuilt, consult the following list. It indicates which versions of MySQL introduced character set or collation changes that require indexes to be rebuilt. Each entry indicates the version in which the change occurred and the character sets or collations that the change affects. If the change is associated with a particular bug report, the bug number is given.

The list applies both for binary upgrades and downgrades. For example, Bug #27877 was fixed in MySQL 5.1.24, so it applies to upgrades from versions older than 5.1.24 to 5.1.24 or newer, and to downgrades from 5.1.24 or newer to versions older than 5.1.24.

In many cases, you can use CHECK TABLE ... FOR UPGRADE to identify tables for which index rebuilding is required. It will report this message:

Table upgrade required.
Please do "REPAIR TABLE `tbl_name`" or dump/reload to fix it!

In these cases, you can also use mysqlcheck --check-upgrade or mysql_upgrade, which execute CHECK TABLE. However, the use of CHECK TABLE applies only after upgrades, not downgrades. Also, CHECK TABLE is not applicable to all storage engines. For details about which storage engines CHECK TABLE supports, see CHECK TABLE Syntax.

These changes cause index rebuilding to be necessary:

  • MySQL 5.1.24 (Bug #27877)

    Affects indexes that use the utf8_general_ci or ucs2_general_ci collation for columns that contain 'ß' LATIN SMALL LETTER SHARP S (German). The bug fix corrected an error in the original collations but introduced an incompatibility such that 'ß' compares equal to characters with which it previously compared different.

    Affected tables can be detected by CHECK TABLE ... FOR UPGRADE as of MySQL 5.1.30 (see Bug #40053).

    A workaround for this issue is implemented as of MySQL 5.1.62, 5.5.21, and 5.6.5. The workaround involves altering affected columns to use the utf8_general_mysql500_ci and ucs2_general_mysql500_ci collations, which preserve the original pre-5.1.24 ordering of utf8_general_ci and ucs2_general_ci.

  • MySQL 5.0.48, 5.1.23 (Bug #27562)

    Affects indexes that use the ascii_general_ci collation for columns that contain any of these characters: '`' GRAVE ACCENT, '[' LEFT SQUARE BRACKET, '\' REVERSE SOLIDUS, ']' RIGHT SQUARE BRACKET, '~' TILDE

    Affected tables can be detected by CHECK TABLE ... FOR UPGRADE as of MySQL 5.1.29 (see Bug #39585).

  • MySQL 5.0.48, 5.1.21 (Bug #29461)

    Affects indexes for columns that use any of these character sets: eucjpms, euc_kr, gb2312, latin7, macce, ujis

    Affected tables can be detected by CHECK TABLE ... FOR UPGRADE as of MySQL 5.1.29 (see Bug #39585).

11.4 Rebuilding or Repairing Tables or Indexes

This section describes how to rebuild a table. This can be necessitated by changes to MySQL such as how data types are handled or changes to character set handling. For example, an error in a collation might have been corrected, necessitating a table rebuild to update the indexes for character columns that use the collation. (For examples, see Section 11.3, “Checking Whether Tables or Indexes Must Be Rebuilt”.) It might also be that a table repair or upgrade should be done as indicated by a table check operation such as that performed by CHECK TABLE, mysqlcheck, or mysql_upgrade.

Methods for rebuilding a table include dumping and reloading it, or using ALTER TABLE or REPAIR TABLE.

Note

If you are rebuilding tables because a different version of MySQL will not handle them after a binary (in-place) upgrade or downgrade, you must use the dump-and-reload method. Dump the tables before upgrading or downgrading using your original version of MySQL. Then reload the tables after upgrading or downgrading.

If you use the dump-and-reload method of rebuilding tables only for the purpose of rebuilding indexes, you can perform the dump either before or after upgrading or downgrading. Reloading still must be done afterward.

To rebuild a table by dumping and reloading it, use mysqldump to create a dump file and mysql to reload the file:

shell> mysqldump db_name t1 > dump.sql
shell> mysql db_name < dump.sql

To rebuild all the tables in a single database, specify the database name without any following table name:

shell> mysqldump db_name > dump.sql
shell> mysql db_name < dump.sql

To rebuild all tables in all databases, use the --all-databases option:

shell> mysqldump --all-databases > dump.sql
shell> mysql < dump.sql

To rebuild a table with ALTER TABLE, use a null alteration; that is, an ALTER TABLE statement that changes the table to use the storage engine that it already has. For example, if t1 is a MyISAM table, use this statement:

mysql> ALTER TABLE t1 ENGINE = MyISAM;

If you are not sure which storage engine to specify in the ALTER TABLE statement, use SHOW CREATE TABLE to display the table definition.

If you must rebuild a table because a table checking operation indicates that the table is corrupt or needs an upgrade, you can use REPAIR TABLE if that statement supports the table's storage engine. For example, to repair a MyISAM table, use this statement:

mysql> REPAIR TABLE t1;

For storage engines such as InnoDB that REPAIR TABLE does not support, use mysqldump to create a dump file and mysql to reload the file, as described earlier.

For specifics about which storage engines REPAIR TABLE supports, see REPAIR TABLE Syntax.

mysqlcheck --repair provides command-line access to the REPAIR TABLE statement. This can be a more convenient means of repairing tables because you can use the --databases or --all-databases option to repair all tables in specific databases or all databases, respectively:

shell> mysqlcheck --repair --databases db_name ...
shell> mysqlcheck --repair --all-databases

For incompatibilities introduced in MySQL 5.1.24 by the fix for Bug #27877 that corrected the utf8_general_ci and ucs2_general_ci collations, a workaround is implemented as of MySQL 5.1.62, 5.5.21, and 5.6.5. Upgrade to one of those versions, then convert each affected table using one of the following methods. In each case, the workaround altering affected columns to use the utf8_general_mysql500_ci and ucs2_general_mysql500_ci collations, which preserve the original pre-5.1.24 ordering of utf8_general_ci and ucs2_general_ci.

  • To convert an affected table after a binary upgrade that leaves the table files in place, alter the table to use the new collation. Suppose that the table t1 contains one or more problematic utf8 columns. To convert the table at the table level, use a statement like this:

    ALTER TABLE t1
    CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_mysql500_ci;
    

    To apply the change on a column-specific basis, use a statement like this (be sure to repeat the column definition as originally specified except for the COLLATE clause):

    ALTER TABLE t1
    MODIFY c1 CHAR(N) CHARACTER SET utf8 COLLATE utf8_general_mysql500_ci;
    
  • To upgrade the table using a dump and reload procedure, dump the table using mysqldump, modify the CREATE TABLE statement in the dump file to use the new collation, and reload the table.

After making the appropriate changes, CHECK TABLE should report no error.

11.5 Copying MySQL Databases to Another Machine

You can copy the .frm, .MYI, and .MYD files for MyISAM tables between different architectures that support the same floating-point format. (MySQL takes care of any byte-swapping issues.) See The MyISAM Storage Engine.

In cases where you need to transfer databases between different architectures, you can use mysqldump to create a file containing SQL statements. You can then transfer the file to the other machine and feed it as input to the mysql client.

Use mysqldump --help to see what options are available.

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 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 these commands:

shell> mysqladmin create db_name
shell> mysqldump -h 'other_hostname' --compress db_name | mysql db_name

You can also store the dump in a file, transfer the file to the target machine, and then load the file into the database there. For example, you can dump a database to a compressed file on the source machine like this:

shell> mysqldump --quick db_name | gzip > db_name.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.gz | mysql db_name

You can also use mysqldump and mysqlimport to transfer the database. For large tables, this is much faster than simply using mysqldump. In the following commands, DUMPDIR represents the full path name of the directory you use to store the output from mysqldump.

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

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

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

shell> mysqladmin create db_name           # create database
shell> cat DUMPDIR/*.sql | mysql db_name   # create tables in database
shell> mysqlimport db_name DUMPDIR/*.txt   # load data into tables

Do not forget to copy the mysql database because that is where the grant tables are stored. You might have to run commands as the MySQL root user on the new machine until you have the mysql database in place.

After you import the mysql database on the new machine, execute mysqladmin flush-privileges so that the server reloads the grant table information.