How to Install MySQL on CentOS 7 / RHEL 7 / Oracle Linux 7 instead of MariaDB

how to install mysql

By default, CentOS 7, RHEL 7, and Oracle Linux 7 come with MariaDB, a drop-in replacement for MySQL. However, in some cases, you might prefer to use the original MySQL instead of MariaDB. In this guide, we will demonstrate how to install MySQL on CentOS 7, RHEL 7, and Oracle Linux 7 instead of MariaDB.

Step 1: Remove MariaDB if installed

If MariaDB is installed on your system, you need to remove it first. To uninstall MariaDB and its dependencies, execute the following command:

sudo yum remove -y mariadb mariadb-server

Step 2: Add the MySQL Yum repository

To install MySQL, you need to add the MySQL Yum repository. Download the MySQL Yum repository RPM package using the following command:

wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

Install the downloaded MySQL repository RPM package:

sudo rpm -Uvh mysql57-community-release-el7-8.noarch.rpm

This command adds the MySQL repository to your system.

Step 3: Install MySQL

With the MySQL repository added, you can now install MySQL using the following command:

sudo yum install -y mysql-community-server

This command installs the MySQL server and its dependencies on your system.

See also  How to Show the Tables in a MySQL Database Server

Step 4: Start and enable the MySQL service

Start the MySQL service:

sudo systemctl start mysqld

Enable the MySQL service to start automatically on system boot:

sudo systemctl enable mysqld

Step 5: Secure the MySQL installation

Run the MySQL security script to secure your MySQL installation:

sudo mysql_secure_installation

The script will prompt you to configure several security settings, such as setting a root password, removing anonymous users, disallowing remote root login, and removing the test database.

# sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 50
Change the password for root ? ((Press y|Y for Yes, any other key for No) : yes

New password:

Re-enter new password:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : no

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

Programs Mentioned:

  • MariaDB – A drop-in replacement for MySQL that is the default database system in CentOS 7, RHEL 7, and Oracle Linux 7.
  • MySQL – An open-source relational database management system.
  • yum – The default package manager for CentOS and RHEL, used to install, update, and manage software packages on the system.
  • systemctl – A utility for controlling the systemd system and service manager, which is used to manage services on CentOS 7, RHEL 7, and Oracle Linux 7.
See also  How to Install WordPress on Remote MySQL

Conclusion

You have successfully installed MySQL on CentOS 7, RHEL 7, or Oracle Linux 7 instead of MariaDB. You can now use the MySQL server to manage your databases and applications that depend on MySQL. Remember to keep your MySQL installation up-to-date with security patches and new features by regularly running sudo yum update.

If you have any questions, comments, or suggestions for improvements, please feel free to share your thoughts. Your feedback helps us provide the most accurate and useful information possible.

Comments

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *