Cari di MySQL 
    MySQL User Manual
Daftar Isi
(Sebelumnya) 2. Installing and Upgrading MySQL3. Tutorial (Berikutnya)

2.8. Installing MySQL on HP-UX

MySQL for HP-UX is available in a number of different forms:

2.8.1. General Notes on Installing MySQL on HP-UX

Some additional notes on installing and using MySQL on HP-UX:

  • If you install MySQL using a binary tarball distribution on HP-UX, you may run into trouble even before you get the MySQL distribution unpacked, as the HP-UX tar cannot handle long file names. This means that you may see errors when you try to unpack MySQL.

    If this occurs, you must use GNU tar (gtar) to unpack the distribution.

  • Because of some critical bugs in the standard HP-UX libraries, you should install the following patches before trying to run MySQL on HP-UX 11.0:

    PHKL_22840 Streams cumulativePHNE_22397 ARPA cumulative

    This solves the problem of getting EWOULDBLOCK from recv() and EBADF from accept() in threaded applications.

2.8.2. Installing MySQL on HP-UX using DEPOT

The HP-UX DEPOT format packages can be installed using the swinstall command. You should install the ncurses and zlib libraries before installing the MySQL DEPOT package. You can use the free software depothelper tool to install these packages and any dependencies for you automatically.

To install using the MySQL DEPOT packages, follow this guide:

  1. Download the MySQL DEPOT package from http://dev.mysql.com/downloads/. You must decompress the package before installation:

    root-shell> gunzip mysql-5.1.48-hpux11.31-ia64-64bit.depot.gz
  2. Install the DEPOT package using swinstall:

    root-shell> swinstall -s mysql-5.1.49-hpux11.31-ia64-64bit.depot

    MySQL will be installed into a directory matching the depot package name, within /usr/local. For convenience, you may want to create a symbolic link to the installed directory, for example:

    root-shell> ln -s mysql-5.1.49-hpux11.31-ia64-64bit mysql
  3. Your package is now installed. You should complete the configuration of MySQL by creating a user and group:

    root-shell> /usr/sbin/groupadd mysqlroot-shell> /usr/sbin/useradd -g mysql -d /var/lib/mysql/ -s /bin/false mysql
  4. Create the standard database using the new user/group you have created, and set the permissions:

    root-shell> cd /usr/local/root-shell> scripts/mysql_install_db --user=mysqlroot-shell> chown -R root .root-shell> chown -R mysql data
  5. Finally, secure your new installation by setting the root passwords, and then start your MySQL server using the mysql user:

    root-shell> mysql_secure_installationroot-shell> mysqld_safe --user=mysql &

2.9. Installing MySQL on FreeBSD

This section provides information about installing MySQL on variants of FreeBSD Unix.

You can install MySQL on FreeBSD by using the binary distribution provided by Oracle. For more information, see Section 2.2, "Installing MySQL from Generic Binaries on Unix/Linux".

The easiest (and preferred) way to install MySQL is to use the mysql-server and mysql-client ports available at http://www.freebsd.org/. Using these ports gives you the following benefits:

  • A working MySQL with all optimizations enabled that are known to work on your version of FreeBSD.

  • Automatic configuration and build.

  • Startup scripts installed in /usr/local/etc/rc.d.

  • The ability to use pkg_info -L to see which files are installed.

  • The ability to use pkg_delete to remove MySQL if you no longer want it on your machine.

The MySQL build process requires GNU make (gmake) to work. If GNU make is not available, you must install it first before compiling MySQL.

To install using the ports system:

# cd /usr/ports/databases/mysql51-server# make...# cd /usr/ports/databases/mysql51-client# make...

The standard port installation places the server into /usr/local/libexec/mysqld, with the startup script for the MySQL server placed in /usr/local/etc/rc.d/mysql-server.

Some additional notes on the BSD implementation:

  • To remove MySQL after installation using the ports system:

    # cd /usr/ports/databases/mysql51-server# make deinstall...# cd /usr/ports/databases/mysql51-client# make deinstall...
  • If you get problems with the current date in MySQL, setting the TZ variable should help. See Section 2.13, "Environment Variables".

2.10. Installing MySQL from Source

Building MySQL from the source code enables you to customize build parameters, compiler optimizations, and installation location. For a list of systems on which MySQL is known to run, see Section 2.1.1, "Operating Systems Supported by MySQL Community Server".

Before you proceed with an installation from source, check whether Oracle produces a precompiled binary distribution for your platform and whether it works for you. We put a great deal of effort into ensuring that our binaries are built with the best possible options for optimal performance. Instructions for installing binary distributions are available in Section 2.2, "Installing MySQL from Generic Binaries on Unix/Linux".

Note

This section describes how to build MySQL from source using CMake. Before MySQL 5.5, source builds used the GNU autotools on Unix-like systems. Source builds on Windows used CMake, but the process was different from that described here. For source-building instructions for older versions of MySQL, see Installing MySQL from Source, in the MySQL 5.1 Reference Manual. If you are familiar with autotools but not CMake, you might find these transition instructions helpful: Autotools to CMake Transition Guide

Source Installation Methods

There are two methods for installing MySQL from source:

  • Use a standard MySQL source distribution. To obtain a standard distribution, see Section 2.1.3, "How to Get MySQL". For instructions on building from a standard distribution, see Section 2.10.2, "Installing MySQL from a Standard Source Distribution".

    Standard distributions are available as compressed tar files, Zip archives, or RPM packages. Distribution files have names of the form mysql-VERSION.tar.gz, mysql-VERSION.zip, or mysql-VERSION.rpm, where VERSION is a number like 5.5.31. File names for source distributions can be distinguished from those for precompiled binary distributions in that source distribution names are generic and include no platform name, whereas binary distribution names include a platform name indicating the type of system for which the distribution is intended (for example, pc-linux-i686 or winx64).

  • Use a MySQL development tree. Development trees have not necessarily received the same level of testing as standard release distributions, so this installation method is usually required only if you need the most recent code changes. For information on building from one of the development trees, see Section 2.10.3, "Installing MySQL from a Development Source Tree".

Source Installation System Requirements

Installation of MySQL from source requires several development tools. Some of these tools are needed no matter whether you use a standard source distribution or a development source tree. Other tool requirements depend on which installation method you use.

To install MySQL from source, your system must have the following tools, regardless of installation method:

  • CMake, which is used as the build framework on all platforms. CMake can be downloaded from http://www.cmake.org.

  • A good make program. Although some platforms come with their own make implementations, it is highly recommended that you use GNU make 3.75 or newer. It may already be available on your system as gmake. GNU make is available from http://www.gnu.org/software/make/.

  • A working ANSI C++ compiler. GCC 4.2.1 or later, Sun Studio 10 or later, Visual Studio 2008 or later, and many current vendor-supplied compilers are known to work.

  • Perl is needed if you intend to run test scripts. Most Unix-like systems include Perl. On Windows, you can use a version such as ActiveState Perl.

To install MySQL from a standard source distribution, one of the following tools is required to unpack the distribution file:

  • For a .tar.gz compressed tar file: GNU gunzip to uncompress the distribution and a reasonable tar to unpack it. If your tar program supports the z option, it can both uncompress and unpack the file.

    GNU tar is known to work. The standard tar provided with some operating systems is not able to unpack the long file names in the MySQL distribution. You should download and install GNU tar, or if available, use a preinstalled version of GNU tar. Usually this is available as gnutar, gtar, or as tar within a GNU or Free Software directory, such as /usr/sfw/bin or /usr/local/bin. GNU tar is available from http://www.gnu.org/software/tar/.

  • For a .zip Zip archive: WinZip or another tool that can read .zip files.

  • For an .rpm RPM package: The rpmbuild program used to build the distribution unpacks it.

To install MySQL from a development source tree, the following additional tools are required:

  • To obtain the source tree, you must have Bazaar installed. The Bazaar VCS Web site has instructions for downloading and installing Bazaar on different platforms. Bazaar is supported on any platform that supports Python, and is therefore compatible with any Linux, Unix, Windows, or Mac OS X host.

  • bison is needed to generate sql_yacc.cc from sql_yacc.yy You should use the latest version of bison where possible. Versions 1.75 and 2.1 are known to work. There have been reported problems with bison 1.875. If you experience problems, upgrade to a later, rather than earlier, version.

    bison is available from http://www.gnu.org/software/bison/. bison for Windows can be downloaded from http://gnuwin32.sourceforge.net/packages/bison.htm. Download the package labeled "Complete package, excluding sources". On Windows, the default location for bison is the C:\Program Files\GnuWin32 directory. Some utilities may fail to find bison because of the space in the directory name. Also, Visual Studio may simply hang if there are spaces in the path. You can resolve these problems by installing into a directory that does not contain a space; for example C:\GnuWin32.

  • On OpenSolaris and Solaris Express, m4 must be installed in addition to bison. m4 is available from http://www.gnu.org/software/m4/.

Note

If you have to install any programs, modify your PATH environment variable to include any directories in which the programs are located. See Section 4.2.4, "Setting Environment Variables".

If you run into problems and need to file a bug report, please use the instructions in Section 1.7, "How to Report Bugs or Problems".

2.10.1. MySQL Layout for Source Installation

By default, when you install MySQL after compiling it from source, the installation step installs files under /usr/local/mysql. The component locations under the installation directory are the same as for binary distributions. See Table 2.2, "MySQL Installation Layout for Generic Unix/Linux Binary Package", and Section 2.3.1, "MySQL Installation Layout on Microsoft Windows". To configure installation locations different from the defaults, use the options described at Section 2.10.4, "MySQL Source-Configuration Options".

2.10.2. Installing MySQL from a Standard Source Distribution

To install MySQL from a standard source distribution:

  1. Verify that your system satisfies the tool requirements listed at Section 2.10, "Installing MySQL from Source".

  2. Obtain a distribution file using the instructions in Section 2.1.3, "How to Get MySQL".

  3. Configure, build, and install the distribution using the instructions in this section.

  4. Perform postinstallation procedures using the instructions in Section 2.11, "Postinstallation Setup and Testing".

In MySQL 5.5, CMake is used as the build framework on all platforms. The instructions given here should enable you to produce a working installation. For additional information on using CMake to build MySQL, see How to Build MySQL Server with CMake.

If you start from a source RPM, use the following command to make a binary RPM that you can install. If you do not have rpmbuild, use rpm instead.

shell> rpmbuild --rebuild --clean MySQL-VERSION.src.rpm

The result is one or more binary RPM packages that you install as indicated in Section 2.5.1, "Installing MySQL from RPM Packages on Linux".

The sequence for installation from a compressed tar file or Zip archive source distribution is similar to the process for installing from a generic binary distribution (see Section 2.2, "Installing MySQL from Generic Binaries on Unix/Linux"), except that it is used on all platforms and includes steps to configure and compile the distribution. For example, with a compressed tar file source distribution on Unix, the basic installation command sequence looks like this:

# Preconfiguration setupshell> groupadd mysqlshell> useradd -r -g mysql mysql# Beginning of source-build specific instructionsshell> tar zxvf mysql-VERSION.tar.gzshell> cd mysql-VERSIONshell> cmake .shell> makeshell> make install# End of source-build specific instructions# Postinstallation setupshell> cd /usr/local/mysqlshell> chown -R mysql .shell> chgrp -R mysql .shell> scripts/mysql_install_db --user=mysqlshell> chown -R root .shell> chown -R mysql data# Next command is optionalshell> cp support-files/my-medium.cnf /etc/my.cnfshell> bin/mysqld_safe --user=mysql &# Next command is optionalshell> cp support-files/mysql.server /etc/init.d/mysql.server

A more detailed version of the source-build specific instructions is shown following.

Note

The procedure shown here does not set up any passwords for MySQL accounts. After following the procedure, proceed to Section 2.11, "Postinstallation Setup and Testing", for postinstallation setup and testing.

Perform Preconfiguration Setup

On Unix, set up the mysql user and group that will be used to run and execute the MySQL server and own the database directory. For details, see Creating a mysql System User and Group, in Section 2.2, "Installing MySQL from Generic Binaries on Unix/Linux". Then perform the following steps as the mysql user, except as noted.

Obtain and Unpack the Distribution

Pick the directory under which you want to unpack the distribution and change location into it.

Obtain a distribution file using the instructions in Section 2.1.3, "How to Get MySQL".

Unpack the distribution into the current directory:

  • To unpack a compressed tar file, tar can uncompress and unpack the distribution if it has z option support:

    shell> tar zxvf mysql-VERSION.tar.gz

    If your tar does not have z option support, use gunzip to unpack the distribution and tar to unpack it:

    shell> gunzip < mysql-VERSION.tar.gz | tar xvf -

    Alternatively, CMake can uncompress and unpack the distribution:

    shell> cmake -E tar zxvf mysql-VERSION.tar.gz
  • To unpack a Zip archive, use WinZip or another tool that can read .zip files.

