How to Install MySQL on Amazon Linux 2023 (Fedora Version)

You are currently viewing How to Install MySQL on Amazon Linux 2023 (Fedora Version)

MySQL is a popular relational database management system (RDBMS) that is used to store and manage data. It is free and open-source software that is available for a wide range of platforms, including Amazon Linux 2023.

This blog post will show you how to install MySQL on Amazon Linux 2023 (Fedora version). We will also show you how to secure your MySQL installation.

Prerequisites

Before you can install MySQL, you will need to have the following prerequisites:

  • An Amazon Linux 2023 instance
  • A terminal window

Installing MySQL

To install MySQL, follow these steps:

  1. Open a terminal window.
  2. Install the MySQL Community repository:
sudo wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm 
sudo ls -lrt
  1. Install the MySQL server:
sudo dnf install mysql80-community-release-el9-1.noarch.rpm
dnf repolist enabled | grep "mysql.*-community.*"
sudo dnf install mysql-community-server
  1. Start the MySQL server:
sudo systemctl start mysqld
sudo mysql -V
  1. Secure the MySQL server:
sudo mysql_secure_installation
  1. Test the MySQL server:
sudo mysql -uroot -p

You should be able to connect to the MySQL server and create a new database. If you can’t connect with an empty password, then edit “my.cnf” file

sudo vi /etc/my.cnf

Add a line to mysqld block.*

skip-grant-tables

Save and exit and then restart MySQL service.

sudo systemctl restart mysqld

Securing MySQL

Once you have installed MySQL, it is essential to secure your installation. To do this, you can use the mysql_secure_installation script. This script will help you set a strong password for the MySQL root user, remove anonymous users, and disable remote root logins.

To run the mysql_secure_installation script, follow these steps:

  1. Open a terminal window.
  2. Run the following command:
sudo mysql_secure_installation

The mysql_secure_installation script will prompt you for several options. You can use the following guidelines to answer the prompts:

  • Set a strong password for the MySQL root user: This is the most important step in securing your installation. Make sure to use a strong password that is not easy to guess.
  • Remove anonymous users: Anonymous users are users who do not have a password. They can be used by attackers to gain access to your MySQL server.
  • Disable remote root logins: Remote root logins allow you to connect to the MySQL server from a remote computer. This can be a security risk, so it is best to disable it.

Testing MySQL

Once you have secured your MySQL installation, you can test it by connecting to the MySQL server and creating a new database.

To connect to the MySQL server, follow these steps:

  1. Open a terminal window.
  2. Run the following command:
mysql -uroot -p

You will be prompted for the password for the MySQL root user. Enter the password that you set in the previous step.

Once you have connected to the MySQL server, you can create a new database by running the following command:

CREATE schema my_database;

You can now use the MySQL server to store and manage your data.

Conclusion

This blog post showed you how to install MySQL on Amazon Linux 2023 (Fedora version). We also showed you how to secure your MySQL installation.

By following the steps in this blog post, you can install and secure MySQL on Amazon Linux 2023. This will allow you to use MySQL to store and manage your data securely.

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

This Post Has 2 Comments

  1. Minh

    I think you need this command to get root password before use “sudo mysql_secure_installation” to config mysql
    sudo grep ‘temporary password’ /var/log/mysqld.log

Leave a Reply