7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Amazon Linux2でmysqlを入れようとしたらエラーが出た

Posted at

いろいろブランク空いたのでEC2を色々触っていたところ、詰まったことがあったので残します。

環境

Amazon Linux2 を使用
Amazon Linux 2 AMI (HVM), SSD Volume Type

起こったこと

nginxと連携するDB入れたかったので、
mysqlをEC2で入れよう!とやってみたところ

[ec2-user@host ~]$ sudo yum install mysql-server
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
No package mysql-server available.
Error: Nothing to do

あれ、、?

AmazonLinux2ってAWSリポジトリにmysql入ってないんだっけ、、

[ec2-user@host ~]$ sudo yum list mysql*
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Available Packages
MySQL-python.x86_64                                       1.2.5-1.amzn2.0.2                                amzn2-core
mysql-connector-java.noarch                               1:5.1.25-3.amzn2                                 amzn2-core
mysql-connector-odbc.x86_64                               5.2.5-7.amzn2                                    amzn2-core

あ! そういえば
[ec2-user@host ~]$ sudo yum list maria*
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Installed Packages
mariadb-libs.x86_64                                       1:5.5.62-1.amzn2.0.1                             installed
Available Packages
mariadb.x86_64                                            1:5.5.62-1.amzn2.0.1                             amzn2-core
mariadb-bench.x86_64                                      1:5.5.62-1.amzn2.0.1                             amzn2-core
mariadb-devel.x86_64                                      1:5.5.62-1.amzn2.0.1                             amzn2-core
mariadb-embedded.x86_64                                   1:5.5.62-1.amzn2.0.1                             amzn2-core
mariadb-embedded-devel.x86_64                             1:5.5.62-1.amzn2.0.1                             amzn2-core
mariadb-libs.i686                                         1:5.5.62-1.amzn2.0.1                             amzn2-core
mariadb-server.x86_64                                     1:5.5.62-1.amzn2.0.1                             amzn2-core
mariadb-test.x86_64                                       1:5.5.62-1.amzn2.0.1                             amzn2-core

mariadbかあああ(既視感)

デフォルトではmariadbが使えるみたいですね。

[ec2-user@host ~]$ sudo yum install mariadb-server
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                                    | 2.4 kB  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package mariadb-server.x86_64 1:5.5.62-1.amzn2.0.1 will be installed
 (省略)
Installed:
  mariadb-server.x86_64 1:5.5.62-1.amzn2.0.1

Dependency Installed:
  mariadb.x86_64 1:5.5.62-1.amzn2.0.1                      perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.amzn2.0.2
  perl-Compress-Raw-Zlib.x86_64 1:2.061-4.amzn2.0.2        perl-DBD-MySQL.x86_64 0:4.023-6.amzn2
  perl-DBI.x86_64 0:1.627-4.amzn2.0.2                      perl-Data-Dumper.x86_64 0:2.145-3.amzn2.0.2
  perl-IO-Compress.noarch 0:2.061-2.amzn2                  perl-Net-Daemon.noarch 0:0.48-5.amzn2
  perl-PlRPC.noarch 0:0.2020-14.amzn2

Complete!

解決。 …こうやって引っかかるの、(初心者)あるあるでしょうか。笑
結果、今回用途的には触れれば別に良かったのでmariadb使います。

因みにmysqlをEC2で使いたい場合は公式からもってくる必要があるのかなと思います。

Download MySQL Yum Repository
https://dev.mysql.com/downloads/repo/yum/

[ec2-user@host ~]$ sudo yum localinstall https://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
 (省略)
[ec2-user@host ~]$ sudo yum list |grep mysql
mysql-community-release.noarch          el7-5                         installed
[ec2-user@host ~]$ cat /etc/yum.repos.d/mysql-community.repo
 (確認)

など。

Amazon Linuxのリポジトリ(おまけ)

ついでにepelリポジトリの話を記載します。

Amazon Linux「パッケージリポジトリ」 - AWSドキュメント
https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/amazon-linux-ami-basics.html#package-repository

Amazon Linux 2 および Amazon Linux AMI は、各 Amazon EC2 のリージョンでホストされているオンラインパッケージリポジトリと一緒に使用するように設計されています。

Amazon LinuxはCentOS7ベースですが、用意されたはじめのリポジトリでは足りないことがよくあり
**エンタープライズ Linux 用の拡張パッケージ(EPEL)**を追加することが多いかと思います。

なので、私はEC2使い始めに行うyum update等と一緒にいつもAmazon Linux Extrasでepel追加します。

Amazon Linux 2 に関するよくある質問
https://aws.amazon.com/jp/amazon-linux-2/faqs/

以下コマンドで追加可能です。

[ec2-user@host ~]$ sudo amazon-linux-extras install epel
Installing epel-release
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-docker amzn2extra-epel amzn2extra-nginx1.12
 (省略)
Installed:
  epel-release.noarch 0:7-11

Complete!
  0  ansible2                 available    [ =2.4.2  =2.4.6 ]
  2  httpd_modules            available    [ =1.0 ]
  3  memcached1.5             available    [ =1.5.1  =1.5.16 ]
  4  nginx1.12=latest         enabled      [ =1.12.2 ]
  5  postgresql9.6            available    [ =9.6.6  =9.6.8 ]
  6  postgresql10             available    [ =10 ]
  8  redis4.0                 available    [ =4.0.5  =4.0.10 ]
  9  R3.4                     available    [ =3.4.3 ]
 10  rust1                    available    \
        [ =1.22.1  =1.26.0  =1.26.1  =1.27.2  =1.31.0 ]
 11  vim                      available    [ =8.0 ]
 13  ruby2.4                  available    [ =2.4.2  =2.4.4 ]
 15  php7.2                   available    \
        [ =7.2.0  =7.2.4  =7.2.5  =7.2.8  =7.2.11  =7.2.13  =7.2.14
          =7.2.16  =7.2.17 ]
 16  php7.1                   available    \
        [ =7.1.22  =7.1.25  =7.1.27  =7.1.28 ]
 17  lamp-mariadb10.2-php7.2  available    \
        [ =10.2.10_7.2.0  =10.2.10_7.2.4  =10.2.10_7.2.5
          =10.2.10_7.2.8  =10.2.10_7.2.11  =10.2.10_7.2.13
          =10.2.10_7.2.14  =10.2.10_7.2.16  =10.2.10_7.2.17 ]
 18  libreoffice              available    [ =5.0.6.2_15  =5.3.6.1 ]
 19  gimp                     available    [ =2.8.22 ]
 20  docker=latest            enabled      \
        [ =17.12.1  =18.03.1  =18.06.1 ]
 21  mate-desktop1.x          available    [ =1.19.0  =1.20.0 ]
 22  GraphicsMagick1.3        available    [ =1.3.29 ]
 23  tomcat8.5                available    \
        [ =8.5.31  =8.5.32  =8.5.38 ]
 24  epel=latest              enabled      [ =7.11 ]
 25  testing                  available    [ =1.0 ]
 26  ecs                      available    [ =stable ]
 27  corretto8                available    \
        [ =1.8.0_192  =1.8.0_202  =1.8.0_212 ]
 28  firecracker              available    [ =0.11 ]
 29  golang1.11               available    [ =1.11.3 ]
 30  squid4                   available    [ =4 ]
 31  php7.3                   available    [ =7.3.2  =7.3.3  =7.3.4 ]
 32  lustre2.10               available    [ =2.10.5 ]
 33  java-openjdk11           available    [ =11 ]
 34  lynis                    available    [ =stable ]

\ お、Ansibleだ! /

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?