LoginSignup
8
3

More than 3 years have passed since last update.

[Oracle Cloud] MySQL Database Service の Getting Started をやってみた

Last updated at Posted at 2020-09-26

はじめに

Oracle Cloud Infrastructure(以下OCI) の Tokyo Region で、MySQL マネージドサービスの MySQL Database Service が最近使えるようになりました。Oracle の MySQL チームによって、開発・管理・サポートされている MySQL のマネージドサービスです。自動構成・自動バックアップ・自動メンテナンスなど、Oracle 側でマネージドされており、作成や保守作業などを Cloud 側にお任せ出来ます。

OCI の Document に、MySQL Database Service の Getting Start が公開されています。今回の記事は、この Getting Start に沿った各手順を丁寧に紹介していきます。

やること

  • MySQL Database Service を作成
  • CentOS7 を MySQL のアクセス元として構築
  • MySQL Shell と、MySQL Client から MySQL Database Service に接続

事前準備 : Network 作成

MySQL Database Service は、仮想ネットワーク内の Subnet に構成するため、ファイアウォールの Security List に、3306 のポートを開けておきます。

1601085184769.png

MySQL Database Service を作成

MySQL のメニューから、DB Systems を選択します。

1601068769589.png

Create MySQL DB System を選択します。

1601068809164.png

各種パラメータを指定します。いくつかのパラメータを紹介します。

  • Shape : CPU や メモリなどのリソースを選択します。2020.9月時点では、次の4個から選択可能です。環境によっては、Service Limit の上限に引っかかる場合があります。こちらのDocumentに、上限緩和の申請方法が書いています。
    • VM.Standard.E2.1 : 1 OCPU (2 vCPU), 8 GBメモリ
    • VM.Standard.E2.2 : 2 OCPU (4 vCPU), 16 GBメモリ
    • VM.Standard.E2.4 : 4 OCPU (8 vCPU), 32 GBメモリ
    • VM.Standard.E2.8 : 8 OCPU (16 vCPU), 64 GBメモリ
  • Configuration Options : MySQL DB システムを操作する変数のまとまりを選択します。Configuration を Custom することで、Connection の上限などのパラメータを指定可能です。

1601068948285.png

各種パラメータを指定します。ユーザー名、パスワード、構成するネットワークなどを指定します。

1601069128892.png

自動バックアップの有無や、保存期間を指定して、Create を押します。

1601069282936.png

Creating となります。自分の環境では、約13分ほどで Active に切り替わりました。

1601069311755.png

Active となっています。各種詳細な情報が見えます。

1601070107246.png

Endpoint の欄です。VCN 内で使える名前解決や、それに紐づく IP アドレス、ポートがが確認可能です。

1601070219179.png

Backup の欄です。自動バックアップの結果や、手動バックアップの実行、バックアップから新たな MySQL へリストアが出来ます。

1601070244277.png

接続確認 MySQL Shell

MySQL Database Service の作成が出来たので、早速、同一 VCN の CentOS 7 からアクセス確認をしてみましょう。まず、CentOS 7 に、MySQL Shell をインストールしていきますが、そのまえに、現在の CentOS 7 が参照しているリポジトリの一覧を確認しておきます。

[opc@test001 ~]$ sudo yum repolist
Loaded plugins: langpacks, ulninfo
repo id                                repo name                                                                               status
ol7_UEKR5/x86_64                       Latest Unbreakable Enterprise Kernel Release 5 for Oracle Linux 7Server (x86_64)          280
ol7_addons/x86_64                      Oracle Linux 7Server Add ons (x86_64)                                                     467
ol7_developer/x86_64                   Oracle Linux 7Server Development Packages (x86_64)                                       1505
ol7_developer_EPEL/x86_64              Oracle Linux 7Server EPEL Packages for Development (x86_64)                             33110
ol7_ksplice                            Ksplice for Oracle Linux 7Server (x86_64)                                                8574
ol7_latest/x86_64                      Oracle Linux 7Server Latest (x86_64)                                                    19428
ol7_oci_included/x86_64                Oracle Software for OCI users on Oracle Linux 7Server (x86_64)                            533
ol7_optional_latest/x86_64             Oracle Linux 7Server Optional Latest (x86_64)                                           14174
ol7_software_collections/x86_64        Software Collection Library release 3.0 packages for Oracle Linux 7 (x86_64)            15333
repolist: 93404
[opc@test001 ~]$

