How to Install MySQL on Amazon Linux 2

How to Install MySQL on Amazon Linux 2

Installing MySQL server on amazon aws Linux 2 server is very easy, there are few commands to use, and you can easily install and configure mysql 8 client on amazon aws linux 2 in just a few minutes. First, connect to the Amazon AWS Linux 2 server and use the sudo yum install -y mariadb-server && sudo mysql_secure_installation commands on aws ssh terminal window to install and configure it.

MySQL is an RDBMS system, which means it is a relational database management system based on a structured query language. Storing, managing, and retrieving structured data using it.

Here are some steps to install, configure, and secure MySQL 8 client on Amazon AWS linux 2 ec2 server:

Step 1 – Connect to Amazon Aws Linux 2 Server

To connect your Amazon AWS Linux 2 instance from putty ssh or aws terminal.

If you do not know how to connect amazon aws Linux 2 ec2 instance with Windows, Ubuntu, and Mac systems. Read this guide: How to Connect to ec2 Instance From Putty and SSH Terminal.

Step 2 – Update System Packages

It’s a good practice to update your system’s package list and upgrade existing packages:

sudo yum -y update

Step 3 – Install MySQL 8 on Amazon AWS Linux 2

To install MySQL 8 client database on Amazon AWS Linux 2 server, Run sudo yum install -y mariadb-server command on aws ssh terminal window:

sudo yum install -y mariadb-server

During the installation, you’ll be prompted to set a password for the MySQL root user. Make sure to choose a strong password and remember it, as you’ll need it to access MySQL.

To check the MySQL server status, use systemctl status mysqld command:

systemctl status mysqld

Step 4 – Enable and Start MySQL Service

In the Amazon AWS Linux 2 server, by default MySQL service will be stopped and will be in an inactive state, you can enable and activate it using sudo systemctl enable mariadb && sudo systemctl start mariadb command on the SSH terminal window:

sudo systemctl enable mariadb && sudo systemctl start mariadb

Step 5 – Secure MySQL 8 on Amazon AWS Linux 2 Server

Once you have installed MySQL on your Amazon AWS Linux 2 server, it is important to secure it so that no unauthenticated users can access it.

To secure MySQL client, Type sudo mysql_secure_installation command on ssh terminal window:

sudo mysql_secure_installation

This will be asked to configure the VALIDATE PASSWORD PLUGIN which is used to test the strength of the MySQL user’s passwords and improve security.

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: 

Press y if you want to set up the validate password plugin or any other key to move to the next step.

There are three levels of password validation policy, low, medium, and strong; is as follows:

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 

Enter 2 for strong password validation.

On the next prompt, will be asked to set a password for the MySQL root user.

Please set the password for root here.

If you need to set up the validate password plugin, the script will show you the strength of your new password. Type y to confirm the password.

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :

Press y on all queries on ssh terminal to remove the anonymous user, restrict root user access to the local machine, delete the test database, and reload the privilege tables.

Step 6 – Verify installation by logging into MySQL as root

First, restart mysql server, Run sudo systemctl restart mariadb to restart the service:

sudo systemctl restart mariadb

Now log in to the MySQL server as the root user and verify installation, use mysql -h localhost -u root -p command on ssh terminal window:

mysql -h localhost -u root -p

Conclusion

Congratulations! You’ve successfully installed MySQL 8 on your Amazon aws ec2 linux 2 server. You can now start using MySQL client to manage your databases and data.

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *