In this article, I will show you how you can install MySQL server on your Amazon Linux 2 machine on AWS, which may help you to get started with your project deployment to AWS. But before that, let me explain what is MySQL.
What is the MySQL database?
MySQL is an open-source relational database management system. Its name is a combination of “My”, the name of co-founder Michael Widenius’s daughter, and “SQL”, the abbreviation for Structured Query Language. Wikipedia
So now we understand that MySQL is an open-source SQL-based database management system. According to these statistics published by statista.com, MySQL is the 2nd most popular database management system on planet Earth. Oracle is not free and also not open-source, so if we consider among the free database management systems, then we can say that MySQL is number 1 in this ranking.
Why you want to install MySQL in Amazon Linux 2
As we discuss in the previous section that MySQL is the number 1 DBMS among the open-source providers, let’s discuss here, what is Amazon Linux 2 and why we want to install MySQL in Amazon Linux 2.
Amazon Linux 2 is the next generation of Amazon Linux, a Linux server operating system from Amazon Web Services (AWS). It provides a secure, stable, and high-performance execution environment to develop and run cloud and enterprise applications. With Amazon Linux 2, you get an application environment that offers long-term support with access to the latest innovations in the Linux ecosystem. Amazon Linux 2 is provided at no additional charge.
There are many open-source Linux distributions available and Amazon Linux 2 is one of the most popular Linux distributions in the web services arena. So if you are using AWS for your project, chances are there that it is an Amazon Linux 2 server and you don’t even know about it.
In most cases, this is fine, because someone else is managing your server, but when you want to manage your own server in AWS or other cloud computing platforms, then it’s obvious that you need to know how to set up MySQL over there. Because your website or application may be using MySQL as their Database system and you must install it on your server to run it smoothly.
How to Install MySQL on Amazon Linux 2
So Amazon Linux 2 is one of the popular operating systems in the webserver arena and that’s why we need to know how can we install the MySQL database server on Amazon Linux 2. At first, you create an EC2 instance in AWS by following my article and then connect to it via Putty or Terminal. I have another article written on how you can connect to your server using Putty here.
Next, I will provide the commands which you can use to install the MySQL server into your Amazon Linux 2 EC2 instance. Let me explain the commands one by one so that you know what you doing and if you are stuck anywhere then you can search the issue specifically by seeing the error message. Note that anything is written after hash-tag(#) is a comment and it will be ignored by SHELL, but we put these comments for you so that you can understand what is happening and later on debug quicker.
sudo yum update -y
So our first command is to update the YUM package. Now, what is YUM and why do we need to update that? An explanation is given below
YUM (Yellowdog Updater Modified) is an open-source command-line as well as graphical-based package management tool for RPM (RedHat Package Manager) based Linux systems. It allows users and system administrators to easily install, update, remove, or search software packages on a system.
So “sudo yum update -y” basically updates all packages to its latest version from a repository list which is managed by Amazon for Amazon Linux 2. So we have updated our package list, now the next command is to install the MySQL server on this machine.
#install mysql server sudo yum install -y mariadb-server
MySQL install command will ask you a few questions, which I described in my video below. When you have given those answers, please run this command to start the MySQL server and enable it to run on boot time as well. Otherwise, if your server reboots then you need to manually run the command to start the MySQL server.
#start the mysql server sudo systemctl start mariadb #enable mysql to start when system reboots sudo systemctl enable mariadb
Next, we need to secure the installation by running this command.
It will ask you a few questions, whose answers are given in my video tutorial, but I am writing it here as well.
Question: Enter current password for root ( enter for none ) :
Answer: Just press enter because there is no root password available as we just did the setup now.
Question: Set Root password? [Y/n]:
Answer: Type here ‘y’ and then press enter. Then it will ask you for new passwords. Please provide a strong password and press enter.
Question: Remove anonymous user? [Y/n]
Answer: type ‘y’ and press enter
Question: Disallow root login remotely? [Y/n]
Answer: type ‘y’ and press enter.
Question: Remove test database and access to it? [Y/n]
Answer: Type ‘y’ and press enter. This will remove the test database and its access to users. If you want to keep the test database then type ‘n’ and press enter. The choice is yours, but I suggest deleting the test database.
Question: Reload privilege tables now? [Y/n]
Answer: Type ‘y’ and press enter. This reloads the privilege tables.
If you have answered the last question, then it’s done and you have secured the MySQL installation.
After that, you can connect to your MySQL server by running this command.
mysql -uroot -p;
if you run this command then it will ask you for the password. Please provide the new password which you set in the MySQL secure installation process. If you have done all the steps correctly then you will probably see this message ” Welcome to the MariaDB monitor”
This welcome message means you have successfully installed the MySQL server on your machine and also connected to it via command prompt.
I have uploaded a detailed video on this as well so that you see it visually.
So in this article, we have seen that MySQL is the number 1 database management system on this planet earth when it comes to open source free alternatives and 2nd in among all RDBMS.
WordPress runs on MySQL, so do other popular CMS like Joomla, Drupal, Magento runs on MySQL database. It’s really important to know as a system administrator or DevOps that how you can install MySQL on AWS using Amazon Linux 2 OS. I hope this might helped you to start with AWS and if you are stuck on any issues feel free to contact me via [email protected] or call me @ +8801554306975