MySQL is a very popular open-source relational database management system that can run on Linux, Windows, and Mac OS. It’s typically used as the back-end database for web applications, though it can also be used to store data for other software. You can use MySQL to store and organize data, retrieve it when needed, and transform it into a different format (e.g. changing it from text to numbers). It’s commonly used by companies of all sizes as the database for their websites and applications.
This article will walk through the process of installing MySQL 8 on Amazon Linux 2. When you’re finished, you’ll have a fully-functioning MySQL database that you can use with either the AWS Console or your own application. You can also use Amazon RDS to configure other databases besides MySQL.
How to Install MySQL 8 on Amazon Linux
The MySQL official team provides the RPM packages for the installation of Amazon Linux systems. Follow the below steps one by one to complete the MySQL installation.
- Configure Yum Repository
Most of the packages required the dependencies that are available in other third-party repositories. Use the following command to configure the EPEL repository that is required for package installation.
sudo amazon-linux-extras install epel -y
Then configure the MySQL repository by installing the package provided by the MySQL official site.
sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
- Install MySQL Server
You can successfully configure the repositories, your system is ready for MySQL installation. Execute the below-mentioned command to install MySQL 8 community server on Amazon Linux.
sudo yum install mysql-community-server
Press ‘y’ for the confirmation prompted during the installation.
- Activate and Start MySQL Service
Once the installation is successfully finished. The default MySQL service will be stopped and in an inactive state. First, use the following commands to activate the service to auto-start on 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 active and running.
systemctl status mysqld
- Find initial root password
During the installation of 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 will see the output below that includes the default root password.
This password will be required in the next step.
- MySQL Post Installation Setup
A post-installation script is provided by the MySQL packages. That is helpful for configuring MySQL once after the installation. This helps us to configure a strong root account password, remote anonymous users, disallow root access remotely and remove the test database.
Execute the following command from the terminal:
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!
- Connect to MySQL
Your MySQL server is ready to use now. From the terminal, you can run the below command to connect to the MySQL command line interface. It will prompt for the root account password. On successful authentication, you will get the MySQL prompt.
mysql -u root -p
Enter the MySQL root user password:Output: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 required things by using the structured query language statements.
Next Steps for Maintaining MySQL
As you’re setting up your new database, it’s a good idea to put some thought into how you will maintain the database in the long term. This guide focuses on setting up a new database, but you should also consider ways to make your database more automated and easier to manage. One simple way to do this is to automate the process of backing up your database. This will allow you to keep a copy of your data in case something goes wrong and you need to restore it from a previous point in time. This can be done with the help of some simple scripts that call the MySQL database and write the data to a different location.
There are many reasons why you might want to run your database on Amazon’s cloud. Some common ones have cost, ease of setup and maintenance, and the ability to scale up or down as needed. Running your database on Amazon Linux has a few advantages over using a different Linux distribution. Amazon has thoroughly tested its distribution and it is optimized for running 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 guide 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.