Contact

Blogs

Take a look at the things that interest us.

Install Mysql 8 on Amazon Ec2

Wesley Wesley 3 years

In this blog post, we are going to show you how to install Mysql 8 on our Amazon Linux ec2 server.

Let's start with setting up the rpm repository for MySQL 8.

$ sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

// make sure to write yes when requested

output
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
mysql80-community-release-el7-3.noarch.rpm                                                                                                                                                            |  25 kB  00:00:00     
Examining /var/tmp/yum-root-b3R6bM/mysql80-community-release-el7-3.noarch.rpm: mysql80-community-release-el7-3.noarch
Marking /var/tmp/yum-root-b3R6bM/mysql80-community-release-el7-3.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql80-community-release.noarch 0:el7-3 will be installed
--> Finished Dependency Resolution
amzn2-core/2/x86_64                                                                                                                                                                                   | 3.7 kB  00:00:00     

Dependencies Resolved

=============================================================================================================================================================================================================================
 Package                                                    Arch                                    Version                                   Repository                                                                Size
=============================================================================================================================================================================================================================
Installing:
 mysql80-community-release                                  noarch                                  el7-3                                     /mysql80-community-release-el7-3.noarch                                   31 k

Transaction Summary
=============================================================================================================================================================================================================================
Install  1 Package

Total size: 31 k
Installed size: 31 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-3.noarch                                                                                                                                                                    1/1 
  Verifying  : mysql80-community-release-el7-3.noarch                                                                                                                                                                    1/1 

Installed:
  mysql80-community-release.noarch 0:el7-3                                                                                                                                                                                   

Complete!

To verify the download you can check if a new repository file has been created inside the /etc/yum.repos.d directory.

$ ls /etc/yum.repos.d
output
amzn2-core.repo  amzn2-extras.repo  mysql-community.repo  mysql-community-source.repo

You can also view a list of configured repositories with yum command.

$ sudo yum repolist
output
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
37 packages excluded due to repository priority protections
repo id                                                                                                      repo name                                                                                                 status
amzn2-core/2/x86_64                                                                                          Amazon Linux 2 core repository                                                                            22,401
amzn2extra-docker/2/x86_64                                                                                   Amazon Extras repo for docker                                                                                 34
amzn2extra-php7.2/2/x86_64                                                                                   Amazon Extras repo for php7.2                                                                                737
mysql-connectors-community/x86_64                                                                            MySQL Connectors Community                                                                                138+37
mysql-tools-community/x86_64                                                                                 MySQL Tools Community                                                                                        120
mysql80-community/x86_64                                                                                     MySQL 8.0 Community Server                                                                                   211
repolist: 23,641

Install MySQL 8 on Amazon Linux ec2

Once the repository has been added to our Amazon ec2 Linux server we can start installing MySQL 8.

$ sudo yum install mysql-community-server

// make sure to write yes when requested

output
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                                                                                                                            | 3.7 kB  00:00:00     
37 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:8.0.22-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 8.0.22-1.el7 for package: mysql-community-server-8.0.22-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 8.0.11 for package: mysql-community-server-8.0.22-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:8.0.22-1.el7 will be installed
--> Processing Dependency: mysql-community-client-plugins = 8.0.22-1.el7 for package: mysql-community-client-8.0.22-1.el7.x86_64
--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.22-1.el7.x86_64
--> Processing Dependency: libncurses.so.5()(64bit) for package: mysql-community-client-8.0.22-1.el7.x86_64
--> Processing Dependency: libtinfo.so.5()(64bit) for package: mysql-community-client-8.0.22-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:8.0.22-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.68-1.amzn2 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.amzn2.0.3.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.amzn2.0.3.x86_64
---> Package mysql-community-client-plugins.x86_64 0:8.0.22-1.el7 will be installed
---> Package mysql-community-libs.x86_64 0:8.0.22-1.el7 will be obsoleting
---> Package ncurses-compat-libs.x86_64 0:6.0-8.20170212.amzn2.1.3 will be installed
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:8.0.22-1.el7 will be obsoleting
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================================================
 Package                                                         Arch                                    Version                                                    Repository                                          Size
=============================================================================================================================================================================================================================
Installing:
 mysql-community-libs                                            x86_64                                  8.0.22-1.el7                                               mysql80-community                                  4.6 M
     replacing  mariadb-libs.x86_64 1:5.5.68-1.amzn2
 mysql-community-libs-compat                                     x86_64                                  8.0.22-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.22-1.el7                                               mysql80-community                                  510 M
Installing for dependencies:
 mysql-community-client                                          x86_64                                  8.0.22-1.el7                                               mysql80-community                                   48 M
 mysql-community-client-plugins                                  x86_64                                  8.0.22-1.el7                                               mysql80-community                                  235 k
 mysql-community-common                                          x86_64                                  8.0.22-1.el7                                               mysql80-community                                  616 k
 ncurses-compat-libs                                             x86_64                                  6.0-8.20170212.amzn2.1.3                                   amzn2-core                                         308 k

Transaction Summary
=============================================================================================================================================================================================================================
Install  3 Packages (+4 Dependent packages)

