How to install MySQL 5.7 community server on Amazon EC2 instances with Amazon Linux AMI

How to install MySQL 5.7 community server on Amazon EC2 instances with Amazon Linux AMI

Follow following basic steps in order to instal MySQL 5.7 on Amazon EC2 Instance.

1 - Choose Amazon Linux 2 as Amazon Linux 1 doesn't support systemd which is indispensable for MySQL 5.7 Community Server.

Amazon Linux 2 includes the widely adopted systemd init system which is used to bootstrap the user space as well as manage system processes.

2 - Within the MySQL Yum repository, different release series of the MySQL Community Server are hosted in different subrepositories. The subrepository for the latest GA series (currently MySQL 5.7) is enabled by default, and the subrepositories for all other series (for example, the MySQL 5.6 series) are disabled by default. Use this command to see all the subrepositories in the MySQL Yum repository, and see which of them are enabled or disabled (for Fedora, replace yum in the command withdnf):
shell> yum repolist all | grep mysql
Besides using yum-config-manager or the dnf config-manager command, you can also select a release series by editing manually the /etc/yum.repos.d/mysql-community.repo file. This is a typical entry for a release series' subrepository in the file:
name=MySQL 5.7 Community Server
Find the entry for the subrepository you want to configure, and edit the enabled option. Specify enabled=0 to disable a subrepository, or enabled=1 to enable a subrepository

  1. Verify that the correct subrepositories have been enabled and disabled by running the following command and checking its output (for Fedora, replace yum in the command with dnf):
    shell> yum repolist enabled | grep mysql
  2. Installing MySQL

    Install MySQL by the following command (for Fedora, replace yum in the command with dnf):
    shell> sudo yum install mysql-community-server
    This installs the package for MySQL server (mysql-community-server) and also packages for the components required to run the server, including packages for the client (mysql-community-client), the common error messages and character sets for client and server (mysql-community-common), and the shared client libraries (mysql-community-libs).
  3. Starting the MySQL Server

    Start the MySQL server with the following command:
    shell> sudo service mysqld start
    Starting mysqld:[ OK ]
    You can check the status of the MySQL server with the following command:
    shell> sudo service mysqld status
    mysqld (pid 3066) is running.
At the initial start up of the server, the following happens, given that the data directory of the server is empty:
  • The server is initialized.
  • SSL certificate and key files are generated in the data directory.
  • validate_password is installed and enabled.
  • A superuser account 'root'@'localhost is created. A password for the superuser is set and stored in the error log file. To reveal it, use the following command:
    shell> sudo grep 'temporary password' /var/log/mysqld.log
    Change the root password as soon as possible by logging in with the generated, temporary password and set a custom password for the superuser account:
    shell> mysql -uroot -p
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
    validate_password is installed by default. The default password policy implemented by validate_password requires that passwords contain at least one upper case letter, one lower case letter, one digit, and one special character, and that the total password length is at least 8 characters.

Post a Comment