MySQL is one of the most popular database management systems used both in production and for storing website and application data. However, after MySQL was taken over by Oracle, MariaDB is used everywhere by default instead. It’s a decent replacement if you’re only looking for basic functionality, but if you want all the finer details and features of MySQL, you need the Oracle version.

But MySQL has been removed from the official repositories. Therefore, you will have to look for other sources. In this article, we will look at how MySQL CentOS 7 is installed. Moreover, in the version from Oracle, and not MariaDB.

System preparation

Before you move on to installing MySQL on CentOS, you need to make a few settings and check if everything is correct on your system. First make sure you have the hostname set. To do this, run the command:

$ hostname -f

Installing MySQL CentOS 7

The first command will show the short hostname, the second will show the full FQDN. If everything is correct, it remains to update the system to the latest version:

sudo yum update

Installing MySQL on CentOS 7

As I said, there is no package in the official repositories, so you will have to add the community repository. You need to go to and download the latest version of the repository file. For example, at the moment it is mysql57-community-release-el7.rpm.

To install this version, you can use the command:

sudo rpm -ivh mysql57-community-release-el7.rpm

Installing MySQL CentOS 7

Next, update the list of repositories:

sudo yum update

Now you just have to install mysql centos 7 and start the service itself:

sudo yum install mysql-server
$ sudo systemctl start mysqld

Installing MySQL CentOS 7

Configuring MySQL CentOS 7

By default, MySQL will listen on localhost If you want the server to be accessible from the internet, you need to change a few settings in the /etc/my.cnf file. However, it is not recommended to make the database server accessible via the Internet. To specify the external ip address to listen on, use the bind_address line:

sudo vi /etc/my.cnf

bind_address =

Also in the default setting there are some settings that may be potentially insecure when accessed from an external network. To do this, run the mysql_secure_installation script to eliminate them:


Installing MySQL CentOS 7

First you need to enter the superuser password. By default, the system generates a random password during installation. To see it, open another terminal and run:

grep 'temporary password' /var/log/mysqld.log

Installing MySQL CentOS 7

Then the system will inform you that your password is outdated and you need to change it, enter the new password twice:

Installing MySQL CentOS 7

Then indicate that the password does not need to be changed. Disable anonymous users. Disable remote login as root:

Installing MySQL CentOS 7

Remove test tables:

Installing MySQL CentOS 7

And update the privilege tables:

Installing MySQL CentOS 7

It is not recommended to constantly work with databases as the root user. Therefore, you need to create a regular user. To do this, first login to the management console as root:

 mysql -u root -p

The utility will ask for password, enter the root password that you set in the previous step, then you can execute mysql commands:


Installing MySQL CentOS 7

Let’s create a dbuser user for the dbase database, with the password password. You need to replace these values ​​with your own. First we create the database:

mysql> create database dbase;
mysql> create user 'dbuser'@'localhost' identified by 'password';
mysql> grant all on dbase.* to dbuser' identified by 'password';

Next, let’s create the first table in our new database, but before that, we’ll log in as the user we just created:

mysql -u testuser -p

Switch to the new database:

mysql> use dbase

Then create a table:

create table customers (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT);

Ready. Now you know how to install MySQL CentOS 7. Let’s take a look at how to reset password in MySQL.

Resetting the root user password in MySQL

Sometimes it can happen that you forget the password of the root user. It can be dropped very easily. First, stop the running instance of the program:

sudo systemctl stop mysqld

Then start the service in safe mode, for this you need to set a special startup option:

systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

In this mode, the program will not ask for a password to connect. Connect as superuser and change the password:

mysql -u root

mysql> use mysql;
mysql> update user SET PASSWORD=PASSWORD("password") WHERE USER='root';
mysql> flush privileges;

Then remove this variable:

sudo systemctl unset-environment MYSQLD_OPTS

It remains to restart the server in normal mode:

sudo systemctl start mysqld

mysql performance improvement

The default mysql setting is not always optimal. Depending on how you use your database, you can improve its performance. The MySQL Tuner script is written in Perl and provides guidance on how to tune MySQL depending on your workload. Let the server run for at least 24 hours before running the script. The longer the running time, the more accurate the instructions.

Download the script:


Then run:

perl ./

Upon launch, you will be prompted for the root password, followed by a list of configuration recommendations and security notes. This is a great point for server optimization.

uninstall mysql

If you want to uninstall MySQL CentOS 7, just run the following command:

sudo yum remove mysql-server


In this article, we have seen how to install mysql centos 7. Now you can install this program on your server or home computer. We also talked about how the basic setup of mysql centos 7 is done, so now you can get a fully working system. If you have any questions, ask in the comments!

Source: The article is distributed under the CC-BY-SA license