How to Install MySQL 8 on Amazon Linux 2


MySQL is a very popular open source relational database management system that can run on Linux, Windows, and Mac OS. It is commonly used as a back-end database for web applications, although it can also be used to store data for other software. You can use MySQL to store and organize data, retrieve the data as needed, and convert it into another format (for example, change it from text to number). It is commonly used by companies of all sizes as the database for their websites and applications.

This article will detail the installation of MySQL 8 on Amazon Linux 2. When it’s done, you’ll have a fully functioning MySQL database that you can use with the AWS Console or its apps. only me. You can also use Amazon RDS to configure databases other than MySQL.

How to Install MySQL 8 on Amazon Linux

The official MySQL team provides RPM packages for installing Amazon Linux systems. Follow the steps below step by step to complete the installation of MySQL.

    1. Configure the Yum . RepositoryMost packages require dependencies that are available in other third-party repositories. Use the following command to configure the EPEL repository required for package installation.
      sudo amazon-linux-extras install epel -y 

      Then configure the MySQL repository by installing the package provided by the official MySQL website.

      sudo yum install 

    1. Install MySQL ServerYou can successfully configure the repository, your system is ready to install MySQL. Execute below mentioned command to install MySQL 8 community server on Amazon Linux.
      sudo yum install mysql-community-server 

      Press ‘y’ to confirm prompted during installation.

      Install MySQL pacakges on Amazon Linux 2

    1. Enable and start the MySQL serviceAfter the installation finished successfully. The default MySQL service will be stopped and in an inactive state. First, use the following commands to enable the service to automatically start at system startup, then start it manually for the first time.
      systemctl active mysqld  systemctl start mysqld 

      Then use the following command to view the MySQL service status. It should be up and running.

      systemctl status mysqld 
      How to Install MySQL 8 on Amazon Linux 2
      Enable and start the MySQL service

    1. Find the original root passwordDuring the installation of the packages, an initial password is configured for the MySQL root account. You can find this password from the MySQL log file.
      cat /var/log/mysql.log | grep "A temporary password" 

      You should see the output below including the default root password.

      How to Install MySQL 8 on Amazon Linux 2
      Get default root password after installation

      This password will be required in the next step.

    1. Set up MySQL Post settingsA post-install script is provided by the MySQL packages. That is useful for configuring MySQL once after installation. This helps us to configure strong root account password, remote anonymous user, disallow remote root access, and delete test database.

      Execute the following command from the terminal:

      sudo mysql_secure_installation 

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

      • Enter the password for the root user: [Enter current root password]
      • A new password: [Enter a new root password]
      • Enter a new password: [Re-Enter the new root password]
      • Estimated password strength: 100
        Change password for root? ((Press y | Y for Yes, any other key for No): WOMEN
      • 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
      • Delete the test database and access it? (Press y | Y for Yes, any other key for No): y
      • Reload the privileges table now? (Press y | Y for Yes, any other key for No): y
      • All has been done!

  1. Connect to MySQLYour MySQL server is ready to use now. From the terminal, you can run the command below to connect to the MySQL command line interface. It will prompt for the root account password. Upon successful authentication, you will get a MySQL prompt.
    mysql -u root -p 

    Enter the MySQL root user password:


    Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 8.0.30 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>

    Here you can create databases, tables, users and all the necessary things using structured query language statements.

Next Steps to Maintain MySQL

As you are setting up your new database, you should think about how you will maintain the database in the long run. This tutorial focuses on setting up a new database, but you should also consider ways to make your database more automated and easier to manage. A simple way to do this is to automate your database backup process. This will allow you to keep a copy of your data in case something goes wrong and you need to recover it from an earlier point in time. This can be done with the help of some simple scripts that call the MySQL database and write the data to another location.

Last word

There are many reasons why you might want to run your database in the Amazon cloud. Some of the common ones have the cost, ease of setup and maintenance, and the ability to scale as needed. Running your database on Amazon Linux has a few advantages over using another Linux distribution. Amazon has thoroughly tested its distribution and it is optimized to run on its cloud infrastructure. When you’re setting up a new database, it’s important to choose a solution that meets your needs and can grow with your business.

This tutorial focuses on installing MySQL on Amazon Linux, which is one of the easiest and most cost-effective ways to get a new database up and running.

Hope this helps!

Source link