Table of Contents
Linux supports a number of different solutions for installing MySQL. The recommended method is to use one of the distributions from Oracle. If you choose this method, there are several options available:
Installing from a generic binary package in
.tar.gz format. See
Chapter 1, Installing MySQL on Unix/Linux Using Generic Binaries for more information.
Extracting and compiling MySQL from a source distribution. For detailed instructions, see Installing MySQL from Source.
Installing using a precompiled RPM package. For more information, see Section 2.1, “Installing MySQL on Linux Using RPM Packages”.
As an alternative, you can use the native package manager within your Linux distribution to automatically download and install MySQL for you. Native package installations can take care of the download and dependencies required to run MySQL, but the MySQL version will often be some versions behind the currently available release. You will also normally be unable to install development releases, as these are not usually made available in the native repository. For more information on using the native package installers, see Section 2.2, “Installing MySQL on Linux Using Native Package Managers”.
For many Linux installations, you will want to set up MySQL to be
started automatically when your machine starts. Many of the native
package installations perform this operation for you, but for
source, binary and RPM solutions you may need to set this up
separately. The required script, mysql.server,
can be found in the support-files directory
under the MySQL installation directory or in a MySQL source tree.
You can install it as /etc/init.d/mysql for
automatic MySQL startup and shutdown. See
mysql.server — MySQL Server Startup Script.
The recommended way to install MySQL on RPM-based Linux
distributions is by using the RPM packages. The RPMs that we
provide to the community should work on all versions of Linux that
support RPM packages and use glibc 2.3. To
obtain RPM packages, see How to Get MySQL.
For non-RPM Linux distributions, you can install MySQL using a
.tar.gz package. See
Chapter 1, Installing MySQL on Unix/Linux Using Generic Binaries.
Installations created from our Linux RPM distributions result in files under the system directories shown in the following table.
Table 2.1 MySQL Installation Layout for Linux RPM Packages
| Directory | Contents of Directory |
|---|---|
/usr/bin | Client programs and scripts |
/usr/sbin | The mysqld server |
/var/lib/mysql | Log files, databases |
/usr/share/info | MySQL manual in Info format |
/usr/share/man | Unix manual pages |
/usr/include/mysql | Include (header) files |
/usr/lib/mysql | Libraries |
/usr/share/mysql | Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation |
/usr/share/sql-bench | Benchmarks |
RPM distributions of MySQL are also provided by other vendors. Be aware that they may differ from those built by Oracle in features, capabilities, and conventions (including communication setup), and that the instructions in this manual do not necessarily apply to installing them. The vendor's instructions should be consulted instead. Because of these differences, RPM packages built by Oracle check whether such RPMs built by other vendors are installed. If so, the RPM does not install and produces a message explaining this.
Conflicts can arise when an RPM from another vendor is already
installed, such as when a vendor's conventions about which files
belong with the server and which belong with the client library
differ from the breakdown used for Oracle packages. In such
cases, attempts to install an Oracle RPM with rpm
-i may result in messages that files in the RPM to be
installed conflict with files from an installed package (denoted
mysql-libs in the following paragraphs).
Each MySQL release provides a
MySQL-shared-compat package that is meant to
replace mysql-libs and provides a
replacement-compatible client library for older MySQL series.
MySQL-shared-compat is set up to make
mysql-libs obsolete, but
rpm explicitly refuses to replace obsoleted
packages when invoked with -i (unlike
-U), which is why installation with
rpm -i produces a conflict.
MySQL-shared-compat can safely be installed
alongside mysql-libs because libraries are
installed to different locations. Therefore, it is possible to
install MySQL-shared-compat first, then
manually remove mysql-libs before continuing
with the installation. After mysql-libs is
removed, the dynamic linker stops looking for the client library
in the location where mysql-libs puts it, and
the library provided by the
MySQL-shared-compat package takes over.
Another alternative is to install packages using
yum. In a directory containing all RPM
packages for a MySQL release, yum install
MySQL*rpm installs them in the correct order and
removes mysql-libs in one step without
conflicts.
In most cases, you need install only the
MySQL-server and
MySQL-client packages to get a functional
standard MySQL installation. The other packages are not required
for a standard installation.
RPMs for MySQL Cluster.
Beginning with MySQL 5.1.24, standard MySQL server RPMs built by
MySQL no longer provide support for the
NDBCLUSTER storage engine. MySQL
Cluster users should check the MySQL Cluster Downloads page at
http://dev.mysql.com/downloads/cluster/ for RPMs that should
work with most Linux distributions for both of these release
series.
When upgrading a MySQL Cluster RPM installation, you must
upgrade all installed RPMs, including the
Server and Client RPMs.
For more information about installing MySQL Cluster from RPMs, see Installing MySQL Cluster from RPM.
For upgrades, if your installation was originally produced by installing multiple RPM packages, it is best to upgrade all the installed packages, not just some. For example, if you previously installed the server and client RPMs, do not upgrade just the server RPM.
The following list shows the available RPM packages. The names
shown here use a suffix of .glibc23.i386.rpm,
but particular packages can have different suffixes, described
later.
MySQL-server-
VERSION.glibc23.i386.rpm
The MySQL server. You need this unless you only want to connect to a MySQL server running on another machine.
MySQL-client-
VERSION.glibc23.i386.rpm
The standard MySQL client programs. You probably always want to install this package.
MySQL-devel-
VERSION.glibc23.i386.rpm
The libraries and include files needed to compile other MySQL clients, such as the Perl MySQL module. Install this RPM if you intend to compile C API applications.
MySQL-debuginfo-
VERSION.glibc23.i386.rpm
Debugging information. It is specific to Red Hat Enterprise
Linux. debuginfo RPMs are never needed to
use MySQL software; this is true both for the server and for
client programs. However, they contain additional information
that might be needed by a debugger to analyze a crash.
MySQL-shared-
VERSION.glibc23.i386.rpm
The shared libraries (libmysqlclient.so*)
that certain languages and applications need to dynamically
load and use MySQL. It contains single-threaded and
thread-safe libraries. Install this RPM if you intend to
compile or run C API applications that depend on the shared
client library. If you install this package, do not install
the MySQL-shared-compat package.
MySQL-shared-compat-
VERSION.glibc23.i386.rpm
The shared libraries for older releases, up to the current
release. It contains single-threaded and thread-safe
libraries. Install this package instead of
MySQL-shared if you have applications
installed that are dynamically linked against older versions
of MySQL but you want to upgrade to the current version
without breaking the library dependencies.
MySQL-shared-compat-advanced-gpl-,
VERSION.glibc23.i386.rpmMySQL-shared-compat-advanced-
VERSION.glibc23.i386.rpm
These are like the MySQL-shared-compat
package, but are for the “MySQL Enterprise Server
– Advanced Edition” products. Install these
packages rather than the normal
MySQL-shared-compat package if you want to
included shared client libraries for older MySQL versions.
MySQL-embedded-
VERSION.glibc23.i386.rpm
The embedded MySQL server library.
MySQL-ndb-management-,
VERSION.glibc23.i386.rpmMySQL-ndb-storage-,
VERSION.glibc23.i386.rpmMySQL-ndb-tools-,
VERSION.glibc23.i386.rpmMySQL-ndb-extra-
VERSION.glibc23.i386.rpm
Packages that contain additional files for MySQL Cluster installations.
The MySQL-ndb-tools RPM requires a
working installation of perl. Prior to MySQL 5.1.18, the
DBI and HTML::Template
packages were also required. See
Perl Installation Notes, and
ndb_size.pl — NDBCLUSTER Size Requirement Estimator, for
more information.
MySQL-test-
VERSION.glibc23.i386.rpm
The MySQL test suite.
MySQL-
VERSION.src.rpm
The source code for all of the previous packages. It can also be used to rebuild the RPMs on other architectures (for example, SPARC).
In RPM package names, the suffix (following the
VERSION value) has the following
syntax:
.PLATFORM.CPU.rpm
The PLATFORM and
CPU values indicate the type of system
for which the package is built.
PLATFORM indicates the platform and
CPU indicates the processor type or
family.
All packages are dynamically linked against
glibc 2.3. The
PLATFORM value indicates whether the
package is platform independent or intended for a specific
platform, as shown in the following table.
Table 2.2 MySQL Linux RPM Package Platforms
PLATFORM Value | Intended Use |
|---|---|
glibc23 | Platform independent, should run on any Linux distribution that supports
glibc 2.3 |
rhel4, rhel5 | Red Hat Enterprise Linux 4 or 5 |
sles10, sles11 | SuSE Linux Enterprise Server 10 or 11 |
In MySQL 5.1, only glibc23
packages are available currently.
The CPU value indicates the processor
type or family for which the package is built, as shown in the
following table.
Table 2.3 MySQL Linux RPM Package CPU Identifiers
CPU Value | Intended Processor Type or Family |
|---|---|
i386, i586,
i686 | Pentium processor or better, 32 bit |
x86_64 | 64-bit x86 processor |
ia64 | Itanium (IA-64) processor |
To see all files in an RPM package (for example, a
MySQL-server RPM), run a command like this
(modify the platform and CPU identifiers appropriately for your
system):
shell> rpm -qpl MySQL-server-VERSION.glibc23.i386.rpm
To perform a standard minimal installation, install the server and client RPMs:
shell>rpm -i MySQL-server-shell>VERSION.glibc23.i386.rpmrpm -i MySQL-client-VERSION.glibc23.i386.rpm
To install only the client programs, install just the client RPM:
shell> rpm -i MySQL-client-VERSION.glibc23.i386.rpm
RPM provides a feature to verify the integrity and authenticity of packages before installing them. To learn more about this feature, see Verifying Package Integrity Using MD5 Checksums or GnuPG.
The server RPM places data under the
/var/lib/mysql directory. The RPM also
creates a login account for a user named mysql
(if one does not exist) to use for running the MySQL server, and
creates the appropriate entries in
/etc/init.d/ to start the server
automatically at boot time. (This means that if you have performed
a previous installation and have made changes to its startup
script, you may want to make a copy of the script so that you can
reinstall it after you install a newer RPM.) See
Starting and Stopping MySQL Automatically, for more information on how
MySQL can be started automatically at system startup.
In MySQL 5.1.49 and later, during an upgrade installation using RPM packages, if the MySQL server is running when the upgrade occurs, the MySQL server is stopped, the upgrade occurs, and the MySQL server is restarted. If the MySQL server is not already running when the RPM upgrade occurs, the MySQL server is not started at the end of the installation.
If something goes wrong, you can find more information in the binary installation section. See Chapter 1, Installing MySQL on Unix/Linux Using Generic Binaries.
The accounts created in the MySQL grant tables for an RPM installation initially have no passwords. After starting the server, you should assign passwords to them using the instructions in Postinstallation Setup and Testing.
An RPM installation creates a user named mysql
and a group named mysql on the system using the
useradd, groupadd, and
usermod commands. Those commands require
appropriate administrative privileges, which is required for
locally managed users and groups (as listed in the
/etc/passwd and
/etc/group files) by the RPM installation
process being run by root.
If you log in as the mysql user, you may find
that MySQL displays “Invalid (old?) table or database
name” errors that mention .mysqlgui,
lost+found, .mysqlgui,
.bash_history,
.fonts.cache-1,
.lesshst,
.mysql_history,
.profile, .viminfo, and
similar files created by MySQL or operating system utilities. You
can safely ignore these error messages or remove the files or
directories that cause them if you do not need them.
For nonlocal user management (LDAP, NIS, and so forth), the administrative tools may require additional authentication (such as a password), and will fail if the installing user does not provide this authentication. Even if they fail, the RPM installation will not abort but succeed, and this is intentional. If they failed, some of the intended transfer of ownership may be missing, and it is recommended that the system administrator then manually ensures some appropriate user and group exists and manually transfers ownership following the actions in the RPM spec file.
Many Linux distributions include a version of the MySQL server, client tools, and development components into the standard package management system built into distributions such as Fedora, Debian, and Ubuntu. This section provides basic instructions for installing MySQL using these systems.
Native package installations can take care of the download and dependencies required to run MySQL, but the MySQL version will often be some way behind the currently available release. You will also normally be unable to install development releases, as these are not usually made available in the native repository.
Distribution specific instructions are shown below:
Red Hat Linux, Fedora, CentOS
For Red Hat and similar distributions, the MySQL distribution
is divided into a number of separate packages,
mysql for the client tools,
mysql-server for the server and associated
tools, and mysql-libs for the libraries.
The libraries are required if you want to provide connectivity
from different languages and environments such as Perl, Python
and others.
To install, use the yum command to specify the packages that you want to install. For example:
root-shell> yum install mysql mysql-server mysql-libs mysql-server Loaded plugins: presto, refresh-packagekit Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package mysql.x86_64 0:5.1.48-2.fc13 set to be updated ---> Package mysql-libs.x86_64 0:5.1.48-2.fc13 set to be updated ---> Package mysql-server.x86_64 0:5.1.48-2.fc13 set to be updated --> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.48-2.fc13.x86_64 --> Running transaction check ---> Package perl-DBD-MySQL.x86_64 0:4.017-1.fc13 set to be updated --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: mysql x86_64 5.1.48-2.fc13 updates 889 k mysql-libs x86_64 5.1.48-2.fc13 updates 1.2 M mysql-server x86_64 5.1.48-2.fc13 updates 8.1 M Installing for dependencies: perl-DBD-MySQL x86_64 4.017-1.fc13 updates 136 k Transaction Summary ================================================================================ Install 4 Package(s) Upgrade 0 Package(s) Total download size: 10 M Installed size: 30 M Is this ok [y/N]: y Downloading Packages: Setting up and reading Presto delta metadata Processing delta metadata Package(s) data still to download: 10 M (1/4): mysql-5.1.48-2.fc13.x86_64.rpm | 889 kB 00:04 (2/4): mysql-libs-5.1.48-2.fc13.x86_64.rpm | 1.2 MB 00:06 (3/4): mysql-server-5.1.48-2.fc13.x86_64.rpm | 8.1 MB 00:40 (4/4): perl-DBD-MySQL-4.017-1.fc13.x86_64.rpm | 136 kB 00:00 -------------------------------------------------------------------------------- Total 201 kB/s | 10 MB 00:52 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : mysql-libs-5.1.48-2.fc13.x86_64 1/4 Installing : mysql-5.1.48-2.fc13.x86_64 2/4 Installing : perl-DBD-MySQL-4.017-1.fc13.x86_64 3/4 Installing : mysql-server-5.1.48-2.fc13.x86_64 4/4 Installed: mysql.x86_64 0:5.1.48-2.fc13 mysql-libs.x86_64 0:5.1.48-2.fc13 mysql-server.x86_64 0:5.1.48-2.fc13 Dependency Installed: perl-DBD-MySQL.x86_64 0:4.017-1.fc13 Complete!
MySQL and the MySQL server should now be installed. A sample
configuration file is installed into
/etc/my.cnf. An init script, to start and
stop the server, will have been installed into
/etc/init.d/mysqld. To start the MySQL
server use service:
root-shell> service mysqld start
To enable the server to be started and stopped automatically during boot, use chkconfig:
root-shell> chkconfig --levels 235 mysqld on
Which enables the MySQL server to be started (and stopped) automatically at the specified the run levels.
The database tables will have been automatically created for you, if they do not already exist. You should, however, run mysql_secure_installation to set the root passwords on your server.
Debian, Ubuntu, Kubuntu
On Debian and related distributions, there are two packages,
mysql-client and
mysql-server, for the client and server
components respectively. You should specify an explicit
version, for example mysql-client-5.1, to
ensure that you install the version of MySQL that you want.
To download and install, including any dependencies, use the apt-get command, specifying the packages that you want to install.
Before installing, make sure that you update your
apt-get index files to ensure you are
downloading the latest available version.
A sample installation of the MySQL packages might look like this (some sections trimmed for clarity):
root-shell> apt-get install mysql-client-5.1 mysql-server-5.1 Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: linux-headers-2.6.28-11 linux-headers-2.6.28-11-generic Use 'apt-get autoremove' to remove them. The following extra packages will be installed: bsd-mailx libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient15off libmysqlclient16 libnet-daemon-perl libplrpc-perl mailx mysql-common postfix Suggested packages: dbishell libipc-sharedcache-perl tinyca procmail postfix-mysql postfix-pgsql postfix-ldap postfix-pcre sasl2-bin resolvconf postfix-cdb The following NEW packages will be installed bsd-mailx libdbd-mysql-perl libdbi-perl libhtml-template-perl libmysqlclient15off libmysqlclient16 libnet-daemon-perl libplrpc-perl mailx mysql-client-5.1 mysql-common mysql-server-5.1 postfix 0 upgraded, 13 newly installed, 0 to remove and 182 not upgraded. Need to get 1907kB/25.3MB of archives. After this operation, 59.5MB of additional disk space will be used. Do you want to continue [Y/n]? Y Get: 1 http://gb.archive.ubuntu.com jaunty-updates/main mysql-common 5.1.30really5.0.75-0ubuntu10.5 [63.6kB] Get: 2 http://gb.archive.ubuntu.com jaunty-updates/main libmysqlclient15off 5.1.30really5.0.75-0ubuntu10.5 [1843kB] Fetched 1907kB in 9s (205kB/s) Preconfiguring packages ... Selecting previously deselected package mysql-common. (Reading database ... 121260 files and directories currently installed.) ... Processing 1 added doc-base file(s)... Registering documents with scrollkeeper... Setting up libnet-daemon-perl (0.43-1) ... Setting up libplrpc-perl (0.2020-1) ... Setting up libdbi-perl (1.607-1) ... Setting up libmysqlclient15off (5.1.30really5.0.75-0ubuntu10.5) ... Setting up libdbd-mysql-perl (4.008-1) ... Setting up libmysqlclient16 (5.1.31-1ubuntu2) ... Setting up mysql-client-5.1 (5.1.31-1ubuntu2) ... Setting up mysql-server-5.1 (5.1.31-1ubuntu2) ... * Stopping MySQL database server mysqld ...done. 100825 11:46:15 InnoDB: Started; log sequence number 0 46409 100825 11:46:15 InnoDB: Starting shutdown... 100825 11:46:17 InnoDB: Shutdown completed; log sequence number 0 46409 100825 11:46:17 [Warning] Forcing shutdown of 1 plugins * Starting MySQL database server mysqld ...done. * Checking for corrupt, not cleanly closed and upgrade needing tables. ... Processing triggers for libc6 ... ldconfig deferred processing now taking place
The apt-get command will install a number of packages, including the MySQL server, in order to provide the typical tools and application environment. This can mean that you install a large number of packages in addition to the main MySQL package.
During installation, the initial database will be created, and
you will be prompted for the MySQL root password (and
confirmation). A configuration file will have been created in
/etc/mysql/my.cnf. An init script will
have been created in /etc/init.d/mysql.
The server will already be started. You can manually start and stop the server using:
root-shell> service mysql [start|stop]
The service will automatically be added to the 2, 3 and 4 run levels, with stop scripts in the single, shutdown and restart levels.