リポジトルを構成しているファイルも確認しておきます。

[opc@test001 ~]$ ls -la /etc/yum.repos.d/
total 52
drwxr-xr-x.  2 root root 4096 Aug 25 01:52 .
drwxr-xr-x. 95 root root 8192 Sep 26 01:38 ..
-rw-r--r--.  1 root root  488 Jun 11 21:19 ksplice-ol7.repo
-rw-r--r--.  1 root root  205 Sep 25 19:43 ksplice-uptrack.repo
-rw-r--r--.  1 root root  252 Jun 11 21:22 oci-included-ol7.repo
-rw-r--r--.  1 root root  252 Jun 11 21:19 oracle-epel-ol7.repo
-rw-r--r--.  1 root root 4082 Aug 25 01:47 oracle-linux-ol7.repo
-rw-r--r--.  1 root root  276 Jun 11 21:25 oracle-softwarecollection-ol7.repo
-rw-r--r--.  1 root root 1039 Dec 13  2019 oraclelinux-developer-ol7.repo
-rw-r--r--.  1 root root 2587 Jul  8 21:25 uek-ol7.repo
-rw-r--r--.  1 root root  226 Jul  8 21:25 virt-ol7.repo
[opc@test001 ~]$

一般的に公開している MySQL の Repository を参照するために、RPM ファイルをインストールします。

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

3個のRepositoryが追加されています

[opc@test001 ~]$ sudo yum repolist
Loaded plugins: langpacks, ulninfo
repo id                                 repo name                                                                              status
mysql-connectors-community/x86_64       MySQL Connectors Community                                                               165
mysql-tools-community/x86_64            MySQL Tools Community                                                                    115
mysql80-community/x86_64                MySQL 8.0 Community Server                                                               193
ol7_UEKR5/x86_64                        Latest Unbreakable Enterprise Kernel Release 5 for Oracle Linux 7Server (x86_64)         280
ol7_addons/x86_64                       Oracle Linux 7Server Add ons (x86_64)                                                    467
ol7_developer/x86_64                    Oracle Linux 7Server Development Packages (x86_64)                                      1505
ol7_developer_EPEL/x86_64               Oracle Linux 7Server EPEL Packages for Development (x86_64)                            33110
ol7_ksplice                             Ksplice for Oracle Linux 7Server (x86_64)                                               8574
ol7_latest/x86_64                       Oracle Linux 7Server Latest (x86_64)                                                   19428
ol7_oci_included/x86_64                 Oracle Software for OCI users on Oracle Linux 7Server (x86_64)                           533
ol7_optional_latest/x86_64              Oracle Linux 7Server Optional Latest (x86_64)                                          14174
ol7_software_collections/x86_64         Software Collection Library release 3.0 packages for Oracle Linux 7 (x86_64)           15333
repolist: 93877
[opc@test001 ~]$

実際のファイルをみると、mysql-community-source.repomysql-community.repo が追加されています。

[opc@test001 ~]$ ls -la /etc/yum.repos.d/
total 60
drwxr-xr-x.  2 root root 4096 Sep 26 01:40 .
drwxr-xr-x. 94 root root 8192 Sep 26 02:50 ..
-rw-r--r--.  1 root root  488 Jun 11 21:19 ksplice-ol7.repo
-rw-r--r--.  1 root root  205 Sep 25 19:43 ksplice-uptrack.repo
-rw-r--r--.  1 root root 2108 Apr 24  2019 mysql-community-source.repo
-rw-r--r--.  1 root root 2076 Apr 24  2019 mysql-community.repo
-rw-r--r--.  1 root root  252 Jun 11 21:22 oci-included-ol7.repo
-rw-r--r--.  1 root root  252 Jun 11 21:19 oracle-epel-ol7.repo
-rw-r--r--.  1 root root 4082 Aug 25 01:47 oracle-linux-ol7.repo
-rw-r--r--.  1 root root  276 Jun 11 21:25 oracle-softwarecollection-ol7.repo
-rw-r--r--.  1 root root 1039 Dec 13  2019 oraclelinux-developer-ol7.repo
-rw-r--r--.  1 root root 2587 Jul  8 21:25 uek-ol7.repo
-rw-r--r--.  1 root root  226 Jul  8 21:25 virt-ol7.repo
[opc@test001 ~]$

