Many Linux distributions include a version of the MySQL server, client tools, and development components in their native software repositories and can be installed with the platforms' standard package management systems. This section provides basic instructions for installing MySQL using those package management systems.
Native packages are often several versions behind the currently available release. You will also normally be unable to install development milestone releases (DMRs), as these are not usually made available in the native repositories. Before proceeding, we recommend that you check out the other installation options described in Section 2.5, “Installing MySQL on Linux”.
Distribution specific instructions are shown below:
Red Hat Linux, Fedora, CentOS
For EL5, EL6, or EL7-based Linux platforms and Fedora 21 or 22, you can install MySQL using the MySQL Yum repository instead of the platform's native software repository. See Section 2.5.1, “Installing MySQL on Linux Using the MySQL Yum Repository” for details.
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
mysql-libs for the libraries.
The libraries are required if you want to provide connectivity
from different languages and environments such as Perl, Python
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
For Debian 7 and 8, and Ubuntu 12, 14, and 15, MySQL can be installed using the MySQL APT Repository instead of the platform's native software repository. See Section 2.5.3, “Installing MySQL on Linux Using the MySQL APT Repository” for details.
On Debian and related distributions, there are two packages
for MySQL in their software repositories,
mysql-server, for the client and server
components respectively. You should specify an explicit
version, for example
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
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.
As a source-based distribution, installing MySQL on Gentoo involves downloading the source, patching the Gentoo specifics, and then compiling the MySQL server and installing it. This process is handled automatically by the emerge command. Depending on the version of MySQL that you want to install, you may need to unmask the specific version that you want for your chosen platform.
The MySQL server and client tools are provided within a single
dev-db/mysql. You can obtain a
list of the versions available to install by looking at the
portage directory for the package:
root-shell> ls /usr/portage/dev-db/mysql/mysql-5.1* mysql-5.1.39-r1.ebuild mysql-5.1.44-r1.ebuild mysql-5.1.44-r2.ebuild mysql-5.1.44-r3.ebuild mysql-5.1.44.ebuild mysql-5.1.45-r1.ebuild mysql-5.1.45.ebuild mysql-5.1.46.ebuild
To install a specific MySQL version, you must specify the entire atom. For example:
root-shell> emerge =dev-db/mysql-5.1.46
A simpler alternative is to use the
virtual/mysql-5.1 package, which will
install the latest version:
root-shell> emerge =virtual/mysql-5.1
If the package is masked (because it is not tested or
certified for the current platform), use the
ACCEPT_KEYWORDS environment variable. For
root-shell> ACCEPT_KEYWORDS="~x86" emerge =virtual/mysql-5.1
After installation, you should create a new database using mysql_install_db, and set the password for the root user on MySQL. You can use the configuration interface to set the password and create the initial database:
root-shell> emerge --config =dev-db/mysql-5.1.46
A sample configuration file will have been created for you in
/etc/mysql/my.cnf, and an init script
will have been created in
To enable MySQL to start automatically at the normal (default) run levels, you can use:
root-shell> rc-update add mysql default