MySQL logo with abstract tech elements on a blue background

Linux Database Management: MySQL Installation Guide

Setting Up MySQL on a Linux System

In today’s digital era, data reigns supreme. As businesses increasingly pivot towards data-driven strategies, the role of digital transformation in driving progress becomes undeniably crucial. The essence of data in propelling business growth cannot be overstated—it is, in every sense, pivotal. Recognizing this, the significance of implementing an efficient database management system has skyrocketed. This guide will navigate you through the steps of configuring MySQL on a Linux platform.

One might ponder, “Why opt for MySQL on Linux?” The answer lies in the unparalleled synergy this combination offers for the development of database-centric software applications. Both MySQL and Linux stand out for their reliability, security, and open-source nature. This guide will cover the prerequisites for MySQL installation on Linux, detail the installation process via the MySQL Yum repository, and provide instructions for installing MySQL directly from the command line.

If you’re interested in Linux software installation, you may also like to explore articles on installing Conda on Linux to make your Linux experience even more efficient.

The Significance of Choosing Linux

Linux, akin to Windows or macOS, enjoys widespread popularity as an operating system. Its distinct advantage lies in its open-source framework, allowing users the freedom to run, examine, modify, and share its source code. Linux’s ubiquity is evident, with a significant portion of professional developers opting for Linux-based systems and its dominance in powering 85% of smartphones worldwide.

Key Advantages of Linux:

  • Cost-effectiveness;
  • Enhanced performance;
  • User-friendly interface;
  • Robust security features;
  • High degree of flexibility;
  • Consistent updates;
  • Wide range of distributions;
  • Comprehensive support for prevalent programming languages.

Essential Requirements for Setting Up MySQL on Linux

To successfully install MySQL on a Linux system, you need to ensure that the following prerequisites are in place:

  • A stable network connection;
  • A Linux-based operating system installed on your machine;
  • Access to the terminal for executing commands;
  • A user account with sudo privileges to carry out administrative tasks.

Before you begin the installation process, it’s important to note that the method for installing MySQL can vary depending on the specific Linux distribution you are using. Therefore, it’s crucial to identify your Linux distribution before proceeding.

For instance, if you’re running Oracle Linux, Red Hat Enterprise Linux, or CentOS, you can take advantage of the MySQL Yum repository, which offers RPM packages for installing various MySQL components such as the MySQL Server, client, Workbench, and Utilities. Alternatively, if you’re using Debian or Ubuntu, the MySQL APT repository provides .deb packages for efficient installation and management of MySQL server, client, and related components.

Guide to Installing MySQL via Yum Repository

This guide focuses exclusively on the fresh installation of MySQL through a Yum repository. If MySQL is already installed on your system, you may need to consider upgrading or replacing the existing MySQL package.

  • Installation Process;
  • Initializing a Yum Repository;
  • Acquiring the Most Recent MySQL Version;
  • Activating the MySQL Service;
  • Setting Up the MySQL Root Account;
  • Accessing MySQL;
  • Opting for an Alternate MySQL Version (5.6, 5.7).

1. Initializing a Yum Repository

Firstly, incorporate a MySQL Yum repository into your system’s repository collection by executing the command below.

sudo rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm

2. Acquiring the Most Recent MySQL Version

The Yum repository now includes several configurations for various MySQL versions. To proceed, disable all active repositories in the MySQL repo file with the command:

sudo sed -i ‘s/enabled=1/enabled=0/’ /etc/yum.repos.d/mysql-community.repo

Following this, install the MySQL server by enabling the specific repository and running:

sudo yum –enablerepo=mysql80-community install mysql-community-server

3. Activating the MySQL Service

Initiate the MySQL service with the command below. Enter the password when prompted.

service mysqld start

Upon installation, the root account is assigned a temporary password. Retrieve this password using:

sudo grep “A temporary password” /var/log/mysqld.log

This temporary password is essential for resetting the root account’s password.

4. Setting Up the MySQL Root Account

After launching the MySQL service and acquiring the temporary password, secure your MySQL server by executing:

mysql_secure_installation

Input the temporary password when prompted, then set and confirm a new root password. Answer ‘Yes’ to all subsequent security questions to ensure optimal configuration.

Consider restarting and enabling the MySQL service to run at boot with:

service mysqld restart

chkconfig mysqld on

5. Accessing MySQL

To log into MySQL, use:

mysql -u root -p

Enter the root password when prompted. You can list all databases on the server with `show databases`.

6. Opting for an Alternate MySQL Version (5.6, 5.7)

