Installing MySQL Like a Pro on an EC2 Instance 1

Installing MySQL Like a Pro on an EC2 Instance

In this technical guide, we will furnish you with the knowledge and tools required to execute a flawless MySQL installation on an EC2 instance, leveraging the power of the cloud for robust database management. From meticulously provisioning your EC2 instance with the appropriate specifications and security measures to fine-tuning the MySQL configuration for optimal performance, we have tried our best to cover each step. Get ready to navigate the command line interface, execute complex commands, and master the art of EC2 instance management. With our step-by-step instructions and insights into best practices, you’ll learn how to seamlessly set up a resilient MySQL environment, enabling you to handle massive amounts of data with precision and efficiency.

 

This detailed installation guide has been performed on EC2 Instance X86 architecture with Ubuntu 20 running.

After establishing the remote terminal connection and issuing the command to obtain the root access for the whole session.

~# sudo - i 

The first step is to issue the system update command and observe the response as below.

root@ip-172-31-26-246:~# sudo apt update

Hit:1 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:4 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/universe amd64 Packages [8628 kB]
Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:6 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/universe Translation-en [5124 kB]
Get:7 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/universe amd64 c-n-f Metadata [265 kB]
Get:8 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [144 kB]
Get:9 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/multiverse Translation-en [104 kB]
Get:10 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal/multiverse amd64 c-n-f Metadata [9136 B ]
Get:11 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1947 kB]
Get:12 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates/main Translation-en [353 kB]
Get:13 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [15.6 kB]
Get:14 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [1141 kB]
Get:15 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates/restricted Translation-en [162 kB]
Get:16 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates/restricted amd64 c-n-f Metadata [592 B]
Get:17 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [923 kB ]
Get:18 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates/universe Translation-en [208 kB ]
Get:19 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates/universe amd64 c-n-f Metadata [ 20.9 kB]
Get:20 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [24.4 kB]
Get:21 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates/multiverse Translation-en [7336 B]
Get:22 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 c-n-f Metadata [592 B]
Get:23 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-backports/main amd64 Packages [44.8 kB]
Get:24 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-backports/main Translation-en [11.3 kB]
Get:25 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-backports/main amd64 c-n-f Metadata [97 6 B]
Get:26 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-backports/restricted amd64 c-n-f Metada ta [116 B]
Get:27 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [23.7 kB]
Get:28 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-backports/universe Translation-en [15.9 kB]
Get:29 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-backports/universe amd64 c-n-f Metadata [860 B]
Get:30 http://us-east-2.ec2.archive.ubuntu.com/ubuntu focal-backports/multiverse amd64 c-n-f Metada ta [116 B]
Get:31 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [1592 kB]
Get:32 http://security.ubuntu.com/ubuntu focal-security/main Translation-en [271 kB]
Get:33 http://security.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [10.7 kB]
Get:34 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [1051 kB]
Get:35 http://security.ubuntu.com/ubuntu focal-security/restricted Translation-en [149 kB]
Get:36 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 c-n-f Metadata [572 B]
Get:37 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [710 kB]
Get:38 http://security.ubuntu.com/ubuntu focal-security/universe Translation-en [128 kB]
Get:39 http://security.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [14.6 kB]
Get:40 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [22.2 kB]
Get:41 http://security.ubuntu.com/ubuntu focal-security/multiverse Translation-en [5376 B]
Get:42 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 c-n-f Metadata [512 B]
Fetched 23.5 MB in 4s (5699 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
38 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@ip-172-31-26-246:~#

To be followed by the below command to perform the necessary system upgrade in the system

root@ip-172-31-26-246:~# sudo apt upgrade

Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
linux-aws-5.13-headers-5.13.0-1031 linux-headers-5.13.0-1031-aws linux-image-5.13.0-1031-aws
linux-modules-5.13.0-1031-aws
The following packages will be upgraded:
apt apt-utils cloud-init curl dirmngr gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf
gpgsm gpgv intel-microcode isc-dhcp-client isc-dhcp-common libapt-pkg6.0 libcurl3-gnutls libcurl4 libmbim-glib4
libmbim-proxy libmm-glib0 libnss3 libqmi-glib5 libqmi-proxy libssl1.1 linux-aws linux-headers-aws linux-image-aws
modemmanager open-vm-tools openssl snapd ubuntu-advantage-tools unattended-upgrades update-notifier-common
38 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
22 standard security updates
Need to get 95.0 MB of archives.
After this operation, 219 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Note that there is a prompt to continue to and obtain consent to perform the necessary upgrade which involves additional disk space.

See also  Manage and Master -MySQL Database using Python Script on EC2

We can now continue with the actual command for MySQL installation on your Ubuntu distribution.

root@ip-172-31-26-246:~# sudo apt install mysql-server

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl
libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
liblwp-mediatypes-perl libmecab2 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils
mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-core-8.0
Suggested packages:
libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca
The following NEW packages will be installed:
libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl
libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
liblwp-mediatypes-perl libmecab2 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils
mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0
0 upgraded, 25 newly installed, 0 to remove and 0 not upgraded.
Need to get 31.6 MB of archives.
After this operation, 262 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Check the above installation information and desired consent.  Also, note the latest version, 8.0,  MySQL will be installed.

done!
update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode
Setting up libhtml-parser-perl (3.72-5) ...
Setting up libhttp-message-perl (6.22-1) ...
Setting up mysql-server-8.0 (8.0.29-0ubuntu0.20.04.3) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
mysqld will log errors to /var/log/mysql/error.log
mysqld is running as pid 16541
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
Setting up libcgi-pm-perl (4.46-1) ...
Setting up libhtml-template-perl (2.97-1) ...
Setting up mysql-server (8.0.29-0ubuntu0.20.04.3) ...
Setting up libcgi-fast-perl (1:2.15-1) ...
Processing triggers for systemd (245.4-4ubuntu3.17) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
root@ip-172-31-26-246:~# Setting up libhtml-parser-perl (3.72-5) ...

After the MySQL installation is finished,  a log is presented for user information. There is some key information above presented and highlighted for your reference.

root@ip-172-31-26-246:~# service mysql status mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-07-08 00:59:57 UTC; 5min ago
Main PID: 16760 (mysqld)
Status: "Server is operational"
Tasks: 37 (limit: 1145)
Memory: 351.6M
CGroup: /system.slice/mysql.service
└─16760 /usr/sbin/mysqld

Jul 08 00:59:56 ip-172-31-26-246 systemd[1]: Starting MySQL Community Server...
Jul 08 00:59:57 ip-172-31-26-246 systemd[1]: Started MySQL Community Server.
root@ip-172-31-26-246:~#

After the installation, MySQL server should be running if everything went well. Check the command to check the service status of MySQL and report for your reference.

root@ip-172-31-26-246:~# mysql -V
mysql Ver 8.0.29-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))
root@ip-172-31-26-246:~#

 

See also  Mastering Apache Configuration-Tips for Optimal Performance

The above command will help you find the version of MySQL server you have just installed on your Ubuntu distribution.

This important command tells your the version of MySQL server  as well as the version of your Ubuntu distribution.

 

Congrats! you have just installed your first MySQL server on an EC2 Instance running Ubuntu.