2.5.2. Installing MySQL on Linux using Native Package Manager

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, Ubuntu, and Gentoo. This section provides basic instructions for installing MySQL using these systems.


Native package installations can take care of the download and depdendencies 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 developmental releases, as these are not usually made available in the native repository.

Distribution specific instructions are shown below:

  • RedHat Linux, Fedora, CentOS

    For RedHat 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> 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
     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 
      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                                          

    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 pacakges 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
    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
     * 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.

  • Gentoo Linux

    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 package, 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*

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

    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 /etc/init.d/mysql.

    To enable MySQL to start automatically at the normal (default) run levels, you can use:

    root-shell> rc-update add default mysql
Copyright © 2010-2022 Platon Technologies, s.r.o.           Home | Man pages | tLDP | Documents | Utilities | About
Design by styleshout