リポジトリが正常に構成できたので、MySQL Shell をインストールします

sudo yum install mysql-shell

依存関係は特にありません

=====================================================================================================================================
 Package                       Arch                     Version                        Repository                               Size
=====================================================================================================================================
Installing:
 mysql-shell                   x86_64                   8.0.21-1.el7                   mysql-tools-community                    31 M

Transaction Summary
=====================================================================================================================================

インストールしたので、mysqlsh コマンドが実行できるようになっています

[opc@test001 ~]$ which mysqlsh
/usr/bin/mysqlsh

MySQL Database Service へ接続していきましょう。接続に使う書式です。

mysqlsh Username@IPAddressOfMySQLDBSystemEndpoint 

Endpoint を見ましょう。VCN 内部の名前解決が sugimysql で出来ることが分かります。

1601084912925.png

接続します。MySQL Database Service を作成した時に指定したユーザー名と、Endpoint の名前を入れます。(FQDNを入れても大丈夫です。)

mysqlsh admin@sugimysql 

パスワードを入力します。MySQL Database Service を作成した時に指定しました。

[opc@test001 ~]$ mysqlsh admin@sugimysql
Please provide the password for 'admin@sugimysql': ***********************

接続完了です

[opc@test001 ~]$ mysqlsh admin@sugimysql
Please provide the password for 'admin@sugimysql': ***********************
MySQL Shell 8.0.21

Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.

Type '\help' or '\?' for help; '\quit' to exit.
Creating a session to 'admin@sugimysql'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 9
Server version: 8.0.21-u1-cloud MySQL Enterprise - Cloud
No default schema selected; type \use <schema> to set one.
 MySQL  sugimysql:3306 ssl  JS >

動作確認のために、status コマンドを表示してみます。8.0.21-u1-cloud MySQL Enterprise - Cloud と表示されており、OCI で動いてそうだ、ということがわかります。

 MySQL  sugimysql:3306 ssl  JS > \status
MySQL Shell version 8.0.21

Connection Id:                9
Current schema:
Current user:                 admin@test001.publicsubnet01.testuser001.oraclevcn.com
SSL:                          Cipher in use: ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2
Using delimiter:              ;
Server version:               8.0.21-u1-cloud MySQL Enterprise - Cloud
Protocol version:             Classic 10
Client library:               8.0.21
Connection:                   sugimysql via TCP/IP
TCP port:                     3306
Server characterset:          utf8mb4
Schema characterset:          utf8mb4
Client characterset:          utf8mb4
Conn. characterset:           utf8mb4
Result characterset:          utf8mb4
Compression:                  Disabled
Uptime:                       4 hours 51 min 32.0000 sec

Threads: 3  Questions: 11079  Slow queries: 0  Opens: 164  Flush tables: 3  Open tables: 85  Queries per second avg: 0.633
 MySQL  sugimysql:3306 ssl  JS >

接続確認 MySQL Client

では次に、なじみ深い MySQL Client から接続確認を行います。まず、インストールします。

sudo yum install mysql

依存関係です。

=====================================================================================================================================
 Package                                    Arch                  Version                     Repository                        Size
=====================================================================================================================================
Installing:
 mysql-community-client                     x86_64                8.0.21-1.el7                mysql80-community                 48 M
 mysql-community-libs                       x86_64                8.0.21-1.el7                mysql80-community                4.5 M
     replacing  mariadb-libs.x86_64 1:5.5.65-1.el7
 mysql-community-libs-compat                x86_64                8.0.21-1.el7                mysql80-community                1.2 M
     replacing  mariadb-libs.x86_64 1:5.5.65-1.el7
Installing for dependencies:
 mysql-community-common                     x86_64                8.0.21-1.el7                mysql80-community                617 k

Transaction Summary
=====================================================================================================================================

接続します

mysql --host sugimysql -u admin -p 

実行例

[opc@test001 ~]$ mysql --host sugimysql -u admin -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.21-u1-cloud MySQL Enterprise - Cloud

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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>

show databases で実行確認です。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql>

これで、正常に接続できることがわかりました。

参考URL

8
3
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
8
3