When you run a production database, you need a reliable solution that has fast recovery times, won’t crash your applications, and meets the performance demands of your users. That doesn’t mean you have to spend a ton of cash either. Amazon provides services that make it easy to deploy new databases on their infrastructure without needing to know too much about how these things work.

Advertisement

This article will walk through the process of installing MySQL 5.7 on Amazon Linux 2.

Prerequisites

Login to your Fedora system and open a terminal. Now upgrade the current packages to the latest version by running the following command.

sudo yum update -y 

Step 1 – Install MySQL on Amazon Linux

The Amazon Linux default repositories contain MariaDB packages for the installation. To install the MySQL community release, first, configure MySQL yum repository on your machine.

sudo rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm 
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

After that run the following command to install the MySQL 5.7 packages on your systems. This will also install all other required dependencies.

sudo yum install mysql-community-server 
Dependencies Resolved

==========================================================================================================
 Package                          Arch        Version                        Repository              Size
==========================================================================================================
Installing:
 mysql-community-libs             x86_64      5.7.39-1.el7                   mysql57-community      2.6 M
     replacing  mariadb-libs.x86_64 1:5.5.68-1.amzn2
 mysql-community-libs-compat      x86_64      5.7.39-1.el7                   mysql57-community      1.2 M
     replacing  mariadb-libs.x86_64 1:5.5.68-1.amzn2
 mysql-community-server           x86_64      5.7.39-1.el7                   mysql57-community      178 M
Installing for dependencies:
 mysql-community-client           x86_64      5.7.39-1.el7                   mysql57-community       28 M
 mysql-community-common           x86_64      5.7.39-1.el7                   mysql57-community      311 k
 ncurses-compat-libs              x86_64      6.0-8.20170212.amzn2.1.3       amzn2-core             308 k

Transaction Summary
==========================================================================================================
Install  3 Packages (+3 Dependent packages)

Total download size: 210 M
Is this ok [y/d/N]: y

Press ‘y’ when prompt for the confirmation to complete installation.

Once the MySQL installation is completed on your Amazon Linux system. You need to enable the MySQL service to start on system boot. Also, start the service using the following commands:

sudo systemctl enable mysqld 
sudo systemctl start mysqld 

Once you start the MySQL server for the first time, an auto-generated password is set for the root account. You can find this password in MySQL logs.

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

2022-08-18T07:31:38.099501Z 1 [Note] A temporary password is generated for root@localhost: ?iY.1GmJba=J

Copy this password and use this for the post-installation setup wizard.

Step 2 – Post Installation Setup

The MySQL community server has been installed on your system. Now run the following command to apply security on the MySQL server. Simply execute the below command and follow the security wizard.

sudo mysql_secure_installation 

Enter the root password found in the above step, then set a new password for the MySQL root account. Next, follow the onscreen instructions and Press Y for all other operations to apply improved security.

  • Enter password for user root: [Enter current root password]
  • New password: [Enter a new root password]
  • Re-enter new password: [Re-Enter the new root password]
  • Estimated strength of the password: 100
    Change the password for root ? ((Press y|Y for Yes, any other key for No) : n
  • Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
  • Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
  • Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
  • Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
  • All done!

Step 3 – Connect MySQL Terminal

All done. You can now connect to the MySQL server using the command line. The following command will connect MySQL running on localhost as the root user. This will prompt for the root account password.

mysql -u root -p

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.39 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Conclusion

In this tutorial, you have learned to install the MySQL community server on an Amazon Linux 2 system.

Share.

7 Comments

  1. Madan Kumar T on

    Hi Rahul ,
    thank you for the documentation it is very nice , how to handle mysql_secure_installation using script

  2. Anoop Srivastava on

    Thanks Rahul. You have done a great job, now it is really easy to install.

    Looking forward for your next post.

Leave A Reply


Exit mobile version