Should you need a different MySQL version, uninstall the current version and clear all associated packages. After removal, you can install the desired version, e.g., MySQL 5.7:

Add the MySQL 5.7 repository to your CentOS 7 system:

sudo yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

Install MySQL server 5.7:

sudo yum install mysql-community-server

Verify the installation by checking the MySQL version:

mysql –version

This completes the procedure for installing MySQL through a Yum repository, including switching versions if necessary.

Updating MySQL Using Yum Package Manager

To update MySQL using the Yum package manager, you can follow these steps. Please note that the update process may take some time.

Update All MySQL Components:

To update all MySQL components on your system, run the following command with sudo privileges:

sudo yum update

After the update is completed by Yum, the MySQL server will be automatically restarted. To ensure everything is in order, you can run the following command to check and resolve any possible incompatibilities:

mysql_upgrade

Update Specific MySQL Component:

If you want to update only a specific MySQL component, you can do so by following these steps:

First, list all the installed packages related to MySQL components using the following command:

sudo yum list installed | grep “^mysql”

Identify the specific package you want to update from the list and run the following command, replacing ‘package-name’ with the actual package name:

sudo yum update package-name

By following these steps, you can efficiently update MySQL on your system using the Yum package manager, whether you want to update all components or just a specific one.

Installing MySQL Without Yum on Debian and Ubuntu

MySQL Workbench setup window for a new local server connection

If your Linux distribution does not support Yum, such as Debian or Ubuntu, you can install MySQL using the APT repository. Here’s a step-by-step guide to installing MySQL on your Debian or Ubuntu system:

Download the MySQL APT repository configuration package by executing the following command:

wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb

Install the downloaded package using the following command (replace the package name with the actual downloaded version if it’s different):

sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb

In the package configuration window, you will be prompted to select your system and the version of the MySQL server you want to install. Make your selections and press “OK” to confirm.

Update the APT repository to include the MySQL packages:

sudo apt update

Finally, run the following command to install MySQL server and client packages. When prompted, press “Y” to confirm the installation and set a password for the root user:

sudo apt install -f mysql-client=8.0* mysql-community-server=8.0* mysql-server=8.0*

Once the installation is complete, you can manage your MySQL server on your Debian or Ubuntu system.

MySQL Workbench setup window for a new local server connection

Installing MySQL on Linux Distributions

The process of setting up MySQL on any Linux distribution involves a straightforward three-step procedure. This guide outlines the essential steps required to successfully install MySQL, ensuring compatibility across various Linux environments.

Steps for Installation:

  • Acquiring MySQL Server and Client Packages;
  • Uninstalling Pre-existing MySQL Versions (if applicable);
  • Executing the MySQL Package Installation

How to install MySQL database On Linux (Ubuntu, Mint, Manjaro, Fedora)

Step 1: Acquiring MySQL Server and Client Packages

To initiate, the necessary MySQL packages must be downloaded, with the specific command varying based on the Linux distribution in question.

For RHEL/CentOS 8:

wget https://repo.mysql.com/mysql80-community-release-el8

For RHEL/CentOS 7:

wget https://repo.mysql.com/mysql80-community-release-el7

For Fedora 35:

wget https://dev.mysql.com/get/mysql80-community-release-fc35-1.noarch.rpm

For Fedora 34:

wget https://dev.mysql.com/get/mysql80-community-release-fc34-1.noarch.rpm

For Ubuntu 20.04, 22.04, or later:

wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb

For Debian 11:

wget https://dev.mysql.com/get/mysql-apt-config_0.8.20-1_all.deb

For Debian 10:

wget -q http://repo.mysql.com/mysql-apt-config_0.8.15-1_all.deb

Step 2: Uninstalling Pre-existing MySQL Versions (if applicable)

Depending on the Linux distribution, the command to remove any pre-installed MySQL version will differ.

For CentOS and RedHat systems:

sudo yum remove mysql mysql-server

For Ubuntu and Debian systems:

sudo apt remove mysql mysql-server

For Fedora 22+ systems:

sudo dnf remove mysql mysql-server

Step 3: Executing the MySQL Package Installation

Following the removal of any previous MySQL installations, proceed with installing the new MySQL package.

For CentOS and RedHat systems:

sudo yum install mysql-community-server

For Ubuntu and Debian systems:

sudo apt-get install mysql-server

For Fedora 22+ systems:

sudo dnf install mysql-community-server

This structured approach ensures a seamless MySQL setup across a variety of Linux distributions, accommodating the unique package management systems inherent to each.