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.5 to 5.6.
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.8, “Upgrading MySQL on Windows”.
If your current MySQL installation was installed on an Enterprise Linux platform or Fedora using the MySQL Yum Repository, see Section 10.1.2, “Upgrading MySQL with the MySQL Yum Repository”.
If your current MySQL installation was installed on Ubuntu using the MySQL APT repository, see Section 10.1.3, “Upgrading MySQL with the MySQL APT Repository”.
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.6.26 to 5.6.27 is supported. Skipping release series versions is also supported. For example, upgrading from 5.6.25 to 5.6.27 is supported.
Upgrading one release level is supported. For example, upgrading from 5.5 to 5.6 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.5 release before upgrading to 5.6.
Upgrading more than one release level is supported, but only if you upgrade one release level at a time. For example, upgrade from 5.1 to 5.5, and then to 5.6. Follow the upgrade instructions for each release, in succession.
Direct upgrades that skip a release level (for example, upgrading directly from MySQL 5.1 to 5.6) 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.6.9 to 5.6.10 is not supported, as 5.6.9 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.6 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.6”. 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 interaces 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.6” 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.6 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 should not be used when the
server is running with
--gtid-mode=ON. See
GTID mode and mysql_upgrade
for more information.
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.6” 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.6. 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.6-datadir
Start the MySQL 5.6 server, using the new data directory. For example:
mysqld_safe --user=mysql --datadir=/path/to/5.6-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 should not be used when the
server is running with
--gtid-mode=ON. See
GTID mode and mysql_upgrade
for more information.
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.6-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.6, 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.
Beginning with MySQL 5.6.6, several MySQL Server parameters have defaults that differ from previous releases. See the notes regarding these changes under Configuration Changes, particularly regarding overriding them to preserve backward compatibility if that is a concern.
Beginning with MySQL 5.6.6, several MySQL Server parameters have defaults that differ from previous releases. The motivation for these changes is to provide better out-of-box performance and to reduce the need for the database administrator to change settings manually. These changes are subject to possible revision in future releases as we gain feedback.
In some cases, a parameter has a different static default
value. In other cases, the server autosizes a parameter at
startup using a formula based on other related parameters or
server host configuration, rather than using a static value.
For example, the setting for
back_log now is its
previous default of 50, adjusted up by an amount
proportional to the value of
max_connections. The idea
behind autosizing is that when the server has information
available to make a decision about a parameter setting
likely to be better than a fixed default, it will.
The following table summarizes changes to defaults. Any of these can be overridden by specifying an explicit value at server startup.
| Parameter | Old Default | New Default |
|---|---|---|
back_log | 50 | Autosized using max_connections |
binlog_checksum | NONE | CRC32 |
--binlog-row-event-max-size | 1024 | 8192 |
flush_time | 1800 (on Windows) | 0 |
innodb_autoextend_increment | 8 | 64 |
innodb_buffer_pool_instances | 1 | 8 (platform dependent) |
innodb_checksum_algorithm | INNODB | CRC32 (changed back to |
innodb_concurrency_tickets | 500 | 5000 |
innodb_file_per_table | 0 | 1 |
innodb_old_blocks_time | 0 | 1000 |
innodb_open_files | 300 | Autosized using innodb_file_per_table,
table_open_cache |
innodb_stats_on_metadata | ON | OFF |
join_buffer_size | 128KB | 256KB |
max_allowed_packet | 1MB | 4MB |
max_connect_errors | 10 | 100 |
sync_master_info | 0 | 10000 |
sync_relay_log | 0 | 10000 |
sync_relay_log_info | 0 | 10000 |
With regard to compatibility with previous releases, the most important changes are:
innodb_file_per_table
is enabled (previously disabled).
innodb_checksum_algorithm
is CRC32 (previously
INNODB and changed back to
INNODB in MySQL 5.6.7).
binlog_checksum is
CRC32 (previously
NONE).
Therefore, if you are upgrading an existing MySQL installation, have not already changed the values of these parameters from their previous defaults, and backward compatibility is a concern, you may want to explicitly set these parameters to their previous defaults. For example, put these lines in the server option file:
[mysqld] innodb_file_per_table=0 innodb_checksum_algorithm=INNODB binlog_checksum=NONE
Those settings preserve compatibility as follows:
With the new default of
innodb_file_per_table
enabled, ALTER TABLE
operations following an upgrade will move
InnoDB tables that are in
the system tablespace to individual
.ibd files. Using
innodb_file_per_table=0
will prevent this from happening.
Setting
innodb_checksum_algorithm=INNODB
permits binary downgrades after upgrading to this
release. With a setting of CRC32,
InnoDB would use checksumming that older MySQL versions
cannot use.
With
binlog_checksum=NONE,
the server can be used as a replication master without
causing failure of older slaves that do not understand
binary log checksums.
As of MySQL 5.6.5, pre-4.1 passwords and the
mysql_old_password authentication plugin
are deprecated. Passwords stored in the older hash format
used before MySQL 4.1 are less secure than passwords that
use the native password hashing method and should be
avoided. To prevent connections using accounts that have
pre-4.1 password hashes, the
secure_auth system variable
is now enabled by default. (To permit connections for
accounts that have such password hashes, start the server
with --secure_auth=0.)
DBAs are advised to convert accounts that use the
mysql_old_password authentication plugin
to use mysql_native_password instead. For
account upgrade instructions, see
Migrating Away from Pre-4.1 Password Hashing and the mysql_old_password Plugin.
Known issue: In some early
development versions of MySQL 5.6 (5.6.6 to 5.6.10), the
server could create accounts with a mismatched password hash
and authentication plugin. For example, if the default
authentication plugin is
mysql_native_password, this sequence of
statements results in an account with a plugin of
mysql_native_password but a pre-4.1
password hash (the format used by
mysql_old_password):
SET old_passwords = 1; CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';
The mismatch produces symptoms such as being unable to
connect to the MySQL server and being unable to use
SET PASSWORD with
OLD_PASSWORD() or with
old_passwords=1.
As of MySQL 5.6.11, this mismatch no longer occurs. Instead, the server produces an error:
mysql>SET old_passwords = 1;mysql>CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';ERROR 1827 (HY000): The password hash doesn't have the expected format. Check if the correct password algorithm is being used with the PASSWORD() function.
To deal with an account affected by a mismatch, the DBA can
modify either the plugin or
Password column in the account's
mysql.user table row to be consistent
with the other column:
Set old_passwords to 0,
then assign a new password to the account using
SET PASSWORD and
PASSWORD(). This sets the
Password column to have a 4.1
password hash, consistent with the
mysql_native_password plugin. This is
the preferred method of fixing the account.
Alternatively, the DBA can change the plugin to
mysql_old_password to make the plugin
match the password hash format, then flush the
privileges. This is not recommended because the
mysql_old_password plugin and pre-4.1
password hashing are deprecated and support for them
will be removed in a future version of MySQL.
Incompatible change: It is
possible for a column DEFAULT value to be
valid for the sql_mode
value at table-creation time but invalid for the
sql_mode value when rows
are inserted or updated. Example:
SET sql_mode = ''; CREATE TABLE t (d DATE DEFAULT 0); SET sql_mode = 'NO_ZERO_DATE,STRICT_ALL_TABLES'; INSERT INTO t (d) VALUES(DEFAULT);
In this case, 0 should be accepted for the
CREATE TABLE but rejected for
the INSERT. However, the
server did not evaluate DEFAULT values
used for inserts or updates against the current
sql_mode. In the example, the
INSERT succeeds and inserts
'0000-00-00' into the
DATE column.
As of MySQL 5.6.13, the server applies the proper
sql_mode checks to generate
a warning or error at insert or update time.
A resulting incompatibility for replication if you use
statement-based logging
(binlog_format=STATEMENT)
is that if a slave is upgraded, a nonupgraded master will
execute the preceding example without error, whereas the
INSERT will fail on the slave
and replication will stop.
To deal with this, stop all new statements on the master and
wait until the slaves catch up. Then upgrade the slaves
followed by the master. Alternatively, if you cannot stop
new statements, temporarily change to row-based logging on
the master
(binlog_format=ROW) and
wait until all slaves have processed all binary logs
produced up to the point of this change. Then upgrade the
slaves followed by the master and change the master back to
statement-based logging.
Incompatible change: MySQL
5.6.11 and later supports
CREATE
TABLE ... [SUB]PARTITION BY
ALGORITHM=, which can be used to create a table whose
n [LINEAR] KEY
(...)KEY partitioning is compatible with a
MySQL 5.1 server (n=1). (Bug
#14521864, Bug #66462) This syntax is not accepted by MySQL
5.6.10 and earlier, although it is supported in MySQL 5.5
beginning with MySQL 5.5.31. mysqldump in
MySQL 5.5.31 and later MySQL 5.5 releases includes the
ALGORITHM option when dumping tables
using this option, but surrounds it with conditional
comments, like this:
CREATE TABLE t1 (a INT)
/*!50100 PARTITION BY KEY */ /*!50531 ALGORITHM = 1 */ /*!50100 ()
PARTITIONS 3 */
When importing a dump containing such CREATE
TABLE statements into a MySQL 5.6.10 or earlier
MySQL 5.6 server, the versioned comment is not ignored,
which causes a syntax error. Therefore, prior to importing
such a dump file, you must either change the comments so
that the MySQL 5.6 server ignores them (by removing the
string !50531 or replacing it with
!50611, wherever it occurs), or remove
them.
This is not an issue with dump files made using MySQL 5.6.11
or later, where the ALGORITHM option is
written using /*!50611 ... */.
Incompatible change: For
TIME,
DATETIME, and
TIMESTAMP columns, the
storage required for tables created before MySQL 5.6.4
differs from storage required for tables created in 5.6.4
and later. This is due to a change in 5.6.4 that permits
these temporal types to have a fractional part. This change
can affect the output of statements that depend on the row
format, such as CHECKSUM
TABLE. After upgrading from MySQL 5.5 to MySQL
5.6.4 or later, it is recommended that you also upgrade from
MySQL 5.5 to MySQL 5.6 TIME,
DATETIME, and
TIMESTAMP types.
ALTER TABLE currently allows
the creation of tables containing temporal columns in both
MySQL 5.5 and MySQL 5.6.4 (or later) binary format but this
makes it more difficult to recreate tables in cases where
.frm files are not available.
Additionally, as of MySQL 5.6.4, the aforementioned temporal
types are more space efficient. For more information about
changes to temporal types in MySQL 5.6.4, see
Storage Requirements for Date and Time Types.
As of MySQL 5.6.16, ALTER
TABLE upgrades old temporal columns to 5.6 format
for ADD COLUMN, CHANGE
COLUMN, MODIFY COLUMN,
ADD INDEX, and FORCE
operations. Hence, the following statement upgrades a table
containing columns in the old format:
ALTER TABLE tbl_name FORCE;
This conversion cannot be done using the
INPLACE algorithm because the table must
be rebuilt, so specifying
ALGORITHM=INPLACE in these cases results
in an error. Specify ALGORITHM=COPY if
necessary.
When ALTER TABLE does produce
a temporal-format conversion, it generates a message that
can be displayed with SHOW
WARNINGS: TIME/TIMESTAMP/DATETIME columns
of old format have been upgraded to the new
format.
When upgrading to MySQL 5.6.4 or later, be aware that
CHECK TABLE ...
FOR UPGRADE does not report temporal columns that
use the pre-MySQL 5.6.4 format (Bug #73008, Bug #18985579).
In MySQL 5.6.24, two new system variables,
avoid_temporal_upgrade and
show_old_temporals, were
added to provide control over temporal column upgrades (Bug
#72997, Bug #18985760).
Due to the temporal type changes described in the previous
incompatible change item above, importing pre-MySQL 5.6.4
tables (using
ALTER TABLE ...
IMPORT TABLESPACE) that contain
DATETIME and
TIMESTAMP types into MySQL
5.6.4 (or later) fails. Importing a MySQL 5.5 table with
these temporal types into MySQL 5.6.4 (or later) is the
mostly likely scenario for this problem to occur.
The following procedures describe workarounds that use the
original pre-MySQL 5.6.4 .frm file to
recreate a table with a row structure that is compatible
with 5.6.4 (or later). The procedures involve changing the
original pre-MySQL 5.6.4 .frm file to
use the Memory storage engine
instead of InnoDB, copying the
.frm file to the data directory of the
destination instance, and using ALTER
TABLE to change the table's storage engine type
back to InnoDB. Use the first procedure
if your tables do not have foreign keys. Use the second
procedure, which has additional steps, if your table
includes foreign keys.
If the table does not have foreign keys:
Copy the table's original .frm file
to the data directory on the server where you want to
import the tablespace.
Modify the table's .frm file to use
the Memory storage engine instead of
the InnoDB storage engine. This
modification requires changing 7 bytes in the
.frm file that define the table's
storage engine type. Using a hexidecimal editing tool:
Change the byte at offset position 0003, which is
the legacy_db_type, from
“0c” (for
InnoDB) to
“06” (for
Memory), as shown below:
00000000 fe 01 09 06 03 00 00 10 01 00 00 30 00 00 10 00
The remaining 6 bytes do not have a fixed offset.
Search the .frm file for
“InnoDB” to locate
the line with the other 6 bytes. The line appears as
shown below:
00001010 ff 00 00 00 00 00 00 06 00 49 6e 6e 6f 44 42 00 |.........InnoDB.|
Modify the bytes so that the line appears as follows:
00001010 ff 00 00 00 00 00 00 06 00 4d 45 4d 4f 52 59 00
Run ALTER
TABLE ... ENGINE=INNODB to add the table
definition to the InnoDB data
dictionary. This creates the InnoDB
table with the temporal data types in the new format.
For the ALTER TABLE
operation to complete successfully, the
.frm file must correspond to the
tablespace.
Import the table using
ALTER TABLE
... IMPORT TABLESPACE.
If table has foreign keys:
Recreate the tables with foreign keys using table
definitions from SHOW CREATE
TABLE output. The incorrect temporal column
formats do not matter at this point.
Dump all foreign key definitions to a text file by
selecting the foreign key information from
INFORMATION_SCHEMA.TABLE_CONSTRAINTS
and
INFORMATION_SCHEMA.KEY_COLUMN_USAGE.
Drop all tables and complete the table import process described in steps 1 to 4 in the procedure described above for tables without foreign keys.
After the import operation is complete, add the foreign keys from foreign key definitions that you saved to a text file.
Incompatible change: As of
MySQL 5.6, the full-text stopword file is loaded and
searched using latin1 if
character_set_server is
ucs2, utf16,
utf16le, or utf32. If
any table was created with FULLTEXT
indexes while the server character set was
ucs2, utf16,
utf16le, or utf32,
repair it using this statement:
REPAIR TABLE tbl_name QUICK;
Incompatible change: In
MySQL 5.6.20, the patch for Bug #69477 limits the size of
redo log BLOB writes to 10%
of the redo log file size. As a result of this new limit,
innodb_log_file_size should
be set to a value greater than 10 times the largest
BLOB data size found in the
rows of your tables. No action is required if your
innodb_log_file_size
setting is already 10 times the largest
BLOB data size or your tables
contain no BLOB data.
In MySQL 5.6.22, the redo log
BLOB write limit is relaxed
to 10% of the total redo log size
(innodb_log_file_size *
innodb_log_files_in_group).
(Bug #19498877)
Some keywords may be reserved in MySQL 5.6 that were not reserved in MySQL 5.5. See Keywords and Reserved Words.
The YEAR(2) data type has certain issues
that you should consider before choosing to use it. As of
MySQL 5.6.6, YEAR(2) is deprecated.
YEAR(2) columns in existing tables are
treated as before, but YEAR(2) in new or
altered tables are converted to YEAR(4).
For more information, see
YEAR(2) Limitations and Migrating to YEAR(4).
As of MySQL 5.6.6, it is explicitly disallowed to assign the
value DEFAULT to stored procedure or
function parameters or stored program local variables (for
example with a SET
statement). This was not previously supported, or documented
as permitted, but is flagged as an incompatible change in
case existing code inadvertently used this construct. It
remains permissible to assign var_name = DEFAULTDEFAULT to
system variables, as before, but assigning
DEFAULT to parameters or local variables
now results in a syntax error.
After an upgrade to MySQL 5.6.6 or later, existing stored programs that use this construct produce a syntax error when invoked. If a mysqldump file from 5.6.5 or earlier is loaded into 5.6.6 or later, the load operation fails and affected stored program definitions must be changed.
In MySQL, the TIMESTAMP data
type differs in nonstandard ways from other data types:
TIMESTAMP columns not
explicitly declared with the NULL
attribute are assigned the NOT NULL
attribute. (Columns of other data types, if not
explicitly declared as NOT NULL,
permit NULL values.) Setting such a
column to NULL sets it to the current
timestamp.
The first TIMESTAMP
column in a table, if not declared with the
NULL attribute or an explicit
DEFAULT or ON
UPDATE clause, is automatically assigned the
DEFAULT CURRENT_TIMESTAMP and
ON UPDATE CURRENT_TIMESTAMP
attributes.
TIMESTAMP columns
following the first one, if not declared with the
NULL attribute or an explicit
DEFAULT clause, are automatically
assigned DEFAULT '0000-00-00
00:00:00' (the “zero” timestamp).
For inserted rows that specify no explicit value for
such a column, the column is assigned
'0000-00-00 00:00:00' and no warning
occurs.
Those nonstandard behaviors remain the default for
TIMESTAMP but as of MySQL
5.6.6 are deprecated and this warning appears at startup:
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
As indicated by the warning, to turn off the nonstandard
behaviors, enable the new
explicit_defaults_for_timestamp
system variable at server startup. With this variable
enabled, the server handles
TIMESTAMP as follows instead:
TIMESTAMP columns not
explicitly declared as NOT NULL
permit NULL values. Setting such a
column to NULL sets it to
NULL, not the current timestamp.
No TIMESTAMP column is
assigned the DEFAULT
CURRENT_TIMESTAMP or ON UPDATE
CURRENT_TIMESTAMP attributes automatically.
Those attributes must be explicitly specified.
TIMESTAMP columns
declared as NOT NULL and without an
explicit DEFAULT clause are treated
as having no default value. For inserted rows that
specify no explicit value for such a column, the result
depends on the SQL mode. If strict SQL mode is enabled,
an error occurs. If strict SQL mode is not enabled, the
column is assigned the implicit default of
'0000-00-00 00:00:00' and a warning
occurs. This is similar to how MySQL treats other
temporal types such as
DATETIME.
To upgrade servers used for replication, upgrade the slaves
first, then the master. Replication between the master and
its slaves should work provided that all use the same value
of
explicit_defaults_for_timestamp:
Bring down the slaves, upgrade them, configure them with
the desired value of
explicit_defaults_for_timestamp,
and bring them back up.
The slaves will recognize from the format of the binary
logs received from the master that the master is older
(predates the introduction of
explicit_defaults_for_timestamp)
and that operations on
TIMESTAMP columns coming
from the master use the old
TIMESTAMP behavior.
Bring down the master, upgrade it, and configure it with
the same
explicit_defaults_for_timestamp
value used on the slaves, and bring it back up.
For supported Yum-based platforms (see Section 7.1, “Installing MySQL on Linux Using the MySQL Yum Repository”, for a list), you can perform an in-place upgrade for MySQL (that is, replacing the old version and then running the new version off the old data files) with the MySQL Yum repository.
Before performing any update to MySQL, follow carefully the instructions in Section 10.1, “Upgrading MySQL”. Among other instructions discussed there, it is especially important to back up your database before the update.
The following instructions assume you have installed MySQL with the MySQL Yum repository or with an RPM package directly downloaded from MySQL Developer Zone's MySQL Download page; if that is not the case, following the instructions in Section 7.2, “Replacing a Third-Party Distribution of MySQL Using the MySQL Yum Repository”.
By default, the MySQL Yum repository updates MySQL to the latest version in the release series you have chosen during installation (see Selecting a Release Series for details), which means, for example, a 5.6.x installation will NOT be updated to a 5.7.x release automatically. To update to another release series, you need to first disable the subrepository for the series that has been selected (by default, or by yourself) and enable the subrepository for your target series. To do that, see the general instructions given in Selecting a Release Series. For upgrading from MySQL 5.6 to 5.7, perform the reverse of the steps illustrated in Selecting a Release Series, disabling the subrepository for the MySQL 5.6 series and enabling that for the MySQL 5.7 series.
As a general rule, to upgrade from one release series to another, go to the next series rather than skipping a series. For example, if you are currently running MySQL 5.5 and wish to upgrade to 5.7, upgrade to MySQL 5.6 first before upgrading to 5.7.
For important information about upgrading from MySQL 5.6 to 5.7, see Upgrading from MySQL 5.6 to 5.7.
Upgrade MySQL and its components by the following command, for platforms that are not dnf-enabled:
sudo yum update mysql-server
For platforms that are dnf-enabled:
sudo dnf upgrade mysql-server
Alternatively, you can update MySQL by telling Yum to update everything on your system, which might take considerably more time; for platforms that are not dnf-enabled:
sudo yum update
For platforms that are dnf-enabled:
sudo dnf upgrade
The MySQL server always restarts after an update by Yum. Once the server restarts, run mysql_upgrade to check and possibly resolve any incompatibilities between the old data and the upgraded software. mysql_upgrade also performs other functions; see mysql_upgrade — Check and Upgrade MySQL Tables for details.
You can also update only a specific component. Use the following command to list all the installed packages for the MySQL components (for dnf-enabled systems, replace yum in the command with dnf):
sudo yum list installed | grep "^mysql"
After identifying the package name of the component of your
choice, for platforms that are not dnf-enabled, update the
package with the following command, replacing
package-name with the name of the
package:
sudo yum update package-name
For dnf-enabled platforms:
sudo dnf upgrade package-name
After updating MySQL using the Yum repository, applications compiled with older versions of the shared client libraries should continue to work.
If you recompile applications and dynamically link them with the updated libraries: As typical with new versions of shared libraries where there are differences or additions in symbol versioning between the newer and older libraries (for example, between the newer, standard 5.6 shared client libraries and some older—prior or variant—versions of the shared libraries shipped natively by the Linux distributions' software repositories, or from some other sources), any applications compiled using the updated, newer shared libraries will require those updated libraries on systems where the applications are deployed. And, as expected, if those libraries are not in place, the applications requiring the shared libraries will fail. So, be sure to deploy the packages for the shared libraries from MySQL on those systems. You can do this by adding the MySQL Yum repository to the systems (see Adding the MySQL Yum Repository) and install the latest shared libraries using the instructions given in Installing Additional MySQL Products and Components with Yum.
On Debian 7 or 8 and Ubuntu 12, 14, or 15, you can perform an in-place upgrade of MySQL and its components with the MySQL APT repository. See Upgrading MySQL with the MySQL APT Repository in A Quick Guide to Using the MySQL APT Repository.
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.6.27 to 5.6.26.
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.6.27 to 5.6.26 and for downgrades from 5.6 to 5.5.
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.6.27 to 5.6.26 is supported. Skipping release series versions is also supported. For example, downgrading from 5.6.27 to 5.6.25 is supported.
Downgrading one release level is supported using the logical downgrade method. For example, downgrading from 5.6 to 5.5 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.6 to 5.5, and then to 5.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. For example, downgrading from MySQL 5.6.10 to MySQL 5.6.9 is not supported, as 5.6.9 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.6”. 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.6” 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.6” 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.6” 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.6, review the changes described in this section. Some changes may require action before or after downgrading.
The mysql.user table in MySQL 5.6 has a
password_expired column. The
mysql.user table in MySQL 5.5 does not.
This means that an account with an expired password in MySQL
5.6 will work normally in MySQL 5.5.
The mysql.host table was removed in MySQL
5.6.7. When downgrading to a previous release, startup on
the downgraded server fails with an error if the
mysql.host table is not present. You can
recreate the table manually or restore it from a backup
taken prior to upgrading to MySQL 5.6.7 or higher.
For TIME,
DATETIME, and
TIMESTAMP columns, the
storage required for tables created before MySQL 5.6.4
differs from storage required for tables created in 5.6.4
and later. This is due to a change in 5.6.4 that permits
these temporal types to have a fractional part. To downgrade
to a version older than 5.6.4, dump affected tables with
mysqldump before downgrading, and reload
the tables after downgrading.
The following query identifies tables and columns that may
be affected by this problem. Some of them are system tables
in the mysql database (such as
columns_priv and
proxies_priv). This means that
mysql is one of the databases you must
dump and reload, or server startup may fail after
downgrading.
SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE DATA_TYPE IN ('TIME','DATETIME','TIMESTAMP')
ORDER BY TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME;
InnoDB search indexes (with a type of
FULLTEXT), introduced in MySQL 5.6.4, are
not compatible with earlier versions of MySQL, including
earlier releases in the 5.6 series. Drop such indexes before
performing a downgrade.
InnoDB small page sizes specified by the
innodb_page_size
configuration option, introduced in MySQL 5.6.4, are not
compatible with earlier versions of MySQL, including earlier
releases in the 5.6 series. Dump all
InnoDB tables in instances that use a
smaller InnoDB page size, drop the
tables, and re-create and reload them after the downgrade.
As of MySQL 5.6, the relay-log.info
file contains a line count and a replication delay value, so
the file format differs from that in older versions. See
Slave Status Logs. If you downgrade a
slave server to a version older than MySQL 5.6, the older
server will not read the file correctly. To address this,
modify the file in a text editor to delete the initial line
containing the number of lines.
Beginning with MySQL 5.6.6, the MySQL Server employs Version
2 binary log events when writing the binary log. Binary logs
written using Version 2 log events cannot by read by earlier
versions of MySQL Server. To generate a binary log that is
written using Version 1 log events readable by older
servers, start the MySQL 5.6.6 or later server using
--log-bin-use-v1-row-events=1,
which forces the server to employ Version 1 events when
writing the binary log.
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”.
If you have ARCHIVE tables created in
MySQL 5.0, the recommended upgrade procedure is to dump the 5.0
ARCHIVE tables before upgrading and
reload them after upgrading.
As of MySQL 5.6.4, MySQL permits fractional seconds for
TIME,
DATETIME, and
TIMESTAMP column values. As a
result, encoding and storage requirements for these temporal
column types differ in tables created in MySQL 5.6.4 and later.
This incompatibility is described in
Section 10.1.1, “Changes Affecting Upgrades to MySQL 5.6”. When upgrading
to MySQL 5.6.4 or later, be aware that
CHECK TABLE ... FOR
UPGRADE does not report temporal columns that use the
pre-MySQL 5.6.4 format (Bug #73008, Bug #18985579). In MySQL
5.6.24, two new system variables,
avoid_temporal_upgrade and
show_old_temporals, were added to
provide control over temporal column upgrades (Bug #72997, Bug
#18985760).
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.
This section describes how to rebuild a table, following changes
to MySQL such as how data types or character sets are handled. For
example, an error in a collation might have been corrected,
requiring 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”.) You might
also need to repair or upgrade a table, 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.