Unpacking the distribution file creates a directory named mysql-VERSION.

Configure the Distribution

Change location into the top-level directory of the unpacked distribution:

shell> cd mysql-VERSION

Configure the source directory. The minimum configuration command includes no options to override configuration defaults:

shell> cmake .

On Windows, specify the development environment. For example, the following commands configure MySQL for 32-bit or 64-bit builds, respectively:

shell> cmake . -G "Visual Studio 9 2008"shell> cmake . -G "Visual Studio 9 2008 Win64"

On Mac OS X, to use the Xcode IDE:

shell> cmake . -G Xcode

When you run cmake, you might want to add options to the command line. Here are some examples:

For a more extensive list of options, see Section 2.10.4, "MySQL Source-Configuration Options".

To list the configuration options, use one of the following commands:

shell> cmake . -L   # overviewshell> cmake . -LH  # overview with help textshell> cmake . -LAH # all params with help textshell> ccmake . # interactive display

If CMake fails, you might need to reconfigure by running it again with different options. If you do reconfigure, take note of the following:

  • If CMake is run after it has previously been run, it may use information that was gathered during its previous invocation. This information is stored in CMakeCache.txt. When CMake starts up, it looks for that file and reads its contents if it exists, on the assumption that the information is still correct. That assumption is invalid when you reconfigure.

  • Each time you run CMake, you must run make again to recompile. However, you may want to remove old object files from previous builds first because they were compiled using different configuration options.

To prevent old object files or configuration information from being used, run these commands on Unix before re-running CMake:

shell> make cleanshell> rm CMakeCache.txt

Or, on Windows:

shell> devenv MySQL.sln /cleanshell> del CMakeCache.txt

If you build out of the source tree (as described later), the CMakeCache.txt file and all built files are in the build directory, so you can remove that directory to object files and cached configuration information.

If you are going to send mail to a MySQL mailing list to ask for configuration assistance, first check the files in the CMakeFiles directory for useful information about the failure. To file a bug report, please use the instructions in Section 1.7, "How to Report Bugs or Problems".

Build the Distribution

On Unix:

shell> makeshell> make VERBOSE=1

The second command sets VERBOSE to show the commands for each compiled source.

Use gmake instead on systems where you are using GNU make and it has been installed as gmake.

On Windows:

shell> devenv MySQL.sln /build RelWithDebInfo

It is possible to build out of the source tree to keep the tree clean. If the top-level source directory is named mysql-src under your current working directory, you can build in a directory named build at the same level like this:

shell> mkdir buildshell> cd buildshell> cmake ../mysql-src

If you have gotten to the compilation stage, but the distribution does not build, see Section 2.10.5, "Dealing with Problems Compiling MySQL", for help. If that does not solve the problem, please enter it into our bugs database using the instructions given in Section 1.7, "How to Report Bugs or Problems". If you have installed the latest versions of the required tools, and they crash trying to process our configuration files, please report that also. However, if you get a command not found error or a similar problem for required tools, do not report it. Instead, make sure that all the required tools are installed and that your PATH variable is set correctly so that your shell can find them.

Install the Distribution

On Unix:

shell> make install

This installs the files under the configured installation directory (by default, /usr/local/mysql). You might need to run the command as root.

To install in a specific directory, add a DESTDIR parameter to the command line:

shell> make install DESTDIR="/opt/mysql"

Alternatively, generate installation package files that you can install where you like:

shell> make package

This operation produces one or more .tar.gz files that can be installed like generic binary distribution packages. See Section 2.2, "Installing MySQL from Generic Binaries on Unix/Linux". If you run CMake with -DCPACK_MONOLITHIC_INSTALL=1, the operation produces a single file. Otherwise, it produces multiple files.

On Windows, generate the data directory, then create a .zip archive installation package:

shell> devenv MySQL.sln /build RelWithDebInfo /project initial_databaseshell> devenv MySQL.sln /build RelWithDebInfo /project package

You can install the resulting .zip archive where you like. See Section 2.3.7, "Installing MySQL on Microsoft Windows Using a noinstall Zip Archive".

Perform Postinstallation Setup

The remainder of the installation process involves setting up the configuration file, creating the core databases, and starting the MySQL server. For instructions, see Section 2.11, "Postinstallation Setup and Testing".

Note

The accounts that are listed in the MySQL grant tables initially have no passwords. After starting the server, you should set up passwords for them using the instructions in Section 2.11, "Postinstallation Setup and Testing".

2.10.3. Installing MySQL from a Development Source Tree

This section discusses how to install MySQL from the latest development source code. Development trees have not necessarily received the same level of testing as standard release distributions, so this installation method is usually required only if you need the most recent code changes. Do not use a development tree for production systems. If your goal is simply to get MySQL up and running on your system, you should use a standard release distribution (either a binary or source distribution). See Section 2.1.3, "How to Get MySQL".

MySQL development projects are hosted on Launchpad. MySQL projects, including MySQL Server, MySQL Workbench, and others are available from the Oracle/MySQL Engineering page. For the repositories related only to MySQL Server, see the MySQL Server page.

To install MySQL from a development source tree, your system must satisfy the tool requirements listed at Section 2.10, "Installing MySQL from Source", including the requirements for Bazaar and bison.

To create a local branch of the MySQL development tree on your machine, use this procedure:

  1. To obtain a copy of the MySQL source code, you must create a new Bazaar branch. If you do not already have a Bazaar repository directory set up, you must initialize a new directory:

    shell> mkdir mysql-servershell> bzr init-repo --trees mysql-server

    This is a one-time operation.

  2. Assuming that you have an initialized repository directory, you can branch from the public MySQL server repositories to create a local source tree. To create a branch of a specific version:

    shell> cd mysql-servershell> bzr branch lp:mysql-server/5.5 mysql-5.5

    This is a one-time operation per source tree. You can branch the source trees for several versions of MySQL under the mysql-server directory.

  3. The initial download will take some time to complete, depending on the speed of your connection. Please be patient. Once you have downloaded the first tree, additional trees should take significantly less time to download.

  4. When building from the Bazaar branch, you may want to create a copy of your active branch so that you can make configuration and other changes without affecting the original branch contents. You can achieve this by branching from the original branch:

    shell> bzr branch mysql-5.5 mysql-5.5-build
  5. To obtain changes made after you have set up the branch initially, update it using the pull option periodically. Use this command in the top-level directory of the local copy:

    shell> bzr pull

    To examine the changeset comments for the tree, use the log option to bzr:

    shell> bzr log

    You can also browse changesets, comments, and source code online at the Launchpad MySQL Server page.

    If you see diffs (changes) or code that you have a question about, do not hesitate to send email to the MySQL internals mailing list. See Section 1.6.1, "MySQL Mailing Lists". If you think you have a better idea on how to do something, send an email message to the list with a patch.

After you have the local branch, you can build MySQL server from the source code. For information, see Section 2.10.2, "Installing MySQL from a Standard Source Distribution", except that you skip the part about obtaining and unpacking the distribution.

Be careful about installing a build from a distribution source tree on a production machine. The installation command may overwrite your live release installation. If you already have MySQL installed and do not want to overwrite it, run CMake with values for the CMAKE_INSTALL_PREFIX, MYSQL_TCP_PORT, and MYSQL_UNIX_ADDR options different from those used by your production server. For additional information about preventing multiple servers from interfering with each other, see Section 5.3, "Running Multiple MySQL Instances on One Machine".

Play hard with your new installation. For example, try to make new features crash. Start by running make test. See Section 23.1.2, "The MySQL Test Suite".

2.10.4. MySQL Source-Configuration Options

The CMake program provides a great deal of control over how you configure a MySQL source distribution. Typically, you do this using options on the CMake command line. For information about options supported by CMake, run either of these commands in the top-level source directory:

shell> cmake . -LHshell> ccmake .

You can also affect CMake using certain environment variables. See Section 2.13, "Environment Variables".

The following table shows the available CMake options. In the Default column, PREFIX stands for the value of the CMAKE_INSTALL_PREFIX option, which specifies the installation base directory. This value is used as the parent location for several of the installation subdirectories.

Table 2.14. MySQL Source-Configuration Option Reference(CMake)

FormatsDescriptionDefaultIntroducedRemoved
BUILD_CONFIGUse same build options as official releases5.5.7 
CMAKE_BUILD_TYPEType of build to produceRelWithDebInfo5.5.7 
CMAKE_INSTALL_PREFIXInstallation base directory/usr/local/mysql5.5.8 
COMPILATION_COMMENTComment about compilation environment5.5.7 
CPACK_MONOLITHIC_INSTALLWhether package build produces single fileOFF5.5.7 
DEFAULT_CHARSETThe default server character setlatin15.5.7 
DEFAULT_COLLATIONThe default server collationlatin1_swedish_ci5.5.7 
ENABLE_DEBUG_SYNCWhether to enable Debug Sync supportON5.5.7 
ENABLE_DOWNLOADSWhether to download optional filesOFF5.5.7 
ENABLE_DTRACEWhether to include DTrace support5.5.7 
ENABLE_GCOVWhether to include gcov support5.5.14 
ENABLED_LOCAL_INFILEWhether to enable LOCAL for LOAD DATA INFILEOFF5.5.7 
ENABLED_PROFILINGWhether to enable query profiling codeON5.5.7 
INSTALL_BINDIRUser executables directoryPREFIX/bin5.5.7 
INSTALL_DOCDIRDocumentation directoryPREFIX/docs5.5.7 
INSTALL_DOCREADMEDIRREADME file directoryPREFIX5.5.7 
INSTALL_INCLUDEDIRHeader file directoryPREFIX/include5.5.7 
INSTALL_INFODIRInfo file directoryPREFIX/docs5.5.7 
INSTALL_LAYOUTSelect predefined installation layoutSTANDALONE5.5.7 
INSTALL_LIBDIRLibrary file directoryPREFIX/lib5.5.7 
INSTALL_MANDIRManual page directoryPREFIX/man5.5.7 
INSTALL_MYSQLSHAREDIRShared data directoryPREFIX/share5.5.7 
INSTALL_MYSQLTESTDIRmysql-test directoryPREFIX/mysql-test5.5.7 
INSTALL_PLUGINDIRPlugin directoryPREFIX/lib/plugin5.5.7 
INSTALL_SBINDIRServer executable directoryPREFIX/bin5.5.7 
INSTALL_SCRIPTDIRScripts directoryPREFIX/scripts5.5.7 
INSTALL_SHAREDIRaclocal/mysql.m4 installation directoryPREFIX/share5.5.7 
INSTALL_SQLBENCHDIRsql-bench directoryPREFIX5.5.7 
INSTALL_SUPPORTFILESDIRExtra support files directoryPREFIX/support-files5.5.7 
MEMCACHED_HOMEPath to memcached[none]5.5.16-ndb-7.2.2 
MYSQL_DATADIRData directory5.5.7 
MYSQL_MAINTAINER_MODEWhether to enable MySQL maintainer-specific development environmentOFF5.5.7 
MYSQL_PROJECT_NAMEWindows/Mac OS X project name33065.5.21 
MYSQL_TCP_PORTTCP/IP port number33065.5.7 
MYSQL_UNIX_ADDRUnix socket file/tmp/mysql.sock5.5.7 
ODBC_INCLUDESODBC includes directory  
ODBC_LIB_DIRODBC library directory  
SYSCONFDIROption file directory5.5.7 
WITH_BUNDLED_LIBEVENTUse bundled libevent when building ndbmemcacheON5.5.16-ndb-7.2.2 
WITH_BUNDLED_MEMCACHEDUse bundled memcached when building ndbmemcacheON5.5.16-ndb-7.2.2 
WITH_CLASSPATHClasspath to use when building MySQL Cluster Connector for Java. Default is an empty string.  
WITH_DEBUGWhether to include debugging supportOFF5.5.7 
WITH_EMBEDDED_SERVERWhether to build embedded serverOFF5.5.7 
WITH_xxx_STORAGE_ENGINECompile storage engine xxx statically into server5.5.7 
WITH_ERROR_INSERTEnable error injection in the NDBCLUSTER storage engine. Should not be used for building binaries intended for production.OFF  
WITH_EXTRA_CHARSETSWhich extra character sets to includeall5.5.7 
WITH_LIBWRAPWhether to include libwrap (TCP wrappers) supportOFF5.5.7 
WITH_NDB_BINLOGEnable binary logging by default by mysqld.ON  
WITH_NDB_DEBUGProduce a debug build for testing or troubleshooting.OFF  
WITH_NDB_JAVAEnable building of Java and ClusterJ support. Enabled by default. Supported in MySQL Cluster only.ON5.5.27-ndb-7.2.9 
WITH_NDB_PORTDefault port used by a management server built with this option. If this option was not used to build it, the management server's default port is 1186.[none]  
WITH_NDB_TEST Include NDB API test programs.OFF  
WITH_NDBCLUSTER_STORAGE_ENGINEBuild the NDB storage engineON  
WITH_NDBMTDBuild multi-threaded data node.ON  
WITH_READLINEUse bundled readlineOFF5.5.7 
WITH_SSLType of SSL supportno5.5.7 
WITH_UNIXODBCEnable unixODBC supportOFF  
WITH_ZLIBType of zlib supportsystem5.5.7 
WITHOUT_xxx_STORAGE_ENGINEExclude storage engine xxx from build5.5.7 

