" />

スポンサーリンク

AWS

EC2-Amazonlinux2にMySQL8.0をインストールする

更新日:

MySQLリポジトリを設定

sh-4.2# sudo yum update -y
...
Complete!

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

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

Complete!

sh-4.2# sudo yum repolist
Loaded plugins: ovl, priorities
...
amzn2-core/2/aarch64                   Amazon Linux 2 core repository      18716
mysql-connectors-community/aarch64     MySQL Connectors Community         131+34
mysql-tools-community/aarch64          MySQL Tools Community                  53
mysql80-community/aarch64              MySQL 8.0 Community Server            154
...

MySQLをインストール

このように、GPGキーがうんにゃらかんにゃらと怒られた場合は、
鍵を最新化してください。

The GPG keys listed for the "MySQL 8.0 Community Server" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.


 Failing package is: mysql-community-client-8.0.28-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

$ sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

MySQLをインストールします。

$ sudo yum install mysql-community-server -y
読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                               | 3.7 kB     00:00     
259 packages excluded due to repository priority protections
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ mysql-community-server.x86_64 0:8.0.28-1.el7 を インストール
--> 依存性の処理をしています: mysql-community-icu-data-files = 8.0.28-1.el7 のパッケージ: mysql-community-server-8.0.28-1.el7.x86_64
--> トランザクションの確認を実行しています。
---> パッケージ mysql-community-icu-data-files.x86_64 0:8.0.28-1.el7 を インストール
--> 依存性解決を終了しました。

依存性を解決しました

================================================================================
 Package                         アーキテクチャー
                                         バージョン    リポジトリー        容量
================================================================================
インストール中:
 mysql-community-server          x86_64  8.0.28-1.el7  mysql80-community  451 M
依存性関連でのインストールをします:
 mysql-community-icu-data-files  x86_64  8.0.28-1.el7  mysql80-community  2.1 M

トランザクションの要約
================================================================================
インストール  1 パッケージ (+1 個の依存関係のパッケージ)

合計容量: 453 M
インストール容量: 2.1 G
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : mysql-community-icu-data-files-8.0.28-1.el7.x   1/2 
  インストール中          : mysql-community-server-8.0.28-1.el7.x86_64      2/2 
  検証中                  : mysql-community-icu-data-files-8.0.28-1.el7.x   1/2 
  検証中                  : mysql-community-server-8.0.28-1.el7.x86_64      2/2 

インストール:
  mysql-community-server.x86_64 0:8.0.28-1.el7                                  

依存性関連をインストールしました:
  mysql-community-icu-data-files.x86_64 0:8.0.28-1.el7                          

完了しました!

// MySQLクライアントのインストール確認
$ mysql --version
mysql  Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)

// MySQL本体のインストール確認
$ mysqld --version
/usr/sbin/mysqld  Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)

MySQLを起動

$ sudo systemctl enable --now mysqld

$ systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 木 2022-02-24 13:04:43 UTC; 2s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3806 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 3877 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─3877 /usr/sbin/mysqld

 2月 24 13:04:37 ip-172-31-12-19.ap-northeast-1.compute.internal systemd[1]: ...
 2月 24 13:04:43 ip-172-31-12-19.ap-northeast-1.compute.internal systemd[1]: ...
Hint: Some lines were ellipsized, use -l to show in full.

MySQLに接続

いきなりrootで接続することはできません

$ mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

mysql_secure_installation というのを使って、パスワードを設定するのが常套です。

$ sudo grep 'temporary password' /var/log/mysqld.log
2022-02-24T13:04:39.427198Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: PoIzoZ.e/0M6

$ sudo mysql_secure_installation -p'PoIzoZ.e/0M6'
mysql_secure_installation: [Warning] Using a password on the command line interface can be insecure.

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

 ... skipping.
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 -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.28 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

データベース&ユーザー作成

mysql> CREATE DATABASE okozukai CHARACTER SET =utf8mb4;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE USER 'okozukaiadmin'@'localhost' IDENTIFIED BY 'lknuve7gAre';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> CREATE USER 'okozukaiadmin'@'localhost' IDENTIFIED BY 'lknuve7gAre%';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON * . * TO 'okozukaiadmin'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[ec2-user@ip-172-31-12-19 ~]$ mysql -uokozukaiadmin -plknuve7gAre%

参考リンク

スポンサーリンク

-AWS

Copyright© ノリックジオグラフィック for Webエンジニア , 2022 All Rights Reserved Powered by AFFINGER5.