Total download size: 564 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/2/mysql80-community/packages/mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm is not installed
(1/7): mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm                                                                                                                                         | 235 kB  00:00:00     
(2/7): mysql-community-common-8.0.22-1.el7.x86_64.rpm                                                                                                                                                 | 616 kB  00:00:00     
(3/7): mysql-community-libs-8.0.22-1.el7.x86_64.rpm                                                                                                                                                   | 4.6 MB  00:00:00     
(4/7): mysql-community-libs-compat-8.0.22-1.el7.x86_64.rpm                                                                                                                                            | 1.2 MB  00:00:00     
(5/7): mysql-community-client-8.0.22-1.el7.x86_64.rpm                                                                                                                                                 |  48 MB  00:00:00     
(6/7): ncurses-compat-libs-6.0-8.20170212.amzn2.1.3.x86_64.rpm                                                                                                                                        | 308 kB  00:00:00     
(7/7): mysql-community-server-8.0.22-1.el7.x86_64.rpm                                                                                                                                                 | 510 MB  00:00:15     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                         36 MB/s | 564 MB  00:00:15     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql80-community-release-el7-3.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-8.0.22-1.el7.x86_64                                                                                                                                                                1/8 
  Installing : mysql-community-client-plugins-8.0.22-1.el7.x86_64                                                                                                                                                        2/8 
  Installing : mysql-community-libs-8.0.22-1.el7.x86_64                                                                                                                                                                  3/8 
  Installing : ncurses-compat-libs-6.0-8.20170212.amzn2.1.3.x86_64                                                                                                                                                       4/8 
  Installing : mysql-community-client-8.0.22-1.el7.x86_64                                                                                                                                                                5/8 
  Installing : mysql-community-server-8.0.22-1.el7.x86_64                                                                                                                                                                6/8 
  Installing : mysql-community-libs-compat-8.0.22-1.el7.x86_64                                                                                                                                                           7/8 
  Erasing    : 1:mariadb-libs-5.5.68-1.amzn2.x86_64                                                                                                                                                                      8/8 
  Verifying  : mysql-community-libs-8.0.22-1.el7.x86_64                                                                                                                                                                  1/8 
  Verifying  : ncurses-compat-libs-6.0-8.20170212.amzn2.1.3.x86_64                                                                                                                                                       2/8 
  Verifying  : mysql-community-server-8.0.22-1.el7.x86_64                                                                                                                                                                3/8 
  Verifying  : mysql-community-client-plugins-8.0.22-1.el7.x86_64                                                                                                                                                        4/8 
  Verifying  : mysql-community-common-8.0.22-1.el7.x86_64                                                                                                                                                                5/8 
  Verifying  : mysql-community-client-8.0.22-1.el7.x86_64                                                                                                                                                                6/8 
  Verifying  : mysql-community-libs-compat-8.0.22-1.el7.x86_64                                                                                                                                                           7/8 
  Verifying  : 1:mariadb-libs-5.5.68-1.amzn2.x86_64                                                                                                                                                                      8/8 

Installed:
  mysql-community-libs.x86_64 0:8.0.22-1.el7                            mysql-community-libs-compat.x86_64 0:8.0.22-1.el7                            mysql-community-server.x86_64 0:8.0.22-1.el7                           

Dependency Installed:
  mysql-community-client.x86_64 0:8.0.22-1.el7      mysql-community-client-plugins.x86_64 0:8.0.22-1.el7      mysql-community-common.x86_64 0:8.0.22-1.el7      ncurses-compat-libs.x86_64 0:6.0-8.20170212.amzn2.1.3     

Replaced:
  mariadb-libs.x86_64 1:5.5.68-1.amzn2                                                                                                                                                                                       

Complete!

Start and Enable MySQL 8 on Amazon Linux ec2

Now MySQL 8 has been installed we can start with configuring. Let's enable and start MySQL 8.

$ systemctl enable mysqld
$ systemctl start mysqld

We can check with the following command if MySQL 8 is running now.

$ systemctl status mysqld
output
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2020-11-20 01:27:06 UTC; 4s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 10063 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 10178 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─10178 /usr/sbin/mysqld

Nov 20 01:27:00 ip-172-31-27-184.ap-northeast-1.compute.internal systemd[1]: Starting MySQL Server...
Nov 20 01:27:06 ip-172-31-27-184.ap-northeast-1.compute.internal systemd[1]: Started MySQL Server.

Configure MySQL 8 on Amazon Linux ec2

When MySQL 8 is installed, a superuser account ‘root’@’localhost is created with an initial password set and stored in the error log file.

To reveal this password, use the following command:

sudo grep 'temporary password' /var/log/mysqld.log
output
2020-11-20T01:27:03.069950Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: <password>

You can use this password to start the configuration process.

You have to set a new password and other settings to better secure access to the MySQL server. Your password needs to have:

  • 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.

Make sure to follow the configuration process until the end.

sudo mysql_secure_installation -p'<password>'
output
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: 
 ... Failed! Error: Your password does not satisfy the current policy requirements

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) : y

New password: 

Re-enter new 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) : y
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! 

MySQL 8 has been installed.

Install Mysql 8 on Amazon Ec2 2021-08-24 08:15:53

There are no comments.

4221

Have questions about our services?

Contact our Sales team to get answers.

Contact Us
gomibako@aska-ltd.jp