The following sections provide more information about CMake options.

For boolean options, the value may be specified as 1 or ON to enable the option, or as 0 or OFF to disable the option.

Many options configure compile-time defaults that can be overridden at server startup. For example, the CMAKE_INSTALL_PREFIX, MYSQL_TCP_PORT, and MYSQL_UNIX_ADDR options that configure the default installation base directory location, TCP/IP port number, and Unix socket file can be changed at server startup with the --basedir, --port, and --socket options for mysqld. Where applicable, configuration option descriptions indicate the corresponding mysqld startup option.

General Options

  • -DBUILD_CONFIG=mysql_release

    This option configures a source distribution with the same build options used by Oracle to produce binary distributions for official MySQL releases.

  • -DCMAKE_BUILD_TYPE=type

    The type of build to produce:

    • RelWithDebInfo: Enable optimizations and generate debugging information. This is the default MySQL build type.

    • Debug: Disable optimizations and generate debugging information. This build type is also used if the WITH_DEBUG option is enabled. That is, -DWITH_DEBUG=1 has the same effect as -DCMAKE_BUILD_TYPE=Debug.

  • -DCPACK_MONOLITHIC_INSTALL=bool

    This option affects whether the make package operation produces multiple installation package files or a single file. If disabled, the operation produces multiple installation package files, which may be useful if you want to install only a subset of a full MySQL installation. If enabled, it produces a single file for installing everything.

Installation Layout Options

The CMAKE_INSTALL_PREFIX option indicates the base installation directory. Other options with names of the form INSTALL_xxx that indicate component locations are interpreted relative to the prefix and their values are relative pathnames. Their values should not include the prefix.

  • -DCMAKE_INSTALL_PREFIX=dir_name

    The installation base directory.

    This value can be set at server startup with the --basedir option.

  • -DINSTALL_BINDIR=dir_name

    Where to install user programs.

  • -DINSTALL_DOCDIR=dir_name

    Where to install documentation.

  • -DINSTALL_DOCREADMEDIR=dir_name

    Where to install README files.

  • -DINSTALL_INCLUDEDIR=dir_name

    Where to install header files.

  • -DINSTALL_INFODIR=dir_name

    Where to install Info files.

  • -DINSTALL_LAYOUT=name

    Select a predefined installation layout:

    • STANDALONE: Same layout as used for .tar.gz and .zip packages. This is the default.

    • RPM: Layout similar to RPM packages.

    • SVR4: Solaris package layout.

    • DEB: DEB package layout (experimental).

    You can select a predefined layout but modify individual component installation locations by specifying other options. For example:

    shell> cmake . -DINSTALL_LAYOUT=SVR4 -DMYSQL_DATADIR=/var/mysql/data
  • -DINSTALL_LIBDIR=dir_name

    Where to install library files.

  • -DINSTALL_MANDIR=dir_name

    Where to install manual pages.

  • -DINSTALL_MYSQLSHAREDIR=dir_name

    Where to install shared data files.

  • -DINSTALL_MYSQLTESTDIR=dir_name

    Where to install the mysql-test directory.

  • -DINSTALL_PLUGINDIR=dir_name

    The location of the plugin directory.

    This value can be set at server startup with the --plugin_dir option.

  • -DINSTALL_SBINDIR=dir_name

    Where to install the mysqld server.

  • -DINSTALL_SCRIPTDIR=dir_name

    Where to install mysql_install_db.

  • -DINSTALL_SHAREDIR=dir_name

    Where to install aclocal/mysql.m4.

  • -DINSTALL_SQLBENCHDIR=dir_name

    Where to install the sql-bench directory. To not install this directory, use an empty value (-DINSTALL_SQLBENCHDIR=).

  • -DINSTALL_SUPPORTFILESDIR=dir_name

    Where to install extra support files.

  • -DMYSQL_DATADIR=dir_name

    The location of the MySQL data directory.

    This value can be set at server startup with the --datadir option.

  • -DODBC_INCLUDES=dir_name

    The location of the ODBC includes directory, and may be used while configuring Connector/ODBC.

  • -DODBC_LIB_DIR=dir_name

    The location of the ODBC library directory, and may be used while configuring Connector/ODBC.

  • -DSYSCONFDIR=dir_name

    The default my.cnf option file directory.

    This location cannot be set at server startup, but you can start the server with a given option file using the --defaults-file=file_name option, where file_name is the full path name to the file.

  • -DWITH_UNIXODBC=1

    Enables unixODBC support, for Connector/ODBC.

Storage Engine Options

Storage engines are built as plugins. You can build a plugin as a static module (compiled into the server) or a dynamic module (built as a dynamic library that must be installed into the server using the INSTALL PLUGIN statement or the --plugin-load option before it can be used). Some plugins might not support static or dynamic building.

The MyISAM, MERGE, MEMORY, and CSV engines are mandatory (always compiled into the server) and need not be installed explicitly.

To compile a storage engine statically into the server, use -DWITH_engine_STORAGE_ENGINE=1. Some permissible engine values are ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), NDBCLUSTER (NDB), PARTITION (partitioning support), and PERFSCHEMA (Performance Schema). Examples:

-DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_ARCHIVE_STORAGE_ENGINE=1-DWITH_BLACKHOLE_STORAGE_ENGINE=1-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
Note

WITH_NDBCLUSTER_STORAGE_ENGINE is supported only when building MySQL Cluster using the MySQL Cluster sources. It cannot be used to enable clustering support in other MySQL source trees or distributions. In MySQL Cluster NDB 7.2 source distributions, it is enabled by default. See Section 17.2.1.3, "Building MySQL Cluster from Source on Linux", and Section 17.2.2.2, "Compiling and Installing MySQL Cluster from Source on Windows", for more information.

To exclude a storage engine from the build, use -DWITHOUT_engine_STORAGE_ENGINE=1. Examples:

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1-DWITHOUT_FEDERATED_STORAGE_ENGINE=1-DWITHOUT_PARTITION_STORAGE_ENGINE=1

If neither -DWITH_engine_STORAGE_ENGINE nor -DWITHOUT_engine_STORAGE_ENGINE are specified for a given storage engine, the engine is built as a shared module, or excluded if it cannot be built as a shared module.

Feature Options

  • -DCOMPILATION_COMMENT=string

    A descriptive comment about the compilation environment.

  • -DDEFAULT_CHARSET=charset_name

    The server character set. By default, MySQL uses the latin1 (cp1252 West European) character set.

    charset_name may be one of binary, armscii8, ascii, big5, cp1250, cp1251, cp1256, cp1257, cp850, cp852, cp866, cp932, dec8, eucjpms, euckr, gb2312, gbk, geostd8, greek, hebrew, hp8, keybcs2, koi8r, koi8u, latin1, latin2, latin5, latin7, macce, macroman, sjis, swe7, tis620, ucs2, ujis, utf8, utf8mb4, utf16, utf32. The permissible character sets are listed in the cmake/character_sets.cmake file as the value of CHARSETS_AVAILABLE.

    This value can be set at server startup with the --character_set_server option.

  • -DDEFAULT_COLLATION=collation_name

    The server collation. By default, MySQL uses latin1_swedish_ci. Use the SHOW COLLATION statement to determine which collations are available for each character set.

    This value can be set at server startup with the --collation_server option.

  • -DENABLE_DEBUG_SYNC=bool

    Whether to compile the Debug Sync facility into the server. This facility is used for testing and debugging. This option is enabled by default, but has no effect unless MySQL is configured with debugging enabled. If debugging is enabled and you want to disable Debug Sync, use -DENABLE_DEBUG_SYNC=0.

    When compiled in, Debug Sync is disabled by default at runtime. To enable it, start mysqld with the --debug-sync-timeout=N option, where N is a timeout value greater than 0. (The default value is 0, which disables Debug Sync.) N becomes the default timeout for individual synchronization points.

    For a description of the Debug Sync facility and how to use synchronization points, see MySQL Internals: Test Synchronization.

  • -DENABLE_DOWNLOADS=bool

    Whether to download optional files. For example, with this option enabled, CMake downloads the Google Test distribution that is used by the test suite to run unit tests.

  • -DENABLE_DTRACE=bool

    Whether to include support for DTrace probes. For information about DTrace, wee Section 5.4, "Tracing mysqld Using DTrace"

  • -DENABLE_GCOV=bool

    Whether to include gcov support (Linux only).

  • -DENABLED_LOCAL_INFILE=bool

    Whether to enable LOCAL capability in the client library for LOAD DATA INFILE.

    This option controls client-side LOCAL capability, but the capability can be set on the server side at server startup with the --local-infile option. See Section 6.1.6, "Security Issues with LOAD DATA LOCAL".

  • -DENABLED_PROFILING=bool

    Whether to enable query profiling code (for the SHOW PROFILE and SHOW PROFILES statements).

  • -DMYSQL_MAINTAINER_MODE=bool

    Whether to enable a MySQL maintainer-specific development environment. If enabled, this option causes compiler warnings to become errors.

  • -DMYSQL_PROJECT_NAME=name

    For Windows or Mac OS X, the project name to incorporate into the project file name. This option was added in MySQL 5.5.21.

  • -DMYSQL_TCP_PORT=port_num

    The port number on on which the server listens for TCP/IP connections. The default is 3306.

    This value can be set at server startup with the --port option.

  • -DMYSQL_UNIX_ADDR=file_name

    The Unix socket file path on which the server listens for socket connections. This must be an absolute path name. The default is /tmp/mysql.sock.

    This value can be set at server startup with the --socket option.

  • -DWITH_DEBUG=bool

    Whether to include debugging support.

    Configuring MySQL with debugging support enables you to use the --debug="d,parser_debug" option when you start the server. This causes the Bison parser that is used to process SQL statements to dump a parser trace to the server's standard error output. Typically, this output is written to the error log.

  • -DWITH_EMBEDDED_SERVER=bool

    Whether to build the libmysqld embedded server library.

  • -DWITH_EXTRA_CHARSETS=name

    Which extra character sets to include:

    • all: All character sets. This is the default.

    • complex: Complex character sets.

    • none: No extra character sets.

  • -DWITH_LIBWRAP=bool

    Whether to include libwrap (TCP wrappers) support.

  • -DWITH_READLINE=bool

    Whether to use the readline library bundled with the distribution.

  • -DWITH_SSL=ssl_type

    The type of SSL support to include, if any:

    • no: No SSL support. This is the default.

    • yes: Use the system SSL library if present, else the library bundled with the distribution.

    • bundled: Use the SSL library bundled with the distribution.

    • system: Use the system SSL library.

    For information about using SSL support, see Section 6.3.8, "Using SSL for Secure Connections".

  • -DWITH_ZLIB=zlib_type

    Some features require that the server be built with compression library support, such as the COMPRESS() and UNCOMPRESS() functions, and compression of the client/server protocol. The WITH_ZLIB indicates the source of zlib support:

    • bundled: Use the zlib library bundled with the distribution.

    • system: Use the system zlib library. This is the default.

Compiler Flags

To specify compiler flags, set the CFLAGS and CXXFLAGS environment variables before running CMake. Example:

shell> CFLAGS=-DDISABLE_GRANT_OPTIONSshell> CXXFLAGS=-DDISABLE_GRANT_OPTIONSshell> export CFLAGS CXXFLAGSshell> cmake [options]

The following flags control configuration features:

  • DISABLE_GRANT_OPTIONS

    If this flag is defined, it causes the --bootstrap, --skip-grant-tables, and --init-file options for mysqld to be disabled.

  • HAVE_EMBEDDED_PRIVILEGE_CONTROL

    By default, authentication for connections to the embedded server is disabled. To enable connection authentication, define this flag.

CMake Options for Compiling MySQL Cluster

