How to Install MySQL in CentOS?

Learn to install MySQL on CentOS with our easy-to-follow guide. Perfect for beginners & experts alike. Get your database running in no time

Updated: 14 Feb, 24 by Lisa P 4 Min

List of content you will read in this article:

Are you looking to install MySQL on your CentOS server? In this article, we will guide you through the step-by-step process of installing MySQL on CentOS, covering various versions and installation methods. If you are looking for CentOS VPS Hosting, click here to see our plans.

To begin, let's explore the general process of installing MySQL in CentOS. By following these steps, you'll be able to get MySQL up and running on your CentOS server.

First, open your terminal and log in to your CentOS server as the root user or a user with sudo privileges. Then, proceed with the following steps:

  1. Update the system packages by running the command:

sudo yum update

  1. Install the MySQL server package using the following command:

sudo yum install mysql-server

  1. Once the installation is complete, start the MySQL service:

sudo systemctl start mysqld

  1. To ensure that MySQL starts automatically on system boot, enable it with this command:

sudo systemctl enable mysqld

  1. Secure your MySQL installation by running the security script provided by MySQL:

sudo mysql_secure_installation

If you want to install the Apache web server, PHP, and MySQL on your CentOS 7 server, follow these steps:

  1. Log in to your CentOS 7 server using the root user or a user with sudo privileges.
  2. Install the Apache web server:

sudo yum install httpd

  1. Start the Apache service:

sudo systemctl start httpd

  1. Install PHP and related modules:

sudo yum install php php-mysql

  1. Install the MySQL server package:

sudo yum install mysql-server

  1. Start the MySQL service:

sudo systemctl start mysqld

  1. Enable Apache and MySQL to start automatically on system boot:

sudo systemctl enable httpd

sudo systemctl enable mysqld

How to Install MySQL Connector CentOS 7

To install the MySQL Connector for Python, also known as MySQLdb, on CentOS 7, follow these steps:

  1. Log in to your CentOS 7 server using the root user or a user with sudo privileges.
  2. Update the system packages:

sudo yum update

  1. Install the required packages for building Python extensions:

sudo yum install python-devel mysql-devel

  1. Install the MySQL Connector for Python using pip:

sudo pip install mysql-connector-python

MySQL is readily available in the CentOS 9 Stream repositories, simplifying the installation process. Follow these steps:

  1. Begin by opening the terminal or connecting via SSH, and update the system:

sudo dnf update

  1. Next, install MySQL using the following command:

sudo dnf install mysql mysql-server

  1. Once the installation is complete, verify the installed version:

mysql --version

mysql  Ver 8.0.28 for Linux on x86_64 (Source distribution)

Always ensure you're using the latest CentOS version and follow the specific installation instructions provided by the official MySQL documentation or reputable sources to successfully install MySQL on your CentOS system. Click on this link to see How to Update CentOS to the Latest Version.

Installing MySQL on CentOS is a straightforward process when you follow the step-by-step instructions outlined in this article. Whether you are using CentOS 6, CentOS 7, or a Linux distribution based on CentOS 7, you can easily set up and secure MySQL to start managing your databases efficiently. You can also learn How to Install Docker on CentOS 7 by clicking on this link. Remember to adjust the installation steps according to the specific CentOS version you are using and the requirements of your project. Enjoy using MySQL to store and organize your data effectively.

Yes, you can install MySQL on CentOS 6 by following the provided installation steps specific to CentOS 6 in the article.

To secure your MySQL installation on CentOS, you can run the "sudo mysql_secure_installation" command, which will prompt you to set a root password and perform other security configurations.

Yes, you can install Apache, PHP, and MySQL together on CentOS 7. The article provides a step-by-step guide on how to install these components as a bundle.

MySQL Query Browser has been discontinued and is no longer actively maintained. However, alternatives like MySQL Workbench or phpMyAdmin can be used to manage MySQL databases on CentOS.

To install the MySQL Connector for Python on CentOS, you can follow the steps outlined in the article, which involve installing the required packages for building Python extensions and then using pip to install the MySQL Connector.

Lisa P

Lisa P

Hello, everyone, my name is Lisa. I'm a passionate electrical engineering student with a keen interest in technology. I'm fascinated by the intersection of engineering principles and technological advancements, and I'm eager to contribute to the field by applying my knowledge and skills to solve real-world problems.