How To Install Mysql Centos

admin14 April 2024Last Update :

Understanding MySQL Installation on CentOS

MySQL is a widely-used open-source relational database management system (RDBMS) that is an essential part of many web applications. Installing MySQL on CentOS, a popular Linux distribution for servers, involves several steps that require attention to detail and understanding of Linux commands. This guide will walk you through the process of installing MySQL on a CentOS system.

Prerequisites for Installing MySQL on CentOS

Before proceeding with the installation, ensure that your CentOS system meets the following requirements:

  • A running instance of CentOS (preferably the latest version).
  • Root or sudo privileges.
  • Access to a terminal or command line interface.
  • An active internet connection to download packages.

Step 1: Updating System Packages

It’s always a good practice to update your package repository before installing new software. Use the following command to update your CentOS system:

yum update -y

This command ensures that all your existing packages are up-to-date.

Step 2: Adding the MySQL Yum Repository

CentOS does not come with MySQL in its default repository. Therefore, you need to add the official MySQL Yum repository to your system:

sudo rpm -ivh mysql80-community-release-el7-3.noarch.rpm

These commands download and install the MySQL repository package.

Step 3: Installing MySQL Server

With the repository added, you can now install MySQL server using yum:

sudo yum install mysql-server

During the installation, you may be prompted to accept the GPG key for the MySQL repository. Confirm this to continue with the installation.

Step 4: Starting and Securing MySQL

Once installed, start the MySQL service and enable it to launch at boot:

sudo systemctl start mysqld
sudo systemctl enable mysqld

After starting MySQL, it’s crucial to secure your installation:

sudo mysql_secure_installation

This script will guide you through setting a root password, removing anonymous users, disallowing remote root login, and removing test databases.

Step 5: Configuring MySQL Database

To configure your MySQL server according to your needs, edit the configuration file located at /etc/my.cnf or /etc/mysql/my.cnf. You can use any text editor like vi or nano:

sudo vi /etc/my.cnf

Make sure to adjust settings such as bind-address, max_connections, and others as per your requirements.

Step 6: Creating a New MySQL User and Database

For security reasons, it’s recommended to create a new user and database for your applications rather than using the root account. Here’s how to do it:

mysql -u root -p
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE newdatabase;
GRANT ALL PRIVILEGES ON newdatabase.* TO 'newuser'@'localhost';

Replace ‘newuser’ and ‘password’ with your desired username and password, and ‘newdatabase’ with your database name.

Troubleshooting Common MySQL Installation Issues

Sometimes, you might encounter issues during the installation process. Here are some common problems and their solutions:

  • If the MySQL service fails to start, check the error log at /var/log/mysqld.log for clues.
  • In case of conflicts with another installed service like MariaDB, you may need to remove the conflicting service before proceeding with the MySQL installation.
  • Ensure SELinux is configured correctly if it’s enabled on your system, as it can interfere with MySQL operations.

Optimizing MySQL Performance on CentOS

To get the most out of your MySQL installation, consider optimizing your server settings based on your workload. Tools like can help analyze your server and provide recommendations.

Backing Up and Restoring MySQL Databases

Regular backups of your MySQL databases are critical. Use mysqldump for backups:

mysqldump -u root -p --all-databases > alldb_backup.sql

To restore a database from a backup file, use:

mysql -u root -p < alldb_backup.sql

FAQ Section

How can I install a specific version of MySQL?

You can list available MySQL versions in the repository and install a specific one using:

yum --disablerepo=mysql80-community --enablerepo=mysql57-community install mysql-community-server

Replace mysql57-community with the repository of the desired version.

What should I do if I forget the MySQL root password?

If you’ve forgotten the root password, you’ll need to reset it by restarting MySQL with skip-grant-tables option and updating the password directly in the user table.

Can I install MySQL on a CentOS system without internet access?

Yes, you can download the RPM packages on another machine with internet access and transfer them to your CentOS system for offline installation.

Is it necessary to run mysql_secure_installation after installing MySQL?

While not strictly necessary, running mysql_secure_installation is highly recommended to improve the security of your MySQL installation.

How do I check if MySQL is running on my CentOS server?

Use the following command to check the status of the MySQL service:

systemctl status mysqld


For further reading and advanced topics related to MySQL installation and optimization, refer to the following resources:

Leave a Comment

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

Comments Rules :

Breaking News