The following options are for use when building MySQL Cluster NDB 7.2 or later. These options are supported only with the MySQL Cluster NDB 7.2 and later MySQL Cluster sources; they are not supported when using sources from the MySQL 5.5 Server tree.

  • -DMEMCACHED_HOME=path

    Perform the build using the memcached (version 1.6 or later) installed in the system directory indicated by path. Files from this installation that are used in the build include the memcached binary, header files, and libraries, as well as the memcached_utilities library and the header file engine_testapp.h.

    You must leave this option unset when building ndbmemcache using the bundled memcached sources (WITH_BUNDLED_MEMCACHED option); in other words, the bundled sources are used by default).

    This option was added in MySQL Cluster NDB 7.2.2.

    While additional CMake options-such as for SASL authorization and for providing dtrace support-are available for use when compiling memcached from external sources, these options are currently not enabled for the memcached sources bundled with MySQL Cluster.

  • -DWITH_BUNDLED_LIBEVENT={ON|OFF}

    Use the libevent included in the MySQL Cluster sources when building MySQL Cluster with ndbmemcached support (MySQL Cluster NDB 7.2.2 and later). Enabled by default. OFF causes the system's libevent to be used instead.

  • -DWITH_BUNDLED_MEMCACHED={ON|OFF}

    Build the memcached sources included in the MySQL Cluster source tree (MySQL Cluster NDB 7.2.3 and later), then use the resulting memcached server when building the ndbmemcache engine. In this case, make install places the memcached binary in the installation bin directory, and the ndbmemcache engine shared object file ndb_engine.so in the installation lib directory.

    This option is ON by default.

  • -DWITH_CLASSPATH=path

    Sets the classpath for building MySQL Cluster Connector for Java. Default is empty. In MySQL Cluster NDB 7.2.9 and later, this option is ignored if -DWITH_NDB_JAVA=OFF is used.

  • -DWITH_ERROR_INSERT={ON|OFF}

    Enables error injection in the NDB kernel. For testing only; not intended for use in building production binaries. Default is OFF.

  • -DWITH_NDBCLUSTER_STORAGE_ENGINE={ON|OFF}

    Build and link in support for the NDB (NDBCLUSTER) storage engine in mysqld. Default is ON.

  • -DWITH_NDBCLUSTER={ON|OFF}

    This is an alias for WITH_NDBCLUSTER_STORAGE_ENGINE.

  • -DWITH_NDBMTD={ON|OFF}

    Build the multithreaded data node executable ndbmtd. Default is ON.

  • -DWITH_NDB_BINLOG={ON|OFF}

    Enable binary logging by default in the mysqld built using this option. ON by default.

  • -DWITH_NDB_DEBUG={ON|OFF}

    Enable building the debug versions of the MySQL Cluster binaries. OFF by default.

  • -DWITH_NDB_JAVA={ON|OFF}

    Enable building MySQL Cluster with Java support, including ClusterJ.

    This option was added in MySQL Cluster NDB 7.2.9, and is ON by default. If you do not wish to compile MySQL Cluster with Java support, you must disable it explicitly by specifiying -DWITH_NDB_JAVA=OFF when running CMake. Otherwise, if Java cannot be found, configuration of the build fails.

  • -DWITH_NDB_PORT=port

    Causes the MySQL Cluster management server (ndb_mgmd) that is built to use this port by default. If this option is unset, the resulting management server tries to use port 1186 by default.

  • -DWITH_NDB_TEST={ON|OFF}

    If enabled, include a set of NDB API test programs. The default is OFF.

2.10.5. Dealing with Problems Compiling MySQL

The solution to many problems involves reconfiguring. If you do reconfigure, take note of the following:

  • If CMake is run after it has previously been run, it may use information that was gathered during its previous invocation. This information is stored in CMakeCache.txt. When CMake starts up, it looks for that file and reads its contents if it exists, on the assumption that the information is still correct. That assumption is invalid when you reconfigure.

  • Each time you run CMake, you must run make again to recompile. However, you may want to remove old object files from previous builds first because they were compiled using different configuration options.

To prevent old object files or configuration information from being used, run these commands on Unix before re-running CMake:

shell> make cleanshell> rm CMakeCache.txt

Or, on Windows:

shell> devenv MySQL.sln /cleanshell> del CMakeCache.txt

If you build out of the source tree, remove and recreate your build directory before re-running CMake. For instructions on building outside of the source tree, see How to Build MySQL Server with CMake.

