SQL stands for “structured query language” and it makes up the name MySQL, which is the combination of My and SQL. My is the name of MySQL’s co-founder, Monty Widenius daughter. MySQL is an open source database management system created primarily for the management of relational databases. For commercial use cases you can buy a license from Oracle for premium support.
In this article I’ll walk you through the installation of MySQL 8.0 on Amazon Linux 2 Server running on AWS Cloud or as a Virtual Machine somewhere in your data center. If you need a detailed article on the new features of MySQL 8, checkout the official release notes page.
Install MySQL 8 on Amazon Linux 2
Amazon Linux is a derivative of CentOS 7 Linux server with few extra repositories and packages for improved performance and integrations with other AWS cloud services. You can check the release of your server by running the following command in the terminal.
$ cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
Step 1: Add MySQL Yum Repository to Amazon Linux 2
First, we need to add the MySQL Yum repository to our Amazon Linux 2 server’s repository list. This operation is only done once and provides all MySQL package versions repositories.
Install an RPM repository package by running the commands below:
sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
Hit the y key in your keyboard when prompted to start the installation.
Dependencies Resolved
======================================================================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================================================================
Installing:
mysql80-community-release noarch el7-5 /mysql80-community-release-el7-5.noarch 9.1 k
Transaction Summary
======================================================================================================================================================================================================
Install 1 Package
Total size: 9.1 k
Installed size: 9.1 k
Is this ok [y/d/N]: y
Verify that the package was installed successfully.
....
Total size: 9.1 k
Installed size: 9.1 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql80-community-release-el7-5.noarch 1/1
Verifying : mysql80-community-release-el7-5.noarch 1/1
Installed:
mysql80-community-release.noarch 0:el7-5
Complete!
A new repository file has been created inside the /etc/yum.repos.d directory.
$ ls /etc/yum.repos.d
amzn2-core.repo amzn2-extras.repo mysql-community.repo mysql-community-source.repo
You can also view list of configured repositories with yum command.
$ sudo yum repolist
repo id repo name status
amzn2-core/2/x86_64 Amazon Linux 2 core repository 27418
amzn2extra-docker/2/x86_64 Amazon Extras repo for docker 56
mysql-connectors-community/x86_64 MySQL Connectors Community 181+49
mysql-tools-community/x86_64 MySQL Tools Community 138
mysql80-community/x86_64 MySQL 8.0 Community Server 321
repolist: 28114
Step 2: Install MySQL 8 on Amazon Linux 2
Once the repository has been added, install MySQL 8 server packages on Amazon Linux 2.
sudo amazon-linux-extras install epel -y
sudo yum -y install mysql-community-server
A number of dependencies are installed in the process.
Dependencies Resolved
======================================================================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================================================================
Installing:
mysql-community-libs x86_64 8.0.28-1.el7 mysql80-community 4.7 M
replacing mariadb-libs.x86_64 1:5.5.68-1.amzn2
mysql-community-libs-compat x86_64 8.0.28-1.el7 mysql80-community 1.2 M
replacing mariadb-libs.x86_64 1:5.5.68-1.amzn2
mysql-community-server x86_64 8.0.28-1.el7 mysql80-community 451 M
Installing for dependencies:
mysql-community-client x86_64 8.0.28-1.el7 mysql80-community 53 M
mysql-community-client-plugins x86_64 8.0.28-1.el7 mysql80-community 5.7 M
mysql-community-common x86_64 8.0.28-1.el7 mysql80-community 630 k
mysql-community-icu-data-files x86_64 8.0.28-1.el7 mysql80-community 2.1 M
ncurses-compat-libs x86_64 6.0-8.20170212.amzn2.1.3 amzn2-core 308 k
Transaction Summary
======================================================================================================================================================================================================
Install 3 Packages (+5 Dependent packages)
Total download size: 518 M
Is this ok [y/d/N]: y
Core packages installed are:
- MySQL server: mysql-community-server
- MySQL client: mysql-community-client
- Common error messages and character sets for client and server: mysql-community-common
- Shared client libraries: mysql-community-libs
Step 3: Start and Configure MySQL 8 on Amazon Linux 2
The next step is to start MySQL server services.
sudo systemctl enable --now mysqld
Confirm if MySQL server service is started and running.
$ systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2022-03-18 07:30:52 UTC; 2s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 4807 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 4880 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─4880 /usr/sbin/mysqld
Aug 12 17:25:33 amazon-linux systemd[1]: Starting MySQL Server...
Aug 12 17:25:38 amazon-linux systemd[1]: Started MySQL Server.
A superuser account ‘root’@’localhost is created with initial password set and stored in the error log file. To reveal it, use the following command:
$ sudo grep 'temporary password' /var/log/mysqld.log
2020-08-12T17:25:34.992227Z 6 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: BEw-U?DV,7eO
Use this initial password to harden the server.
$ sudo mysql_secure_installation -p
Enter password:
Set new password and set other settings to better secure access to MySQL server.
Securing the MySQL server deployment.
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) :
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
You can update root password anytime from MySQL shell.
$ mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '[email protected]!';
The Password Policy is requires:
- At least one uppercase letter
- At least one lowercase letter
- At least one digit
- At least one special character
- Total password length is at least 8 characters.
You have installed MySQL 8 server successfully on Amazon Linux 2 and ready to roll