Table of Contents
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.
This section describes how to upgrade to a new MySQL version.
In the following discussion, MySQL commands that must be run
using a MySQL account with administrative privileges include
-u on the command line
to specify the MySQL rootroot user. Commands that
require a password for root also include a
-p option. Because -p is
followed by no option value, such commands prompt for the
password. Type the password when prompted and press Enter.
SQL statements can be executed using the
mysql command-line client (connect as
root to ensure that you have the necessary
privileges).
Supported downgrade methods include:
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.
MySQL recommends a mysqldump upgrade when upgrading from a previous release. For example, use this method when upgrading from 5.1 to 5.5.
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.10, “Upgrading MySQL on Windows”.
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.5.45 to 5.5.46 is supported. Skipping release series versions is also supported. For example, upgrading from 5.5.44 to 5.5.46 is supported.
Upgrading one release level is supported. For example, upgrading from 5.1 to 5.5 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.1 release before upgrading to 5.5.
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 5.0 and wish to upgrade to a newer series, upgrade to MySQL 5.1 first before upgrading to MySQL 5.5, and so forth. For information on upgrading to MySQL 5.1 see the MySQL 5.1 Reference Manual.
Direct upgrades that skip a release level (for example, upgrading directly from MySQL 5.0 to 5.5) 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 example, upgrading from 5.5.7 to 5.5.8 is not supported, as 5.5.7 is not a GA status release.
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 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 system 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.5 or differ from those found in earlier MySQL releases. Some of these changes may result in incompatibilities.
Review Section 10.1.1, “Changes Affecting Upgrades to MySQL 5.5”. This section describes changes that may require action before or after upgrading.
Check Section 10.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 10.4, “Rebuilding or Repairing Tables or Indexes”.
If you use replication, review Upgrading a 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 MySQL language interfaces is
recommended whenever you install or upgrade to a new release
of MySQL. This applies to MySQL interfaces such as PHP
mysql extensions, the Perl
DBD::mysql module, and the Python
MySQLdb module.
This section describes how to perform an in-place upgrade. Review Before you Begin before proceeding.
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:
Review the changes described in Section 10.1.1, “Changes Affecting Upgrades to MySQL 5.5” for steps to be performed before upgrading.
If you use InnoDB, configure MySQL to
perform a slow shutdown by setting
innodb_fast_shutdown to
0. For example:
mysql -u root -p --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.
Shut down the old MySQL server. For example:
mysqladmin -u root -p shutdown
Upgrade the MySQL binaries or packages in place (replace the old binaries or packages with the new ones).
Start the MySQL 5.5 server, using the existing data directory. For example:
mysqld_safe --user=mysql --datadir=/path/to/existing-datadir
Run mysql_upgrade. For example:
mysql_upgrade -u root -p
mysql_upgrade examines all tables in all
databases for incompatibilities with the current version of
MySQL. mysql_upgrade also upgrades the
mysql system database so that you can take
advantage of new privileges or capabilities.
mysql_upgrade does not upgrade the contents of the help tables. For upgrade instructions, see Server-Side Help.
Shut down and restart the MySQL server to ensure that any changes made to the system tables take effect. For example:
mysqladmin -u root -p shutdown
mysqld_safe --user=mysql --datadir=/path/to/existing-datadir
This section describes how to perform a logical upgrade. Review Before you Begin before proceeding.
To perform a logical upgrade:
Review the changes described in Section 10.1.1, “Changes Affecting Upgrades to MySQL 5.5” for steps to be performed before upgrading.
Export your existing data from the previous MySQL version:
mysqldump -u root -p --add-drop-table --routines --events --all-databases --force > data-for-upgrade.sql
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.
Shut down the old MySQL server. For example:
mysqladmin -u root -p shutdown
Install MySQL 5.5. For installation instructions, see Chapter 1, Installing and Upgrading MySQL.
Initialize a new data directory, as described at Section 9.1, “Initializing the Data Directory”. For example:
scripts/mysql_install_db --user=mysql --datadir=/path/to/5.5-datadir
Start the MySQL 5.5 server, using the new data directory. For example:
mysqld_safe --user=mysql --datadir=/path/to/5.5-datadir
Load the previously created dump file into the new MySQL server. For example:
mysql -u root -p --force < data-for-upgrade.sql
Run mysql_upgrade. For example:
mysql_upgrade -u root -p
mysql_upgrade examines all tables in all
databases for incompatibilities with the current version of
MySQL. mysql_upgrade also upgrades the
mysql system database so that you can take
advantage of new privileges or capabilities.
mysql_upgrade does not upgrade the contents of the help tables. For upgrade instructions, see Server-Side Help.
Shut down and restart the MySQL server to ensure that any changes made to the system tables take effect. For example:
mysqladmin -u root -p shutdown
mysqld_safe --user=mysql --datadir=/path/to/5.5-datadir
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.
Before upgrading to MySQL 5.5, review the changes described in this section to identify upgrade issues that apply to your current MySQL installation and applications.
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 10.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.
Incompatible change: The
InnoDB Plugin is included in MySQL
5.5 releases. It becomes the built-in version
of InnoDB in MySQL Server, replacing the
version previously included as the built-in
InnoDB engine. InnoDB
Plugin is also available in MySQL 5.1 as of
5.1.38, but it is an optional storage engine that must be
enabled explicitly using two server options:
[mysqld] ignore-builtin-innodb plugin-load=innodb=ha_innodb_plugin.so
If you were using InnoDB Plugin in MySQL
5.1 by means of those options, you must remove them after an
upgrade to 5.5 or the server will fail to
start.
In addition, in InnoDB Plugin, the
innodb_file_io_threads system variable
has been removed and replaced with
innodb_read_io_threads and
innodb_write_io_threads. If
you upgrade from MySQL 5.1 to MySQL 5.5 and
previously explicitly set
innodb_file_io_threads at server startup,
you must change your configuration. Either remove any
reference to innodb_file_io_threads or
replace it with references to
innodb_read_io_threads and
innodb_write_io_threads.
Incompatible change: In
MySQL 5.5, the server includes a plugin
services interface that complements the plugin API. The
services interface enables server functionality to be
exposed as a “service” that plugins can access
through a function-call interface. The
libmysqlservices library provides access
to the available services and dynamic plugins now must be
linked against this library (use the
-lmysqlservices flag). For an example
showing how to configure for CMake, see
MySQL Services for Plugins.
On Linux systems, the libaio library may
be needed. Install it first, if it is not already present on
your system.
Known issue: As of MySQL
5.5.32, for new installations, the url
columns in the mysql database 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;
Incompatible change: As of
MySQL 5.5.3, due to work done for Bug #989,
FLUSH
TABLES is not permitted when there is an active
LOCK TABLES ...
READ. To provide a workaround for this
restriction, FLUSH
TABLES has a new variant,
FLUSH TABLES
, that enables tables to be flushed and locked
in a single operation. As a result of this change,
applications that previously used this statement sequence to
lock and flush tables will fail:
tbl_list WITH READ
LOCK
LOCK TABLEStbl_listREAD; FLUSH TABLEStbl_list;
Such applications should now use this statement instead:
FLUSH TABLES tbl_list WITH READ LOCK;
Incompatible change: As of
MySQL 5.5.7, the server requires that a new grant table,
proxies_priv, be present in the
mysql database. If you are upgrading to
5.5.7 from a previous MySQL release rather than performing a
new installation, the server will find that this table is
missing and exit during startup with the following message:
Table 'mysql.proxies_priv' doesn't exist
To create the proxies_priv table, start
the server with the
--skip-grant-tables option to
cause it to skip the normal grant table checks, then run
mysql_upgrade. For example:
mysqld --skip-grant-tables & mysql_upgrade
Then stop the server and restart it normally.
You can specify other options on the
mysqld command line if necessary.
Alternatively, if your installation is configured so that
the server normally reads options from an option file, use
the --defaults-file option
to specify the file (enter each command on a single line):
mysqld --defaults-file=/usr/local/mysql/etc/my.cnf --skip-grant-tables & mysql_upgrade
With the --skip-grant-tables
option, the server does no password or privilege checking,
so any client can connect and effectively have all
privileges. For additional security, use the
--skip-networking option as
well to prevent remote clients from connecting.
This problem is fixed in MySQL 5.5.8; the server treats a
missing proxies_priv table as
equivalent to an empty table. However, after starting the
server, you should still run
mysql_upgrade to create the table.
Incompatible change: As of
MySQL 5.5.7, InnoDB always uses the fast
truncation technique, equivalent to
DROP TABLE and
CREATE TABLE. It no longer
performs a row-by-row delete for tables with parent-child
foreign key relationships. TRUNCATE
TABLE returns an error for such tables. Modify
your SQL to issue DELETE FROM
for such
tables instead.
table_name
Incompatible change: Prior
to MySQL 5.5.7, 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:
mysqladmin flush-logs mvhost_name.err-oldbackup-directory
To avoid the preceding file-loss problem, no renaming occurs as of MySQL 5.5.7; 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:
mvhost_name.errhost_name.err-old mysqladmin flush-logs mvhost_name.err-oldbackup-directory
Incompatible change: As of
MySQL 5.5.6, handling of
CREATE
TABLE IF NOT EXISTS ... SELECT statements has been
changed for the case that the destination table already
exists:
Previously, for
CREATE
TABLE IF NOT EXISTS ... SELECT, MySQL produced
a warning that the table exists, but inserted the rows
and wrote the statement to the binary log anyway. By
contrast,
CREATE
TABLE ... SELECT (without IF NOT
EXISTS) failed with an error, but MySQL
inserted no rows and did not write the statement to the
binary log.
MySQL now handles both statements the same way when the
destination table exists, in that neither statement
inserts rows or is written to the binary log. The
difference between them is that MySQL produces a warning
when IF NOT EXISTS is present and an
error when it is not.
This change in handling of IF NOT EXISTS
results in an incompatibility for statement-based
replication from a MySQL 5.1 master with the original
behavior and a MySQL 5.5 slave with the new behavior.
Suppose that
CREATE
TABLE IF NOT EXISTS ... SELECT is executed on the
master and the destination table exists. The result is that
rows are inserted on the master but not on the slave.
(Row-based replication does not have this problem.)
To address this issue, statement-based binary logging for
CREATE
TABLE IF NOT EXISTS ... SELECT is changed in MySQL
5.1 as of 5.1.51:
If the destination table does not exist, there is no change: The statement is logged as is.
If the destination table does exist, the statement is
logged as the equivalent pair of
CREATE
TABLE IF NOT EXISTS and
INSERT
... SELECT statements. (If the
SELECT in the original
statement is preceded by IGNORE or
REPLACE, the
INSERT becomes
INSERT
IGNORE or
REPLACE, respectively.)
This change provides forward compatibility for statement-based replication from MySQL 5.1 to 5.5 because when the destination table exists, the rows will be inserted on both the master and slave. To take advantage of this compatibility measure, the 5.1 server must be at least 5.1.51 and the 5.5 server must be at least 5.5.6.
To upgrade an existing 5.1-to-5.5 replication scenario, upgrade the master first to 5.1.51 or higher. Note that this differs from the usual replication upgrade advice of upgrading the slave first.
A workaround for applications that wish to achieve the
original effect (rows inserted regardless of whether the
destination table exists) is to use
CREATE
TABLE IF NOT EXISTS and
INSERT ...
SELECT statements rather than
CREATE
TABLE IF NOT EXISTS ... SELECT statements.
Along with the change just described, the following related
change was made: Previously, if an existing view was named
as the destination table for
CREATE
TABLE IF NOT EXISTS ... SELECT, rows were inserted
into the underlying base table and the statement was written
to the binary log. As of MySQL 5.1.51 and 5.5.6, nothing is
inserted or logged.
Incompatible change: Prior
to MySQL 5.5.6, if the server was started with
character_set_server set to
utf16, it crashed during full-text
stopword initialization. Now the stopword file is loaded and
searched using latin1 if
character_set_server is
ucs2, utf16, or
utf32. If any table was created with
FULLTEXT indexes while the server
character set was ucs2,
utf16, or utf32, it
should be repaired using this statement:
REPAIR TABLE tbl_name QUICK;
Incompatible change: As of
MySQL 5.5.5, all numeric operators and functions on integer,
floating-point and DECIMAL
values throw an “out of range” error
(ER_DATA_OUT_OF_RANGE)
rather than returning an incorrect value or
NULL, when the result is out of the
supported range for the corresponding data type. See
Out-of-Range and Overflow Handling.
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(
columns with a MySQL 5.5 or later server:
N)
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(
causes the import to fail with a syntax error.
N)
To fix this problem, edit the dump file in a text editor
to replace any instances of
TIMESTAMP(
with N)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.
When trying replicate any CREATE
TABLE or ALTER
TABLE statement containing
TIMESTAMP(
from a master MySQL server that supports the
N)TIMESTAMP(
syntax to a MySQL 5.5.3 or higher slave, the statement
causes replication to fail. Similarly, when you try to
restore from a binary log written by a server that
supports
N)TIMESTAMP(
to a MySQL 5.5.3 or higher server, any
N)CREATE TABLE or
ALTER TABLE statement
containing
TIMESTAMP(
causes the backup to fail. This holds true regardless of
the logging format.
N)
It may be possible to fix such issues using a hex
editor, by replacing any width arguments used with
TIMESTAMP, and the
parentheses containing them, with space characters
(hexadecimal 20).
Be sure to use a programmer's binary hex editor and
not a regular text editor or word processor for this;
otherwise, the result is almost certain to be a
corrupted binary log file. To guard against accidental
corruption of the binary log, you should always work on
a copy of the file rather than the original.
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: As of MySQL 5.5.3, the Unicode implementation has been extended to provide support for supplementary characters that lie outside the Basic Multilingual Plane (BMP). Noteworthy features:
utf16 and utf32
character sets have been added. These correspond to the
UTF-16 and UTF-32 encodings of the Unicode character
set, and they both support supplementary characters.
The utf8mb4 character set has been
added. This is similar to utf8, but
its encoding allows up to four bytes per character to
enable support for supplementary characters.
The ucs2 character set is essentially
unchanged except for the inclusion of some newer BMP
characters.
In most respects, upgrading to MySQL 5.5 should present few problems with regard to Unicode usage, although there are some potential areas of incompatibility. These are the primary areas of concern:
For the variable-length character data types
(VARCHAR and the
TEXT types), the maximum
length in characters is less for
utf8mb4 columns than for
utf8 columns.
For all character data types
(CHAR,
VARCHAR, and the
TEXT types), the maximum
number of characters that can be indexed is less for
utf8mb4 columns than for
utf8 columns.
Consequently, if you want to upgrade tables from
utf8 to utf8mb4 to
take advantage of supplementary-character support, it may be
necessary to change some column or index definitions.
For additional details about the new Unicode character sets and potential incompatibilities, see Unicode Support, and Converting Between 3-Byte and 4-Byte Unicode Character Sets.
Incompatible change: As of
MySQL 5.5.3, the server includes dtoa, a
library for conversion between strings and numbers by David
M. Gay. In MySQL, this library provides the basis for
improved conversion between string or
DECIMAL values and
approximate-value (FLOAT or
DOUBLE) numbers.
Because the conversions produced by this library differ in some cases from previous results, the potential exists for incompatibilities in applications that rely on previous results. For example, applications that depend on a specific exact result from previous conversions might need adjustment to accommodate additional precision.
For additional information about the properties of
dtoa conversions, see
Type Conversion in Expression Evaluation.
Incompatible change: In MySQL 5.5, several changes were made regarding the language and character set of error messages:
The --language option for
specifying the directory for the error message file is
now deprecated. The new
lc_messages_dir and
lc_messages system
variables should be used instead, and the server treats
--language as an alias
for lc_messages_dir.
The language system
variable has been removed and replaced with the new
lc_messages_dir and
lc_messages system
variables.
lc_messages_dir has
only a global value and is read only.
lc_messages has global
and session values and can be modified at runtime, so
the error message language can be changed while the
server is running, and individual clients each can have
a different error message language by changing their
session lc_messages
value to a different locale name.
Error messages previously were constructed in a mix of
character sets. This issue is resolved by constructing
error messages internally within the server using UTF-8
and returning them to the client in the character set
specified by the
character_set_results
system variable. The content of error messages therefore
may in some cases differ from the messages returned
previously.
For more information, see Setting the Error Message Language, and Error Message Character Set.
Incompatible change: MySQL
5.5 implements new functions used to calculate row placement
for tables partitioned by KEY and
LINEAR KEY. Tables that were created
using KEY or LINEAR
KEY partitioning in MySQL 5.1 can be upgraded in
MySQL 5.5.31 and later using
ALTER
TABLE ... PARTITION BY ALGORITHM=2 [LINEAR] KEY
(...). (Bug #14521864, Bug #66462)
Incompatible change:
Previously, the parser accepted an INTO
clause in nested SELECT
statements, which is invalid because such statements must
return their results to the outer context. As of MySQL
5.5.3, this syntax is no longer permitted and statements
that use it must be changed.
Incompatible change: In
MySQL 5.5.3, several changes were made to alias resolution
in multiple-table DELETE
statements so that it is no longer possible to have
inconsistent or ambiguous table aliases.
In MySQL 5.1.23, alias declarations outside the
table_references part of the
statement were disallowed for the
USING variant of multiple-table
DELETE syntax, to reduce
the possibility of ambiguous aliases that could lead to
ambiguous statements that have unexpected results such
as deleting rows from the wrong table.
As of MySQL 5.5.3, alias declarations outside
table_references are
disallowed for all multiple-table
DELETE statements. Alias
declarations are permitted only in the
table_references part.
Incorrect:
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;
Correct:
DELETE FROM t1 USING t1 AS a1 INNER JOIN t2 AS a2; DELETE t1 FROM t1 AS a1 INNER JOIN t2 AS a2;
Previously, for alias references in the list of tables
from which to delete rows in a multiple-table delete,
the default database is used unless one is specified
explicitly. For example, if the default database is
db1, the following statement does not
work because the unqualified alias reference
a2 is interpreted as having a
database of db1:
DELETE a1, a2 FROM db1.t1 AS a1 INNER JOIN db2.t2 AS a2 WHERE a1.id=a2.id;
To correctly match an alias that refers to a table outside the default database, you must explicitly qualify the reference with the name of the proper database:
DELETE a1, db2.a2 FROM db1.t1 AS a1 INNER JOIN db2.t2 AS a2 WHERE a1.id=a2.id;
As of MySQL 5.5.3, alias resolution does not require qualification and alias references should not be qualified with the database name. Qualified names are interpreted as referring to tables, not aliases.
Statements containing alias constructs that are no longer permitted must be rewritten.
Some keywords may be reserved in MySQL 5.5 that were not reserved in MySQL 5.1. See Keywords and Reserved Words.
This section describes how to downgrade to an older MySQL version.
In the following discussion, MySQL commands that must be run
using a MySQL account with administrative privileges include
-u on the command line
to specify the MySQL rootroot user. Commands that
require a password for root also include a
-p option. Because -p is
followed by no option value, such commands prompt for the
password. Type the password when prompted and press Enter.
SQL statements can be executed using the
mysql command-line client (connect as
root to ensure that you have the necessary
privileges).
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.5.46 to 5.5.45.
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.5.46 to 5.5.45 and for downgrades from 5.5 to 5.1.
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.546 to 5.5.45 is supported. Skipping release series versions is also supported. For example, downgrading from 5.5.46 to 5.5.44 is supported.
Downgrading one release level is supported using the logical downgrade method. For example, downgrading from 5.5 to 5.1 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.5 to 5.1, and then to 5.0.
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. For example, downgrading from MySQL 5.5.8 to MySQL 5.5.7 is not supported, as 5.5.7 is not a GA status release.
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 10.2.1, “Changes Affecting Downgrades from MySQL 5.5”. This section describes changes that may require action before or after downgrading.
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 10.2.1, “Changes Affecting Downgrades from MySQL 5.5” 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 10.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 10.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.
In-place downgrades are supported for downgrades between GA status releases within the same release series. Before proceeding, review Before You Begin.
To perform an in-place downgrade:
Review the changes described in Section 10.2.1, “Changes Affecting Downgrades from MySQL 5.5” for steps to be performed before downgrading.
If you use InnoDB, configure MySQL to
perform a slow shutdown by setting
innodb_fast_shutdown to
0. For example:
mysql -u root -p --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.
Shut down the newer MySQL server. For example:
mysqladmin -u root -p shutdown
After the slow shutdown, remove the InnoDB
redo log files (the ib_logfile* files)
from the data directory to avoid
downgrade issues related to redo log file format changes that
may have occurred between releases.
rm ib_logfile*
Downgrade the MySQL binaries or packages in-place by replacing the newer binaries or packages with the older ones.
Start the older (downgraded) MySQL server, using the existing data directory. For example:
mysqld_safe --user=mysql --datadir=/path/to/existing-datadir
Run mysql_upgrade. For example:
mysql_upgrade -u root -p
Shut down and restart the MySQL server to ensure that any changes made to the system tables take effect. For example:
mysqladmin -u root -p shutdown
mysqld_safe --user=mysql --datadir=/path/to/existing-datadir
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. Before proceeding, review Before You Begin.
To perform a logical downgrade:
Review the changes described in Section 10.2.1, “Changes Affecting Downgrades from MySQL 5.5” for steps to be performed before downgrading.
Dump all databases. For example:
mysqldump -u root -p --add-drop-table --routines --events --all-databases --force > data-for-downgrade.sql
Shut down the newer MySQL server. For example:
mysqladmin -u root -p shutdown
Initialize an older MySQL instance, with a new data directory. For example:
scripts/mysql_install_db --user=mysql
Start the older MySQL server, using the new data directory. For example:
mysqld_safe --user=mysql --datadir=/path/to/new-datadir
Load the dump file into the older MySQL server. For example:
mysql -u root -p --force < data-for-upgrade.sql
Run mysql_upgrade. For example:
mysql_upgrade -u root -p
Shut down and restart the MySQL server to ensure that any changes made to the system tables take effect. For example:
mysqladmin -u root -p shutdown
mysqld_safe --user=mysql --datadir=/path/to/new-datadir
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 10.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:
Stop the older MySQL server that you are downgrading to.
Restart the newer MySQL server you are downgrading from.
Dump any tables that were inaccessible to the older server by using mysqldump to create a dump file.
Stop the newer MySQL server and restart the older one.
Reload the dump file into the older server. Your tables should be accessible.
Before downgrading from MySQL 5.5, review the changes described in this section. Some changes may require action before or after downgrading.
System Tables.
The mysql.proc.comment column
definition changed between MySQL 5.1 and 5.5. After
downgrading from 5.5 to 5.1, this table is seen as corrupt
and in need of repair. Running
mysql_upgrade from the version of MySQL
to which you downgraded (as documented in the downgrade
procedures) reverts the
mysql.proc.comment column definition.
InnoDB.
MySQL 5.5 uses InnoDB Plugin as the
built-in version of InnoDB. MySQL
5.1 includes InnoDB
Plugin as of 5.1.38, but as an option that must
be enabled explicitly. See the
Release
Notes for MySQL 5.1.38.
Tables partitioned by [LINEAR] KEY.
MySQL 5.5 implements new functions used to calculate row
placement for tables partitioned by KEY
and LINEAR KEY. Tables that were
created using KEY or LINEAR
KEY partitioning in MySQL 5.5 cannot be used by
a MySQL 5.1 server. In MySQL 5.5.31 and later, you can
downgrade such tables with
ALTER
TABLE ... PARTITION BY ALGORITHM=1 [LINEAR] KEY
(...) to make them compatible with MySQL 5.1.
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.
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.5 and 5.1). Information about upgrading and downgrading between MySQL release series can be found elsewhere in this chapter; see Section 10.1, “Upgrading MySQL”, and Section 10.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. This includes the following commercial extensions:
MySQL External Authentication for Windows: Following uninstallation of this plugin, existing MySQL user accounts must be re-created using local authentication. See MySQL User Account Management, for more information.
MySQL External Authentication for PAM: Following uninstallation of this plugin, existing MySQL user accounts must be re-created using local authentication. See MySQL User Account Management, for more information.
MySQL Enterprise Thread Pool: Following uninstallation of this plugin, existing MySQL servers revert to default thread and connection handling.
MySQL Enterprise Audit: Following uninstallation of this plugin, no logging of user logins or query activity occurs.
MySQL High Availability: Following uninstallation of this plugin, 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.
A binary upgrade or downgrade is one that installs one version of MySQL “in place” over an existing version, without dumping and reloading tables:
Stop the server for the existing version if it is running.
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.
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 10.4, “Rebuilding or Repairing Tables or Indexes”.
After a binary upgrade to MySQL 5.1 from a MySQL 5.0 installation
that contains ARCHIVE tables,
accessing those tables causes the server to crash, even if you
have run mysql_upgrade or
CHECK TABLE ... FOR
UPGRADE. To work around this problem, use
mysqldump to dump all
ARCHIVE tables before upgrading, and
reload them into MySQL 5.1 after upgrading. The same problem
occurs for binary downgrades from MySQL 5.1 to 5.0.
The upgrade 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.
In MySQL 5.6.3, the length limit for index prefix keys is
increased from 767 bytes to 3072 bytes, for
InnoDB tables using
ROW_FORMAT=DYNAMIC or
ROW_FORMAT=COMPRESSED. See
Limits on InnoDB Tables for details. This change is
also backported to MySQL 5.5.14. If you downgrade from one of
these releases or higher, to an earlier release with a lower
length limit, the index prefix keys could be truncated at 767
bytes or the downgrade could fail. This issue could only occur if
the configuration option
innodb_large_prefix was enabled
on the server being downgraded.
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 10.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 higher, 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).
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 10.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.
REPAIR TABLE only applies to
MyISAM, ARCHIVE, and
CSV tables.
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:
mysqldumpdb_namet1 > dump.sql mysqldb_name< dump.sql
To rebuild all the tables in a single database, specify the database name without any following table name:
mysqldumpdb_name> dump.sql mysqldb_name< dump.sql
To rebuild all tables in all databases, use the
--all-databases option:
mysqldump --all-databases > dump.sql 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 an
InnoDB table, use this statement:
ALTER TABLE t1 ENGINE = InnoDB;
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 need to rebuild an InnoDB table because
a CHECK TABLE operation indicates
that a table upgrade is required, use mysqldump
to create a dump file and mysql to reload the
file, as described earlier. If the CHECK
TABLE operation indicates that there is a corruption or
causes InnoDB to fail, refer to
Forcing InnoDB Recovery for information about
using the innodb_force_recovery
option to restart InnoDB. To understand the
type of problem that CHECK TABLE
may be encountering, refer to the InnoDB notes
in CHECK TABLE Syntax.
For MyISAM, ARCHIVE, or
CSV tables, you can use
REPAIR TABLE if the table checking
operation indicates that there is a corruption or that an upgrade
is required. For example, to repair a MyISAM
table, use this statement:
REPAIR TABLE t1;
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:
mysqlcheck --repair --databases db_name ...
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.
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.
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.
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:
mysqladmin -h 'other_hostname' createdb_namemysqldumpdb_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:
mysqladmin createdb_namemysqldump -h 'other_hostname' --compressdb_name| mysqldb_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:
mysqldump --quickdb_name| gzip >db_name.gz
Transfer the file containing the database contents to the target machine and run these commands there:
mysqladmin createdb_namegunzip <db_name.gz | mysqldb_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:
mkdirDUMPDIRmysqldump --tab=DUMPDIRdb_name
Then transfer the files in the DUMPDIR
directory to some corresponding directory on the target machine
and load the files into MySQL there:
mysqladmin createdb_name# create database catDUMPDIR/*.sql | mysqldb_name# create tables in database mysqlimportdb_nameDUMPDIR/*.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.