On some systems, warnings may occur due to differences in system include files. The following list describes other problems that have been found to occur most often when compiling MySQL:

  • To define flags to be used by your C or C++ compilers, specify them using the CFLAGS and CXXFLAGS environment variables. You can also specify the compiler names this way using CC and CXX. For example:

    shell> CC=gccshell> CFLAGS=-O3shell> CXX=gccshell> CXXFLAGS=-O3shell> export CC CFLAGS CXX CXXFLAGS

    To see what flags you might need to specify, invoke mysql_config with the --cflags option.

  • If compilation fails, check whether the MYSQL_MAINTAINER_MODE option is enabled. This mode causes compiler warnings to become errors, so disabling it may enable compilation to proceed.

  • If your compile fails with errors such as any of the following, you must upgrade your version of make to GNU make:

    make: Fatal error in reader: Makefile, line 18:Badly formed macro assignment

    Or:

    make: file `Makefile' line 18: Must be a separator (:

    Or:

    pthread.h: No such file or directory

    Solaris and FreeBSD are known to have troublesome make programs.

    GNU make 3.75 is known to work.

  • The sql_yacc.cc file is generated from sql_yacc.yy. Normally, the build process does not need to create sql_yacc.cc because MySQL comes with a pregenerated copy. However, if you do need to re-create it, you might encounter this error:

    "sql_yacc.yy", line xxx fatal: default action causes potential...

    This is a sign that your version of yacc is deficient. You probably need to install bison (the GNU version of yacc) and use that instead.

    Versions of bison older than 1.75 may report this error:

    sql_yacc.yy:#####: fatal error: maximum table size (32767) exceeded

    The maximum table size is not actually exceeded; the error is caused by bugs in older versions of bison.

For information about acquiring or updating tools, see the system requirements in Section 2.10, "Installing MySQL from Source".

2.10.6. MySQL Configuration and Third-Party Tools

Third-party tools that need to determine the MySQL version from the MySQL source can read the VERSION file in the top-level source directory. The file lists the pieces of the version separately. For example, if the version is 5.5.8, the file looks like this:

MYSQL_VERSION_MAJOR=5MYSQL_VERSION_MINOR=5MYSQL_VERSION_PATCH=8MYSQL_VERSION_EXTRA=

If the source is not for a General Availability (GA) release, the MYSQL_VERSION_EXTRA value will be nonempty. For example, the value for a Release Candidate release would look like this:

MYSQL_VERSION_EXTRA=rc

To construct a five-digit number from the version components, use this formula:

MYSQL_VERSION_MAJOR*10000 + MYSQL_VERSION_MINOR*100 + MYSQL_VERSION_PATCH

2.11. Postinstallation Setup and Testing

After installing MySQL, there are some issues that you should address. For example, on Unix, you should initialize the data directory and create the MySQL grant tables. On all platforms, an important security concern is that the initial accounts in the grant tables have no passwords. You should assign passwords to prevent unauthorized access to the MySQL server. Optionally, you can create time zone tables to enable recognition of named time zones.

The following sections include postinstallation procedures that are specific to Windows systems and to Unix systems. Another section, Section 2.11.1.3, "Starting and Troubleshooting the MySQL Server", applies to all platforms; it describes what to do if you have trouble getting the server to start. Section 2.11.2, "Securing the Initial MySQL Accounts", also applies to all platforms. You should follow its instructions to make sure that you have properly protected your MySQL accounts by assigning passwords to them.

When you are ready to create additional user accounts, you can find information on the MySQL access control system and account management in Section 6.2, "The MySQL Access Privilege System", and Section 6.3, "MySQL User Account Management".

2.11.1. Unix Postinstallation Procedures

After installing MySQL on Unix, you must initialize the grant tables, start the server, and make sure that the server works satisfactorily. You may also wish to arrange for the server to be started and stopped automatically when your system starts and stops. You should also assign passwords to the accounts in the grant tables.

On Unix, the grant tables are set up by the mysql_install_db program. For some installation methods, this program is run for you automatically if an existing database cannot be found.

  • If you install MySQL on Linux using RPM distributions, the server RPM runs mysql_install_db.

  • Using the native packaging system on many platforms, including Debian Linux, Ubuntu Linux, Gentoo Linux and others, the mysql_install_db command is run for you.

  • If you install MySQL on Mac OS X using a PKG distribution, the installer runs mysql_install_db.

For other platforms and installation types, including generic binary and source installs, you will need to run mysql_install_db yourself.

The following procedure describes how to initialize the grant tables (if that has not previously been done) and start the server. It also suggests some commands that you can use to test whether the server is accessible and working properly. For information about starting and stopping the server automatically, see Section 2.11.1.2, "Starting and Stopping MySQL Automatically".

After you complete the procedure and have the server running, you should assign passwords to the accounts created by mysql_install_db and perhaps restrict access to test databases. For instructions, see Section 2.11.2, "Securing the Initial MySQL Accounts".

In the examples shown here, the server runs under the user ID of the mysql login account. This assumes that such an account exists. Either create the account if it does not exist, or substitute the name of a different existing login account that you plan to use for running the server. For information about creating the account, see Creating a mysql System User and Group, in Section 2.2, "Installing MySQL from Generic Binaries on Unix/Linux".

  1. Change location into the top-level directory of your MySQL installation, represented here by BASEDIR:

    shell> cd BASEDIR

    BASEDIR is the installation directory for your MySQL instance. It is likely to be something like /usr/local/mysql or /usr/local. The following steps assume that you have changed location to this directory.

    You will find several files and subdirectories in the BASEDIR directory. The most important for installation purposes are the bin and scripts subdirectories:

    • The bin directory contains client programs and the server. You should add the full path name of this directory to your PATH environment variable so that your shell finds the MySQL programs properly. See Section 2.13, "Environment Variables".

    • The scripts directory contains the mysql_install_db script used to initialize the mysql database containing the grant tables that store the server access permissions.

  2. If necessary, ensure that the distribution contents are accessible to mysql. If you installed the distribution as mysql, no further action is required. If you installed the distribution as root, its contents will be owned by root. Change its ownership to mysql by executing the following commands as root in the installation directory. The first command changes the owner attribute of the files to the mysql user. The second changes the group attribute to the mysql group.

    shell> chown -R mysql .shell> chgrp -R mysql .
  3. If necessary, run the mysql_install_db program to set up the initial MySQL grant tables containing the privileges that determine how users are permitted to connect to the server. You will need to do this if you used a distribution type for which the installation procedure does not run the program for you.

    shell> scripts/mysql_install_db --user=mysql

    Typically, mysql_install_db needs to be run only the first time you install MySQL, so you can skip this step if you are upgrading an existing installation, However, mysql_install_db does not overwrite any existing privilege tables, so it should be safe to run in any circumstances.

    It might be necessary to specify other options such as --basedir or --datadir if mysql_install_db does not identify the correct locations for the installation directory or data directory. For example:

    shell> scripts/mysql_install_db --user=mysql \ --basedir=/opt/mysql/mysql \ --datadir=/opt/mysql/mysql/data

    The mysql_install_db script creates the server's data directory with mysql as the owner. Under the data directory, it creates directories for the mysql database that holds the grant tables and the test database that you can use to test MySQL. The script also creates privilege table entries for root and anonymous-user accounts. The accounts have no passwords initially. Section 2.11.2, "Securing the Initial MySQL Accounts", describes the initial privileges. Briefly, these privileges permit the MySQL root user to do anything, and permit anybody to create or use databases with a name of test or starting with test_. See Section 6.2, "The MySQL Access Privilege System", for a complete listing and description of the grant tables.

    It is important to make sure that the database directories and files are owned by the mysql login account so that the server has read and write access to them when you run it later. To ensure this if you run mysql_install_db as root, include the --user option as shown. Otherwise, you should execute the script while logged in as mysql, in which case you can omit the --user option from the command.

    If you do not want to have the test database, you can remove it after starting the server, using the instructions in Section 2.11.2, "Securing the Initial MySQL Accounts".

    If you have trouble with mysql_install_db at this point, see Section 2.11.1.1, "Problems Running mysql_install_db".

  4. Most of the MySQL installation can be owned by root if you like. The exception is that the data directory must be owned by mysql. To accomplish this, run the following commands as root in the installation directory:

    shell> chown -R root .shell> chown -R mysql data
  5. If the plugin directory (the directory named by the plugin_dir system variable) is writable by the server, it may be possible for a user to write executable code to a file in the directory using SELECT ... INTO DUMPFILE. This can be prevented by making plugin_dir read only to the server or by setting --secure-file-priv to a directory where SELECT writes can be made safely.

  6. If you installed MySQL using a source distribution, you may want to optionally copy one of the provided configuration files from the support-files directory into your /etc directory. There are different sample configuration files for different use cases, server types, and CPU and RAM configurations. If you want to use one of these standard files, you should copy it to /etc/my.cnf, or /etc/mysql/my.cnf and edit and check the configuration before starting your MySQL server for the first time.

    If you do not copy one of the standard configuration files, the MySQL server will be started with the default settings.

    If you want MySQL to start automatically when you boot your machine, you can copy support-files/mysql.server to the location where your system has its startup files. More information can be found in the mysql.server script itself, and in Section 2.11.1.2, "Starting and Stopping MySQL Automatically".

  7. Start the MySQL server:

    shell> bin/mysqld_safe --user=mysql &

    It is important that the MySQL server be run using an unprivileged (non-root) login account. To ensure this if you run mysqld_safe as root, include the --user option as shown. Otherwise, you should execute the script while logged in as mysql, in which case you can omit the --user option from the command.

    For further instructions for running MySQL as an unprivileged user, see Section 6.1.5, "How to Run MySQL as a Normal User".

    If the command fails immediately and prints mysqld ended, look for information in the error log (which by default is the host_name.err file in the data directory).

    If you neglected to create the grant tables by running mysql_install_db before proceeding to this step, the following message appears in the error log file when you start the server:

    mysqld: Can't find file: 'host.frm'

    This error also occurs if you run mysql_install_db as root without the --user option. Remove the data directory and run mysql_install_db with the --user option as described previously.

    If you have other problems starting the server, see Section 2.11.1.3, "Starting and Troubleshooting the MySQL Server". For more information about mysqld_safe, see Section 4.3.2, "mysqld_safe - MySQL Server Startup Script".

  8. Use mysqladmin to verify that the server is running. The following commands provide simple tests to check whether the server is up and responding to connections:

    shell> bin/mysqladmin versionshell> bin/mysqladmin variables

    The output from mysqladmin version varies slightly depending on your platform and version of MySQL, but should be similar to that shown here:

    shell> bin/mysqladmin versionmysqladmin  Ver 14.12 Distrib 5.5.31, for pc-linux-gnu on i686...Server version  5.5.31Protocol version 10Connection  Localhost via UNIX socketUNIX socket /var/lib/mysql/mysql.sockUptime: 14 days 5 hours 5 min 21 secThreads: 1  Questions: 366  Slow queries: 0Opens: 0  Flush tables: 1  Open tables: 19Queries per second avg: 0.000

    To see what else you can do with mysqladmin, invoke it with the --help option.

  9. Verify that you can shut down the server:

    shell> bin/mysqladmin -u root shutdown
  10. Verify that you can start the server again. Do this by using mysqld_safe or by invoking mysqld directly. For example:

    shell> bin/mysqld_safe --user=mysql &

    If mysqld_safe fails, see Section 2.11.1.3, "Starting and Troubleshooting the MySQL Server".

  11. Run some simple tests to verify that you can retrieve information from the server. The output should be similar to what is shown here:

    shell> bin/mysqlshow+--------------------+| Databases  |+--------------------+| information_schema || mysql  || test   |+--------------------+shell> bin/mysqlshow mysqlDatabase: mysql+---------------------------+|  Tables   |+---------------------------+| columns_priv  || db || event || func  || help_category || help_keyword  || help_relation || help_topic || host  || plugin || proc  || procs_priv || servers   || tables_priv   || time_zone || time_zone_leap_second || time_zone_name || time_zone_transition  || time_zone_transition_type || user  |+---------------------------+shell> bin/mysql -e "SELECT Host,Db,User FROM db" mysql+------+--------+------+| host | db | user |+------+--------+------+| % | test   |  || % | test_% |  |+------+--------+------+
  12. There is a benchmark suite in the sql-bench directory (under the MySQL installation directory) that you can use to compare how MySQL performs on different platforms. The benchmark suite is written in Perl. It requires the Perl DBI module that provides a database-independent interface to the various databases, and some other additional Perl modules:

    DBIDBD::mysqlData::DumperData::ShowTable

    These modules can be obtained from CPAN (http://www.cpan.org/). See also Section 2.14.1, "Installing Perl on Unix".

    The sql-bench/Results directory contains the results from many runs against different databases and platforms. To run all tests, execute these commands:

    shell> cd sql-benchshell> perl run-all-tests

    If you do not have the sql-bench directory, you probably installed MySQL using RPM files other than the source RPM. (The source RPM includes the sql-bench benchmark directory.) In this case, you must first install the benchmark suite before you can use it. There are separate benchmark RPM files named mysql-bench-VERSION.i386.rpm that contain benchmark code and data.

    If you have a source distribution, there are also tests in its tests subdirectory that you can run. For example, to run auto_increment.tst, execute this command from the top-level directory of your source distribution:

    shell> mysql -vvf test < ./tests/auto_increment.tst

    The expected result of the test can be found in the ./tests/auto_increment.res file.

  13. At this point, you should have the server running. However, none of the initial MySQL accounts have a password, and the server permits permissive access to test databases. To tighten security, follow the instructions in Section 2.11.2, "Securing the Initial MySQL Accounts".

The MySQL 5.5 installation procedure creates time zone tables in the mysql database but does not populate them. To do so, use the instructions in Section 10.6, "MySQL Server Time Zone Support".

To make it more convenient to invoke programs installed in the bin directory under the installation directory, you can add that directory to your PATH environment variable setting. That enables you to run a program by typing only its name, not its entire path name. See Section 4.2.4, "Setting Environment Variables".

You can set up new accounts using the bin/mysql_setpermission script if you install the DBI and DBD::mysql Perl modules. See Section 4.6.13, "mysql_setpermission - Interactively Set Permissions in GrantTables". For Perl module installation instructions, see Section 2.14, "Perl Installation Notes".

If you would like to use mysqlaccess and have the MySQL distribution in some nonstandard location, you must change the location where mysqlaccess expects to find the mysql client. Edit the bin/mysqlaccess script at approximately line 18. Search for a line that looks like this:

$MYSQL = '/usr/local/bin/mysql'; # path to mysql executable

Change the path to reflect the location where mysql actually is stored on your system. If you do not do this, a Broken pipe error will occur when you run mysqlaccess.

2.11.1.1. Problems Running mysql_install_db

The purpose of the mysql_install_db script is to generate new MySQL privilege tables. It does not overwrite existing MySQL privilege tables, and it does not affect any other data.

If you want to re-create your privilege tables, first stop the mysqld server if it is running. Then rename the mysql directory under the data directory to save it, and then run mysql_install_db. Suppose that your current directory is the MySQL installation directory and that mysql_install_db is located in the bin directory and the data directory is named data. To rename the mysql database and re-run mysql_install_db, use these commands.

shell> mv data/mysql data/mysql.oldshell> scripts/mysql_install_db --user=mysql

When you run mysql_install_db, you might encounter the following problems:

  • mysql_install_db fails to install the grant tables

    You may find that mysql_install_db fails to install the grant tables and terminates after displaying the following messages:

    Starting mysqld daemon with databases from XXXXXXmysqld ended

    In this case, you should examine the error log file very carefully. The log should be located in the directory XXXXXX named by the error message and should indicate why mysqld did not start. If you do not understand what happened, include the log when you post a bug report. See Section 1.7, "How to Report Bugs or Problems".

  • There is a mysqld process running

    This indicates that the server is running, in which case the grant tables have probably been created already. If so, there is no need to run mysql_install_db at all because it needs to be run only once (when you install MySQL the first time).

  • Installing a second mysqld server does not work when one server is running

    This can happen when you have an existing MySQL installation, but want to put a new installation in a different location. For example, you might have a production installation, but you want to create a second installation for testing purposes. Generally the problem that occurs when you try to run a second server is that it tries to use a network interface that is in use by the first server. In this case, you should see one of the following error messages:

    Can't start server: Bind on TCP/IP port:Address already in useCan't start server: Bind on unix socket...

    For instructions on setting up multiple servers, see Section 5.3, "Running Multiple MySQL Instances on One Machine".

  • You do not have write access to the /tmp directory

    If you do not have write access to create temporary files or a Unix socket file in the default location (the /tmp directory) or the TMP_DIR environment variable, if it has been set, an error occurs when you run mysql_install_db or the mysqld server.

    You can specify different locations for the temporary directory and Unix socket file by executing these commands prior to starting mysql_install_db or mysqld, where some_tmp_dir is the full path name to some directory for which you have write permission:

    shell> TMPDIR=/some_tmp_dir/shell> MYSQL_UNIX_PORT=/some_tmp_dir/mysql.sockshell> export TMPDIR MYSQL_UNIX_PORT

    Then you should be able to run mysql_install_db and start the server with these commands:

    shell> scripts/mysql_install_db --user=mysqlshell> bin/mysqld_safe --user=mysql &

    If mysql_install_db is located in the scripts directory, modify the first command to scripts/mysql_install_db.

    See Section C.5.4.5, "How to Protect or Change the MySQL Unix Socket File", and Section 2.13, "Environment Variables".

There are some alternatives to running the mysql_install_db script provided in the MySQL distribution:

  • If you want the initial privileges to be different from the standard defaults, you can modify mysql_install_db before you run it. However, it is preferable to use GRANT and REVOKE to change the privileges after the grant tables have been set up. In other words, you can run mysql_install_db, and then use mysql -u root mysql to connect to the server as the MySQL root user so that you can issue the necessary GRANT and REVOKE statements.

    If you want to install MySQL on several machines with the same privileges, you can put the GRANT and REVOKE statements in a file and execute the file as a script using mysql after running mysql_install_db. For example:

    shell> scripts/mysql_install_db --user=mysqlshell> bin/mysql -u root < your_script_file

    By doing this, you can avoid having to issue the statements manually on each machine.

  • It is possible to re-create the grant tables completely after they have previously been created. You might want to do this if you are just learning how to use GRANT and REVOKE and have made so many modifications after running mysql_install_db that you want to wipe out the tables and start over.

    To re-create the grant tables, remove all the .frm, .MYI, and .MYD files in the mysql database directory. Then run the mysql_install_db script again.

  • You can start mysqld manually using the --skip-grant-tables option and add the privilege information yourself using mysql:

    shell> bin/mysqld_safe --user=mysql --skip-grant-tables &shell> bin/mysql mysql

    From mysql, manually execute the SQL commands contained in mysql_install_db. Make sure that you run mysqladmin flush-privileges or mysqladmin reload afterward to tell the server to reload the grant tables.

    Note that by not using mysql_install_db, you not only have to populate the grant tables manually, you also have to create them first.

2.11.1.2. Starting and Stopping MySQL Automatically

Generally, you start the mysqld server in one of these ways:

The mysqld_safe and mysql.server scripts, Windows server, Solaris/OpenSolaris SMF, and the Mac OS X Startup Item (or MySQL Preference Pane) can be used to start the server manually, or automatically at system startup time. mysql.server and the Startup Item also can be used to stop the server.

To start or stop the server manually using the mysql.server script, invoke it with start or stop arguments:

shell> mysql.server startshell> mysql.server stop

Before mysql.server starts the server, it changes location to the MySQL installation directory, and then invokes mysqld_safe. If you want the server to run as some specific user, add an appropriate user option to the [mysqld] group of the /etc/my.cnf option file, as shown later in this section. (It is possible that you will need to edit mysql.server if you've installed a binary distribution of MySQL in a nonstandard location. Modify it to change location into the proper directory before it runs mysqld_safe. If you do this, your modified version of mysql.server may be overwritten if you upgrade MySQL in the future, so you should make a copy of your edited version that you can reinstall.)

mysql.server stop stops the server by sending a signal to it. You can also stop the server manually by executing mysqladmin shutdown.

To start and stop MySQL automatically on your server, you need to add start and stop commands to the appropriate places in your /etc/rc* files.

If you use the Linux server RPM package (MySQL-server-VERSION.rpm), or a native Linux package installation, the mysql.server script may be installed in the /etc/init.d directory with the name mysql. See Section 2.5.1, "Installing MySQL from RPM Packages on Linux", for more information on the Linux RPM packages.

Some vendors provide RPM packages that install a startup script under a different name such as mysqld.

If you install MySQL from a source distribution or using a binary distribution format that does not install mysql.server automatically, you can install it manually. The script can be found in the support-files directory under the MySQL installation directory or in a MySQL source tree.

To install mysql.server manually, copy it to the /etc/init.d directory with the name mysql, and then make it executable. Do this by changing location into the appropriate directory where mysql.server is located and executing these commands:

shell> cp mysql.server /etc/init.d/mysqlshell> chmod +x /etc/init.d/mysql
Note

Older Red Hat systems use the /etc/rc.d/init.d directory rather than /etc/init.d. Adjust the preceding commands accordingly. Alternatively, first create /etc/init.d as a symbolic link that points to /etc/rc.d/init.d:

shell> cd /etcshell> ln -s rc.d/init.d .

After installing the script, the commands needed to activate it to run at system startup depend on your operating system. On Linux, you can use chkconfig:

shell> chkconfig --add mysql

On some Linux systems, the following command also seems to be necessary to fully enable the mysql script:

shell> chkconfig --level 345 mysql on

On FreeBSD, startup scripts generally should go in /usr/local/etc/rc.d/. The rc(8) manual page states that scripts in this directory are executed only if their basename matches the *.sh shell file name pattern. Any other files or directories present within the directory are silently ignored. In other words, on FreeBSD, you should install the mysql.server script as /usr/local/etc/rc.d/mysql.server.sh to enable automatic startup.

As an alternative to the preceding setup, some operating systems also use /etc/rc.local or /etc/init.d/boot.local to start additional services on startup. To start up MySQL using this method, you could append a command like the one following to the appropriate startup file:

/bin/sh -c 'cd /usr/local/mysql; ./bin/mysqld_safe --user=mysql &'

For other systems, consult your operating system documentation to see how to install startup scripts.

You can add options for mysql.server in a global /etc/my.cnf file. A typical /etc/my.cnf file might look like this:

[mysqld]datadir=/usr/local/mysql/varsocket=/var/tmp/mysql.sockport=3306user=mysql[mysql.server]basedir=/usr/local/mysql

The mysql.server script supports the following options: basedir, datadir, and pid-file. If specified, they must be placed in an option file, not on the command line. mysql.server supports only start and stop as command-line arguments.

The following table shows which option groups the server and each startup script read from option files.

Table 2.15. MySQL Startup scripts and supported server option groups

ScriptOption Groups
mysqld[mysqld], [server], [mysqld-major_version]
mysqld_safe[mysqld], [server], [mysqld_safe]
mysql.server[mysqld], [mysql.server],[server]

[mysqld-major_version] means that groups with names like [mysqld-5.1] and [mysqld-5.5] are read by servers having versions 5.1.x, 5.5.x, and so forth. This feature can be used to specify options that can be read only by servers within a given release series.

For backward compatibility, mysql.server also reads the [mysql_server] group and mysqld_safe also reads the [safe_mysqld] group. However, you should update your option files to use the [mysql.server] and [mysqld_safe] groups instead when using MySQL 5.5.

For more information on MySQL configuration files and their structure and contents, see Section 4.2.3.3, "Using Option Files".

2.11.1.3. Starting and Troubleshooting the MySQL Server

This section provides troubleshooting suggestions for problems starting the server on Unix. If you are using Windows, see Section 2.3.8, "Troubleshooting a Microsoft Windows MySQL Server Installation".

If you have problems starting the server, here are some things to try:

  • Check the error log to see why the server does not start.

  • Specify any special options needed by the storage engines you are using.

  • Make sure that the server knows where to find the data directory.

  • Make sure that the server can access the data directory. The ownership and permissions of the data directory and its contents must be set such that the server can read and modify them.

  • Verify that the network interfaces the server wants to use are available.

Some storage engines have options that control their behavior. You can create a my.cnf file and specify startup options for the engines that you plan to use. If you are going to use storage engines that support transactional tables (InnoDB, NDB), be sure that you have them configured the way you want before starting the server:

If you are using InnoDB tables, see Section 14.3.2, "Configuring InnoDB".

Storage engines will use default option values if you specify none, but it is recommended that you review the available options and specify explicit values for those for which the defaults are not appropriate for your installation.

When the mysqld server starts, it changes location to the data directory. This is where it expects to find databases and where it expects to write log files. The server also writes the pid (process ID) file in the data directory.

The data directory location is hardwired in when the server is compiled. This is where the server looks for the data directory by default. If the data directory is located somewhere else on your system, the server will not work properly. You can determine what the default path settings are by invoking mysqld with the --verbose and --help options.

If the default locations do not match the MySQL installation layout on your system, you can override them by specifying options to mysqld or mysqld_safe on the command line or in an option file.

To specify the location of the data directory explicitly, use the --datadir option. However, normally you can tell mysqld the location of the base directory under which MySQL is installed and it looks for the data directory there. You can do this with the --basedir option.

To check the effect of specifying path options, invoke mysqld with those options followed by the --verbose and --help options. For example, if you change location into the directory where mysqld is installed and then run the following command, it shows the effect of starting the server with a base directory of /usr/local:

shell> ./mysqld --basedir=/usr/local --verbose --help

You can specify other options such as --datadir as well, but --verbose and --help must be the last options.

Once you determine the path settings you want, start the server without --verbose and --help.

If mysqld is currently running, you can find out what path settings it is using by executing this command:

shell> mysqladmin variables

Or:

shell> mysqladmin -h host_name variables

host_name is the name of the MySQL server host.

If you get Errcode 13 (which means Permission denied) when starting mysqld, this means that the privileges of the data directory or its contents do not permit server access. In this case, you change the permissions for the involved files and directories so that the server has the right to use them. You can also start the server as root, but this raises security issues and should be avoided.

On Unix, change location into the data directory and check the ownership of the data directory and its contents to make sure the server has access. For example, if the data directory is /usr/local/mysql/var, use this command:

shell> ls -la /usr/local/mysql/var

If the data directory or its files or subdirectories are not owned by the login account that you use for running the server, change their ownership to that account. If the account is named mysql, use these commands:

shell> chown -R mysql /usr/local/mysql/varshell> chgrp -R mysql /usr/local/mysql/var

If it possible that even with correct ownership, MySQL may fail to start up if there is other security software running on your system that manages application access to various parts of the file system. In this case, you may need to reconfigure that software to enable mysqld to access the directories it uses during normal operation.

If the server fails to start up correctly, check the error log. Log files are located in the data directory (typically C:\Program Files\MySQL\MySQL Server 5.5\data on Windows, /usr/local/mysql/data for a Unix binary distribution, and /usr/local/var for a Unix source distribution). Look in the data directory for files with names of the form host_name.err and host_name.log, where host_name is the name of your server host. Then examine the last few lines of these files. On Unix, you can use tail to display them:

shell> tail host_name.errshell> tail host_name.log

The error log should contain information that indicates why the server could not start.

If either of the following errors occur, it means that some other program (perhaps another mysqld server) is using the TCP/IP port or Unix socket file that mysqld is trying to use:

Can't start server: Bind on TCP/IP port: Address already in useCan't start server: Bind on unix socket...

Use ps to determine whether you have another mysqld server running. If so, shut down the server before starting mysqld again. (If another server is running, and you really want to run multiple servers, you can find information about how to do so in Section 5.3, "Running Multiple MySQL Instances on One Machine".)

If no other server is running, try to execute the command telnet your_host_name tcp_ip_port_number. (The default MySQL port number is 3306.) Then press Enter a couple of times. If you do not get an error message like telnet: Unable to connect to remote host: Connection refused, some other program is using the TCP/IP port that mysqld is trying to use. You will need to track down what program this is and disable it, or else tell mysqld to listen to a different port with the --port option. In this case, you will also need to specify the port number for client programs when connecting to the server using TCP/IP.

Another reason the port might be inaccessible is that you have a firewall running that blocks connections to it. If so, modify the firewall settings to permit access to the port.

If the server starts but you cannot connect to it, you should make sure that you have an entry in /etc/hosts that looks like this:

127.0.0.1   localhost

If you cannot get mysqld to start, you can try to make a trace file to find the problem by using the --debug option. See MySQL Internals: Porting to Other Systems.

2.11.2. Securing the Initial MySQL Accounts

Part of the MySQL installation process is to set up the mysql database that contains the grant tables:

The mysql.user grant table defines the initial MySQL user accounts and their access privileges:

  • Some accounts have the user name root. These are superuser accounts that have all privileges and can do anything. The initial root account passwords are empty, so anyone can connect to the MySQL server as root without a password and be granted all privileges.

    • On Windows, root accounts are created that permit connections from the local host only. Connections can be made by specifying the host name localhost, the IP address 127.0.0.1, or the IPv6 address ::1. If the user selects the Enable root access from remote machines option during installation, the Windows installer creates another root account that permits connections from any host.

    • On Unix, each root account permits connections from the local host. Connections can be made by specifying the host name localhost, the IP address 127.0.0.1, the IPv6 address ::1, or the actual host name or IP address.

    An attempt to connect to the host 127.0.0.1 normally resolves to the localhost account. However, this fails if the server is run with the --skip-name-resolve option, so the 127.0.0.1 account is useful in that case. The ::1 account is used for IPv6 connections.

  • Some accounts are for anonymous users. These have an empty user name. The anonymous accounts have no password, so anyone can use them to connect to the MySQL server.

    • On Windows, there is one anonymous account that permits connections from the local host. Connections can be made by specifying a host name of localhost.

    • On Unix, each anonymous account permits connections from the local host. Connections can be made by specifying a host name of localhost for one of the accounts, or the actual host name or IP address for the other.

To display which accounts exist in the mysql.user table and check whether their passwords are empty, use the following statement:

mysql> SELECT User, Host, Password FROM mysql.user;+------+--------------------+----------+| User | Host   | Password |+------+--------------------+----------+| root | localhost  |  || root | myhost.example.com |  || root | 127.0.0.1  |  || root | ::1 |  ||  | localhost  |  ||  | myhost.example.com |  |+------+--------------------+----------+

This output indicates that there are several root and anonymous-user accounts, none of which have passwords. The output might differ on your system, but the presence of accounts with empty passwords means that your MySQL installation is unprotected until you do something about it:

  • You should assign a password to each MySQL root account.

  • If you want to prevent clients from connecting as anonymous users without a password, you should either assign a password to each anonymous account or else remove the accounts.

In addition, the mysql.db table contains rows that permit all accounts to access the test database and other databases with names that start with test_. This is true even for accounts that otherwise have no special privileges such as the default anonymous accounts. This is convenient for testing but inadvisable on production servers. Administrators who want database access restricted only to accounts that have permissions granted explicitly for that purpose should remove these mysql.db table rows.

The following instructions describe how to set up passwords for the initial MySQL accounts, first for the root accounts, then for the anonymous accounts. The instructions also cover how to remove the anonymous accounts, should you prefer not to permit anonymous access at all, and describe how to remove permissive access to test databases. Replace newpwd in the examples with the password that you want to use. Replace host_name with the name of the server host. You can determine this name from the output of the preceding SELECT statement. For the output shown, host_name is myhost.example.com.

Note

For additional information about setting passwords, see Section 6.3.5, "Assigning Account Passwords". If you forget your root password after setting it, see Section C.5.4.1, "How to Reset the Root Password".

You might want to defer setting the passwords until later, to avoid the need to specify them while you perform additional setup or testing. However, be sure to set them before using your installation for production purposes.

To set up additional accounts, see Section 6.3.2, "Adding User Accounts".

Assigning root Account Passwords

The root account passwords can be set several ways. The following discussion demonstrates three methods:

To assign passwords using SET PASSWORD, connect to the server as root and issue a SET PASSWORD statement for each root account listed in the mysql.user table. Be sure to encrypt the password using the PASSWORD() function.

For Windows, do this:

shell> mysql -u rootmysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');mysql> SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('newpwd');mysql> SET PASSWORD FOR 'root'@'::1' = PASSWORD('newpwd');mysql> SET PASSWORD FOR 'root'@'%' = PASSWORD('newpwd');

The last statement is unnecessary if the mysql.user table has no root account with a host value of %.

For Unix, do this:

shell> mysql -u rootmysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');mysql> SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('newpwd');mysql> SET PASSWORD FOR 'root'@'::1' = PASSWORD('newpwd');mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');

You can also use a single statement that assigns a password to all root accounts by using UPDATE to modify the mysql.user table directly. This method works on any platform:

shell> mysql -u rootmysql> UPDATE mysql.user SET Password = PASSWORD('newpwd') -> WHERE User = 'root';mysql> FLUSH PRIVILEGES;

The FLUSH statement causes the server to reread the grant tables. Without it, the password change remains unnoticed by the server until you restart it.

To assign passwords to the root accounts using mysqladmin, execute the following commands:

shell> mysqladmin -u root password "newpwd"shell> mysqladmin -u root -h host_name password "newpwd"

Those commands apply both to Windows and to Unix. The double quotation marks around the password are not always necessary, but you should use them if the password contains spaces or other characters that are special to your command interpreter.

The mysqladmin method of setting the root account passwords does not work for the 'root'@'127.0.0.1' or 'root'@'::1' account. Use the SET PASSWORD method shown earlier.

After the root passwords have been set, you must supply the appropriate password whenever you connect as root to the server. For example, to shut down the server with mysqladmin, use this command:

shell> mysqladmin -u root -p shutdownEnter password: (enter root password here)

Assigning Anonymous Account Passwords

The mysql commands in the following instructions include a -p option based on the assumption that you have set the root account passwords using the preceding instructions and must specify that password when connecting to the server.

To assign passwords to the anonymous accounts, connect to the server as root, then use either SET PASSWORD or UPDATE. Be sure to encrypt the password using the PASSWORD() function.

To use SET PASSWORD on Windows, do this:

shell> mysql -u root -pEnter password: (enter root password here)mysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');

To use SET PASSWORD on Unix, do this:

shell> mysql -u root -pEnter password: (enter root password here)mysql> SET PASSWORD FOR ''@'localhost' = PASSWORD('newpwd');mysql> SET PASSWORD FOR ''@'host_name' = PASSWORD('newpwd');

To set the anonymous-user account passwords with a single UPDATE statement, do this (on any platform):

shell> mysql -u root -pEnter password: (enter root password here)mysql> UPDATE mysql.user SET Password = PASSWORD('newpwd') -> WHERE User = '';mysql> FLUSH PRIVILEGES;

The FLUSH statement causes the server to reread the grant tables. Without it, the password change remains unnoticed by the server until you restart it.

Removing Anonymous Accounts

If you prefer to remove any anonymous accounts rather than assigning them passwords, do so as follows on Windows:

shell> mysql -u root -pEnter password: (enter root password here)mysql> DROP USER ''@'localhost';

On Unix, remove the anonymous accounts like this:

shell> mysql -u root -pEnter password: (enter root password here)mysql> DROP USER ''@'localhost';mysql> DROP USER ''@'host_name';

Securing Test Databases

By default, the mysql.db table contains rows that permit access by any user to the test database and other databases with names that start with test_. (These rows have an empty User column value, which for access-checking purposes matches any user name.) This means that such databases can be used even by accounts that otherwise possess no privileges. If you want to remove any-user access to test databases, do so as follows:

shell> mysql -u root -pEnter password: (enter root password here)mysql> DELETE FROM mysql.db WHERE Db LIKE 'test%';mysql> FLUSH PRIVILEGES;

The FLUSH statement causes the server to reread the grant tables. Without it, the privilege change remains unnoticed by the server until you restart it.

With the preceding change, only users who have global database privileges or privileges granted explicitly for the test database can use it. However, if you do not want the database to exist at all, drop it:

mysql> DROP DATABASE test;
Note

On Windows, you can also perform the process described in this section using the Configuration Wizard (see Section 2.3.6.11, "The Security Options Dialog"). On other platforms, the MySQL distribution includes mysql_secure_installation, a command-line utility that automates much of the process of securing a MySQL installation.

2.12. Upgrading or Downgrading MySQL

2.12.1. Upgrading MySQL

As a general rule, to upgrade from one release series to another, go to the next series rather than skipping a series. To upgrade from a release series previous to MySQL 5.1, upgrade to each successive release series in turn until you have reached MySQL 5.1, and then proceed with the upgrade to MySQL 5.5. 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 5.5, and so forth. For information on upgrading to MySQL 5.1, see the MySQL 5.1 Reference Manual.

There is a special case for upgrading to MySQL 5.5, which is that there was a short-lived MySQL 5.4 development series. This series is no longer being worked on, but to accommodate users of both series, this section includes one subsection for users upgrading from MySQL 5.1 to 5.5 and another for users upgrading from MySQL 5.4 to 5.5.

To upgrade to MySQL 5.5, use the items in the following checklist as a guide:

  • Before any upgrade, back up your databases, including the mysql database that contains the grant tables. See Section 7.2, "Database Backup Methods".

  • Read all the notes in Section 2.12.1.1, "Upgrading from MySQL 5.1 to 5.5", or Section 2.12.1.2, "Upgrading from MySQL 5.4 to 5.5", depending on whether you currently use MySQL 5.1 or 5.4. These notes enable you to identify upgrade issues that apply to your current MySQL installation. Some incompatibilities discussed in that section require your attention before upgrading. Others should be dealt with after upgrading.

  • Read the Release Notes as well, which provide information about features that are new in MySQL 5.5 or differ from from those found in earlier MySQL releases.

  • After upgrading to a new version of MySQL, run mysql_upgrade (see Section 4.4.7, "mysql_upgrade - Check and Upgrade MySQL Tables"). This program checks your tables, and attempts to repair them if necessary. It also updates your grant tables to make sure that they have the current structure so that you can take advantage of any new capabilities. (Some releases of MySQL introduce changes to the structure of the grant tables to add new privileges or features.)

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

  • If you run MySQL Server on Windows, see Section 2.3.9, "Upgrading MySQL on Windows".

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

  • If you upgrade an installation originally produced by installing multiple RPM packages, it is best to 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.

  • 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 Section 9.2.4, "Function Name Parsing and Resolution", for the rules describing how the server interprets references to different kinds of functions.

For upgrades between versions of a MySQL release series that has reached General Availability status, you can move the MySQL format files and data files between different versions on systems with the same architecture. For upgrades to a version of a MySQL release series that is in development status, that is not necessarily true. Use of development releases is at your own risk.

If you are cautious about using new versions, you can always rename your old mysqld before installing a newer one. For example, if you are using a version of MySQL 5.1 and want to upgrade to 5.5, rename your current server from mysqld to mysqld-5.1. If your new mysqld then does something unexpected, you can simply shut it down and restart with your old mysqld.

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, you should 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 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.

It is a good idea to rebuild and reinstall the Perl DBD::mysql module whenever you install a new release of MySQL. The same applies to other MySQL interfaces as well, such as PHP mysql extensions and the Python MySQLdb module.

2.12.1.1. Upgrading from MySQL 5.1 to 5.5

Note

It is good practice to back up your data before installing any new version of software. Although MySQL works very hard to ensure a high level of quality, you should protect your data by making a backup.

To upgrade to 5.5 from any previous version, MySQL recommends that you dump your tables with mysqldump before upgrading and reload the dump file after upgrading. Use the --all-databases option to include all databases in the dump. If your databases include stored programs, use the --routines and --events options as well.

In general, you should do the following when upgrading from MySQL 5.1 to 5.5:

  • Read all the items in these sections to see whether any of them might affect your applications:

    • Section 2.12.1, "Upgrading MySQL", has general update information.

    • The items in the change lists provided later in this section enable you to identify upgrade issues that apply to your current MySQL installation. Some incompatibilities discussed there require your attention before upgrading. Others should be dealt with after upgrading.

    • The MySQL 5.5 Release Notes describe significant new features you can use in 5.5 or that differ from those found in earlier MySQL releases. Some of these changes may result in incompatibilities.

    Note particularly any changes that are marked Known issue or Incompatible change. These incompatibilities with earlier versions of MySQL 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 2.12.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 Section 13.7.2.5, "REPAIR TABLE Syntax".

  • Before upgrading to a new version of MySQL, Section 2.12.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 so and these changes result in an incompatibility between MySQL versions, you will need to upgrade the affected tables using the instructions in Section 2.12.4, "Rebuilding or Repairing Tables or Indexes".

  • After upgrading to a new version of MySQL, run mysql_upgrade (see Section 4.4.7, "mysql_upgrade - Check and Upgrade MySQL Tables"). This program checks your tables, and attempts to repair them if necessary. It also updates your grant tables to make sure that they have the current structure so that you can take advantage of any new capabilities. (Some releases of MySQL introduce changes to the structure of the grant tables to add new privileges or features.)

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

  • If you run MySQL Server on Windows, see Section 2.3.9, "Upgrading MySQL on Windows".

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

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.

The following lists describe changes that may affect applications and that you should watch out for when upgrading from MySQL 5.1 to 5.5.

Configuration Changes
  • 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-innodbplugin-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 Section 23.2.5, "MySQL Services for Plugins".

Server Changes
  • 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 tbl_list WITH READ LOCK, 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:

    LOCK TABLES tbl_list READ;FLUSH TABLES tbl_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:

    shell> mysqld --skip-grant-tables &shell> 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):

    shell> mysqld --defaults-file=/usr/local/mysql/etc/my.cnf --skip-grant-tables &shell> 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.

    Note

    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 table_name for such tables instead.

  • 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:

    shell> mysqladmin flush-logsshell> mv host_name.err-old backup-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:

    shell> mv host_name.err host_name.err-oldshell> mysqladmin flush-logsshell> mv host_name.err-old backup-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:

    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 Section 11.2.6, "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(N) columns with a MySQL 5.5 or later server:

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

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

    • When trying replicate any CREATE TABLE or ALTER TABLE statement containing TIMESTAMP(N) from a master MySQL server that supports the TIMESTAMP(N) syntax to a MySQL 5.5.3 or newer slave, the statement causes replication to fail. Similarly, when you try to restore from a binary log written by a server that supports TIMESTAMP(N) to a MySQL 5.5.3 or newer server, any CREATE TABLE or ALTER TABLE statement containing TIMESTAMP(N) causes the backup to fail. This holds true regardless of the logging format.

      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 Section 10.1.10, "Unicode Support", and Section 10.1.11, "Upgrading from Previous to Current Unicode Support".

  • 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 Section 12.2, "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 Section 10.2, "Setting the Error Message Language", and Section 10.1.6, "Character Set for Error Messages".

SQL Changes
  • 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 a2WHERE 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 a2WHERE 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 Section 9.3, "Reserved Words".

2.12.1.2. Upgrading from MySQL 5.4 to 5.5

This section is for the special case of upgrading to MySQL 5.5 from the short-lived MySQL 5.4 development series, which is no longer being worked on.

Note

It is good practice to back up your data before installing any new version of software. Although MySQL works very hard to ensure a high level of quality, you should protect your data by making a backup.

To upgrade to 5.5 from any previous version, MySQL recommends that you dump your tables with mysqldump before upgrading and reload the dump file after upgrading. Use the --all-databases option to include all databases in the dump. If your databases include stored programs, use the --routines and --events options as well.

In general, you should do the following when upgrading from MySQL 5.4 to 5.5:

  • Read all the items in these sections to see whether any of them might affect your applications:

    • Section 2.12.1, "Upgrading MySQL", has general update information.

    • The items in the change lists provided later in this section enable you to identify upgrade issues that apply to your current MySQL installation. Some incompatibilities discussed there require your attention before upgrading. Others should be dealt with after upgrading.

    • The MySQL 5.5 Release Notes describe significant new features you can use in 5.5 or that differ from those found in earlier MySQL releases. Some of these changes may result in incompatibilities.

    Note particularly any changes that are marked Known issue or Incompatible change. These incompatibilities with earlier versions of MySQL 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 2.12.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 Section 13.7.2.5, "REPAIR TABLE Syntax".

  • Before upgrading to a new version of MySQL, Section 2.12.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 so and these changes result in an incompatibility between MySQL versions, you will need to upgrade the affected tables using the instructions in Section 2.12.4, "Rebuilding or Repairing Tables or Indexes".

  • After upgrading to a new version of MySQL, run mysql_upgrade (see Section 4.4.7, "mysql_upgrade - Check and Upgrade MySQL Tables"). This program checks your tables, and attempts to repair them if necessary. It also updates your grant tables to make sure that they have the current structure so that you can take advantage of any new capabilities. (Some releases of MySQL introduce changes to the structure of the grant tables to add new privileges or features.)

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

  • If you run MySQL Server on Windows, see Section 2.3.9, "Upgrading MySQL on Windows".

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

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.

The following lists describe changes that may affect applications and that you should watch out for when upgrading from MySQL 5.4 to 5.5.

Configuration Changes
  • 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 Section 23.2.5, "MySQL Services for Plugins".

Server Changes
  • 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 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:

    shell> mysqld --skip-grant-tables &shell> 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):

    shell> mysqld --defaults-file=/usr/local/mysql/etc/my.cnf --skip-grant-tables &shell> 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.

  • 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 Section 10.1.10, "Unicode Support", and Section 10.1.11, "Upgrading from Previous to Current Unicode Support".

  • 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/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 Section 12.2, "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 messags returned previously.

    For more information, see Section 10.2, "Setting the Error Message Language", and Section 10.1.6, "Character Set for Error Messages".

  • Before MySQL 5.1.36, plugin options were boolean options (see Section 4.2.3.2, "Program Option Modifiers"). If you upgrade to MySQL 5.5 from a version older than 5.1.36 and previously used options of the form --plugin_name=0 or --plugin_name=1, the equivalent options are now --plugin_name=OFF and --plugin_name=ON, respectively. You also have the choice of requiring plugins to start successfully by using --plugin_name=FORCE or --plugin_name=FORCE_PLUS_PERMANENT.

SQL Changes
  • 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.

  • Some keywords may be reserved in MySQL 5.5 that were not reserved in MySQL 5.4. See Section 9.3, "Reserved Words".

2.12.2. Downgrading MySQL

This section describes what you should do to downgrade to an older MySQL version in the unlikely case that the previous version worked better than the new one.

If you are downgrading within the same release series (for example, from 5.1.13 to 5.1.12) the general rule is that you just have to install the new binaries on top of the old ones. There is no need to do anything with the databases. As always, however, it is always a good idea to make a backup.

The following items form a checklist of things you should do whenever you perform a downgrade:

In most cases, you can move the MySQL format files and data files between different versions on the same architecture as long as you stay within versions for the same release series of MySQL.

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 2.12.5, "Copying MySQL Databases to Another Machine".

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

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

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

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

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

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

It might also be the case that system tables in the mysql database have changed and that downgrading introduces some loss of functionality or requires some adjustments. Here are some examples:

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

  • Triggers were added in MySQL 5.0, so if you downgrade from 5.0 to 4.1, you cannot use triggers at all.

  • The mysql.proc.comment column definition changed between MySQL 5.1 and 5.5. After a downgrade from 5.5 to 5.1, this table is seen as corrupt and in need of repair. To workaround this problem, execute mysql_upgrade from the version of MySQL to which you downgraded.

2.12.2.1. Downgrading to MySQL 5.1

When downgrading to MySQL 5.1 from MySQL 5.5, you should keep in mind the following issues relating to features found in MySQL 5.5, but not in MySQL 5.1:

  • 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.

2.12.2.2. Downgrading from MySQL Enterprise Edition to MySQL Community Server

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

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

Note

The issues described in this section are in addition to any that may be encountered as a result of any upgrade or downgrade of the MySQL Server version (such as between MySQL 5.5 and 5.1). Information about upgrading and downgrading between MySQL release series can be found elsewhere in this chapter; see Section 2.12.1, "Upgrading MySQL", and Section 2.12.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 Section 6.3, "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 Section 6.3, "MySQL User Account Management", for more information.

  • MySQL Enterprise Scalability (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 perfomance metrics as well as all trending data are lost.

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

2.12.3. Checking Whether Tables or Indexes Must Be Rebuilt

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

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

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

  3. Start the server for the new version.

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

Table Incompatibilities

After a binary upgrade to MySQL 5.1 from a MySQL 5.0 installation that contains ARCHIVE tables, 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.

Index Incompatibilities

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 Section 14.3.15, "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 2.12.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 and 5.4.0, so it applies to upgrades from versions older than 5.1.24 to 5.1.24 or newer, and to downgrades from 5.1.24 or newer to versions older than 5.1.24.

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

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

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

These changes cause index rebuilding to be necessary:

  • MySQL 5.1.24, 5.4.0 (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, 5.4.0 (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, 5.4.0 (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, 5.4.0 (see Bug #39585).

2.12.4. Rebuilding or Repairing Tables or Indexes

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

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

Note

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

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

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

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

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

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

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

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

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

mysql> ALTER TABLE t1 ENGINE = MyISAM;

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

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

mysql> REPAIR TABLE t1;

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

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

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

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

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

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

    ALTER TABLE t1CONVERT 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 t1MODIFY 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.

2.12.5. Copying MySQL Databases to Another Machine

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2.13. Environment Variables

This section lists all the environment variables that are used directly or indirectly by MySQL. Most of these can also be found in other places in this manual.

Note that any options on the command line take precedence over values specified in option files and environment variables, and values in option files take precedence over values in environment variables.

In many cases, it is preferable to use an option file instead of environment variables to modify the behavior of MySQL. See Section 4.2.3.3, "Using Option Files".

VariableDescription
CXXThe name of your C++ compiler (for running CMake).
CCThe name of your C compiler (for running CMake).
CFLAGSFlags for your C compiler (for running CMake).
CXXFLAGSFlags for your C++ compiler (for running CMake).
DBI_USERThe default user name for Perl DBI.
DBI_TRACETrace options for Perl DBI.
HOMEThe default path for the mysql history file is $HOME/.mysql_history.
LD_RUN_PATHUsed to specify the location of libmysqlclient.so.
LIBMYSQL_ENABLE_CLEARTEXT_PLUGINEnable mysql_clear_password authentication plugin; see Section 6.3.6.4, "The Cleartext Client-Side Authentication Plugin".
MYSQL_DEBUGDebug trace options when debugging.
MYSQL_GROUP_SUFFIXOption group suffix value (like specifying --defaults-group-suffix).
MYSQL_HISTFILEThe path to the mysql history file. If this variable is set, its value overrides the default for $HOME/.mysql_history.
MYSQL_HOMEThe path to the directory in which the server-specific my.cnf file resides.
MYSQL_HOSTThe default host name used by the mysql command-line client.
MYSQL_PS1The command prompt to use in the mysql command-line client.
MYSQL_PWDThe default password when connecting to mysqld. Note that using this is insecure. See Section 6.1.2.1, "End-User Guidelines for Password Security".
MYSQL_TCP_PORTThe default TCP/IP port number.
MYSQL_UNIX_PORTThe default Unix socket file name; used for connections to localhost.
PATHUsed by the shell to find MySQL programs.
TMPDIRThe directory where temporary files are created.
TZThis should be set to your local time zone. See Section C.5.4.6, "Time Zone Problems".
UMASKThe user-file creation mode when creating files. See note following table.
UMASK_DIRThe user-directory creation mode when creating directories. See note following table.
USERThe default user name on Windows when connecting tomysqld.

For information about the mysql history file, see Section 4.5.1.3, "mysql History File".

The UMASK and UMASK_DIR variables, despite their names, are used as modes, not masks:

  • If UMASK is set, mysqld uses ($UMASK | 0600) as the mode for file creation, so that newly created files have a mode in the range from 0600 to 0666 (all values octal).

  • If UMASK_DIR is set, mysqld uses ($UMASK_DIR | 0700) as the base mode for directory creation, which then is AND-ed with ~(~$UMASK & 0666), so that newly created directories have a mode in the range from 0700 to 0777 (all values octal). The AND operation may remove read and write permissions from the directory mode, but not execute permissions.

MySQL assumes that the value for UMASK or UMASK_DIR is in octal if it starts with a zero.

2.14. Perl Installation Notes

The Perl DBI module provides a generic interface for database access. You can write a DBI script that works with many different database engines without change. To use DBI, you must install the DBI module, as well as a DataBase Driver (DBD) module for each type of database server you want to access. For MySQL, this driver is the DBD::mysql module.

Perl, and the DBD::MySQL module for DBI must be installed if you want to run the MySQL benchmark scripts; see Section 8.12.2, "The MySQL Benchmark Suite". They are also required for the MySQL Cluster ndb_size.pl utility; see Section 17.4.22, "ndb_size.pl - NDBCLUSTER Size Requirement Estimator".

Note

Perl support is not included with MySQL distributions. You can obtain the necessary modules from http://search.cpan.org for Unix, or by using the ActiveState ppm program on Windows. The following sections describe how to do this.

The DBI/DBD interface requires Perl 5.6.0, and 5.6.1 or later is preferred. DBI does not work if you have an older version of Perl. You should use DBD::mysql 4.009 or higher. Although earlier versions are available, they do not support the full functionality of MySQL 5.5.

2.14.1. Installing Perl on Unix

MySQL Perl support requires that you have installed MySQL client programming support (libraries and header files). Most installation methods install the necessary files. If you install MySQL from RPM files on Linux, be sure to install the developer RPM as well. The client programs are in the client RPM, but client programming support is in the developer RPM.

The files you need for Perl support can be obtained from the CPAN (Comprehensive Perl Archive Network) at http://search.cpan.org.

The easiest way to install Perl modules on Unix is to use the CPAN module. For example:

shell> perl -MCPAN -e shellcpan> install DBIcpan> install DBD::mysql

The DBD::mysql installation runs a number of tests. These tests attempt to connect to the local MySQL server using the default user name and password. (The default user name is your login name on Unix, and ODBC on Windows. The default password is "no password.") If you cannot connect to the server with those values (for example, if your account has a password), the tests fail. You can use force install DBD::mysql to ignore the failed tests.

DBI requires the Data::Dumper module. It may be installed; if not, you should install it before installing DBI.

It is also possible to download the module distributions in the form of compressed tar archives and build the modules manually. For example, to unpack and build a DBI distribution, use a procedure such as this:

  1. Unpack the distribution into the current directory:

    shell> gunzip < DBI-VERSION.tar.gz | tar xvf -

    This command creates a directory named DBI-VERSION.

  2. Change location into the top-level directory of the unpacked distribution:

    shell> cd DBI-VERSION
  3. Build the distribution and compile everything:

    shell> perl Makefile.PLshell> makeshell> make testshell> make install

The make test command is important because it verifies that the module is working. Note that when you run that command during the DBD::mysql installation to exercise the interface code, the MySQL server must be running or the test fails.

It is a good idea to rebuild and reinstall the DBD::mysql distribution whenever you install a new release of MySQL. This ensures that the latest versions of the MySQL client libraries are installed correctly.

If you do not have access rights to install Perl modules in the system directory or if you want to install local Perl modules, the following reference may be useful: http://servers.digitaldaze.com/extensions/perl/modules.html#modules

Look under the heading "Installing New Modules that Require Locally Installed Modules."

2.14.2. Installing ActiveState Perl on Windows

On Windows, you should do the following to install the MySQL DBD module with ActiveState Perl:

  1. Get ActiveState Perl from http://www.activestate.com/Products/ActivePerl/ and install it.

  2. Open a console window.

  3. If necessary, set the HTTP_proxy variable. For example, you might try a setting like this:

    C:\> set HTTP_proxy=my.proxy.com:3128
  4. Start the PPM program:

    C:\> C:\perl\bin\ppm.pl
  5. If you have not previously done so, install DBI:

    ppm> install DBI
  6. If this succeeds, run the following command:

    ppm> install DBD-mysql

This procedure should work with ActiveState Perl 5.6 or newer.

If you cannot get the procedure to work, you should install the ODBC driver instead and connect to the MySQL server through ODBC:

use DBI;$dbh= DBI->connect("DBI:ODBC:$dsn",$user,$password) ||  die "Got error $DBI::errstr when connecting to $dsn\n";

2.14.3. Problems Using the Perl DBI/DBDInterface

If Perl reports that it cannot find the ../mysql/mysql.so module, the problem is probably that Perl cannot locate the libmysqlclient.so shared library. You should be able to fix this problem by one of the following methods:

  • Copy libmysqlclient.so to the directory where your other shared libraries are located (probably /usr/lib or /lib).

  • Modify the -L options used to compile DBD::mysql to reflect the actual location of libmysqlclient.so.

  • On Linux, you can add the path name of the directory where libmysqlclient.so is located to the /etc/ld.so.conf file.

  • Add the path name of the directory where libmysqlclient.so is located to the LD_RUN_PATH environment variable. Some systems use LD_LIBRARY_PATH instead.

Note that you may also need to modify the -L options if there are other libraries that the linker fails to find. For example, if the linker cannot find libc because it is in /lib and the link command specifies -L/usr/lib, change the -L option to -L/lib or add -L/lib to the existing link command.

If you get the following errors from DBD::mysql, you are probably using gcc (or using an old binary compiled with gcc):

/usr/bin/perl: can't resolve symbol '__moddi3'/usr/bin/perl: can't resolve symbol '__divdi3'

Add -L/usr/lib/gcc-lib/... -lgcc to the link command when the mysql.so library gets built (check the output from make for mysql.so when you compile the Perl client). The -L option should specify the path name of the directory where libgcc.a is located on your system.

Another cause of this problem may be that Perl and MySQL are not both compiled with gcc. In this case, you can solve the mismatch by compiling both with gcc.

You may see the following error from DBD::mysql when you run the tests:

t/00base............install_driver(mysql) failed:Can't load '../blib/arch/auto/DBD/mysql/mysql.so' for module DBD::mysql:../blib/arch/auto/DBD/mysql/mysql.so: undefined symbol:uncompress at /usr/lib/perl5/5.00503/i586-linux/DynaLoader.pm line 169.

This means that you need to include the -lz compression library on the link line. That can be done by changing the following line in the file lib/DBD/mysql/Install.pm:

$sysliblist .= " -lm";

Change that line to:

$sysliblist .= " -lm -lz";

After this, you must run make realclean and then proceed with the installation from the beginning.

Copyright © 1997, 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices
(Sebelumnya) 2. Installing and Upgrading MySQL3. Tutorial (Berikutnya)