CentOS/Fedora/RHEL - Installing MySQL Database with YUM

This article describes how to install MySQL on CentOS, Fedora, and Red Hat Enterprise Linux systems by using the YUM package manager. The YUM package manager is an automatic installer and uinstaller for Red Hat based systems. It downloads requested applications from a network of repository servers where the latest stable versions of popular applications are stored. To install a newer version of an application than what is available in the YUM repositories, you can compile it from the source code.

Note: CentOS 7, Red Hat 7, and Fedora 19 and later versions have replaced MySQL with MariaDB. To reflect this, instructions for MariaDB procedures are included in this article.



Updating your server

To keep your server secure, use the following command to update all of the software on your server with YUM:

# sudo yum -y update


Installing MySQL and MariaDB with YUM

After you complete the updates to your server, perform the following procedures to install the database server.

MySQL installation

Use the following command to install the MySQL server:

# sudo yum -y install mysql-server

MariaDB installation

Use the following command to install the MariaDB server:

# sudo yum install mariadb-server mariadb


Starting the database service

After you complete the installation, you can start the database application for the first time. Upon initial startup, the application creates several test databases and system databases.

Starting MySQL

Use the following command to start the MySQL server:

# sudo /etc/init.d/mysqld start

Starting MariaDB

Use the following command to start the MariaDB server:

#sudo systemctl start mariadb.service


Securing MySQL

Now that you have the MySQL server running, you need to secure the installation.

  1. Use the following command to start the secure setup script:
    # sudo /usr/bin/mysql_secure_installation

  2. You must enter a current root password to begin this installation. Because this is a new installation, the root password is set to None. Press Enter.

  3. When asked if you want to set your root password, select Y and then press Enter.

  4. When prompted, enter your root password twice. If you entered it correctly, you will see the Success! message.

  5. To remove the MySQL anonymous users, press Y and then Enter. The text above the question explains this topic in more detail.

  6. To disallow remote login for the root user and allow connections only from the server itself, press Y and then Enter.

  7. To delete the default test database and the associated users, press Y and then Enter.

  8. To reload the user settings (called privilege tables) so that user changes take effect, press Y and then Enter.

Your database installation is complete. The procedures described in this article support only local connections and do not allow you to connect remotely. The article MySQL - Connect to your database remotely explains how to make a remote connection from another server to your database.


© 2015 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

See license specifics and DISCLAIMER