Install Specific Version of MySQL 8 using YUM

We have many ways to install MySQL on linux machines such as source, binary and so on. But most of the Engineers always prefer default package managers (yum for RPM-Based distributions and apt for DPKG-Based distributions) for its ease of use and it can resolve all dependencies on its own. And of course, it is not possible to use package managers in environments where the internet is not allowed, but this is a different case. 

At some point, we need to install exactly specific version of MySQL for the following cases

  • To create Production Replicas 
  • To simulate an Production Issue on similar kind of environment
  • To configure Disaster Recovery(DR)/UAT Setup
  • Compatibility with opensource tools ( Eg , Xtrabackup compatibility )

But following the instructions from MySQL Documentation for installation using yum always leads to the installation of the latest version released. At the time of writing this blog, the latest release is MySQL 8.0.22. Following the documentation steps resulted in installation of the same. Definitely, we can install other versions of MySQL using RPM files. But it is quite tough at times because of its dependencies or conflicts with any other older version packages.

So, in this blog post, we will look at how to install a specific version of MySQL using yum. All the following steps are tested in CentOS 7 and it requires sudo privileges.

  1. Setting up Yum Repository

The below command will enable the yum repository required for the installation of MySQL

rpm -Uvh
  1. Disabling all repos in MySQL

It is to disable repos for all versions of MySQL.

sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo
  1. To install MySQL 8 of particular minor version, let’s say 8.0.20 , we can execute the following command
yum --enablerepo=mysql80-community install mysql*8.0.20*

So, the general command will be like

yum --enablerepo=mysql80-community install mysql*8.0.X*

Where X is the minor version that you want

Or else if you want to install the latest version, just go with the below command. It will install the latest version available at that time.

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

That’s it if the above command succeeds. We will get the required version successfully installed on the server.

4. Start the MySQL service

Use the below service command to start up the MySQL service

service mysqld start

5. Get the temporary password in the error log

By default, MySQL will generate a temporary password for root user and it will be in the error log. So, to get the temporary password from error log use the below command.

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

The sample output would be like:

[root@ha mydbopslabs]# grep "temporary password" /var/log/mysqld.log
2020-12-10T14:12:49.940127Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 7y:ztnVKwh7q
[root@ha mydbopslabs]#

6) Login the MySQL using root user with the temporary password

mysql -p'$temporary password'

7) On successful login, we should reset the root user password as the first thing. Otherwise, we cannot execute any commands until we reset the password. we will get the warning like below

mysql> show schemas;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

To reset the root user password, execute the below query on mysql prompt.

alter user 'root'@'localhost' identified by 'strong password';

Sample query be like

mysql> alter user 'root'@'localhost' identified by '[BX.D"7s!c';
Query OK, 0 rows affected (0.22 sec)

Once it is done, our MySQL setup is ready to use. For fine tuning of MySQL to handle production work load, refer our presentation Fine Tuning of MySQL 8.0 which was taken at Mydbops Database Meetup.

Also, look our other blogs that explores the coolest features of MySQL 8.0 which greatly helps for Database Administrators and Developers.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s