MySQLを開発に使っている時に、
今回はDockerを使って5.
デモンストレーション環境について
今回はDockerでMySQLの環境を複数用意して見るために、

KitematicはDockerのシンプルなオープンソースソフトウェアで、
Kitematic(Docker Toolbox)のインストール
Kitematicは現在はDockerのToolboxとして提供されています。Dockerの公式ページからOSにあったものをDownloadします。筆者の環境はMacなのでDownload(Mac)からダウンロードしました。バージョンはこの記事を書いている時の最新版1.

インストーラを起動すると次の画面が表示されます。

続けるをどんどん押していきます。一部パスワードを求められますので、

終了画面のひとつ前の画面で、

続けるを押してインストールが完了します。続けて初期設定に移ります。

DockerHubアカウントをお持ちの場合は入力してください。DockerHubはDockerコンテナを公開するためのWebサービスでDockerレジストリを構築することができるので便利ですが、

さてこれにてインストールは完了です。続いてMySQLの任意のバージョンをインストールして使ってみましょう。
最新版のMySQLコンテナイメージをダウンロードする
起動画面の中央上部にある

今回はRecommendedの中にあるofficialを利用しますが、
CREATEを押すとmysqlのlatestのバージョンに関してDockerコンテナのダウンロードが始まります。

ダウンロードが完了すると自動でDockerのコンテナが実行されます。しかし、

何やらエラーメッセージのようなものが表示されています。
Database is uninitialized and MYSQL_ROOT_PASSWORD not set Did you forget to add -e MYSQL_ROOT_PASSWORD=... ?
内容を読んでみるとrootパスワードが設定されていないというエラーメッセージが表示されているので、
Dockerイメージの設定を変更する
右上のSettingsからメニューを開くと、

設定できる項目や内容は以下の表のようになります。
名前 | 設定できる項目の種類 |
---|---|
General | コンテナ名やDockerで起動するときの環境引数をここで指定できます |
Ports | 外部のネットワークから接続する場合に、 |
Volums | コンテナがマウントするディレクトリを選択することができます。 |
Advanced | Kitematicを終了した時のVMの扱いなどを設定することができます。 |
今回はrootパスワードを設定したいのでGeneralのメニューからパスワードを引数として渡してあげます。Generalのメニュー内にあるEnviroment VariablesにMySQLのDockerのイメージ起動方法に書かれているように、

その他にも今回は使っていませんが、
入力が終わったあとSAVEを押すと設定が保存され、

先ほどのエラーとは違うログが出力されていることがわかります。無事起動が完了しました。
mysqlコマンドラインツールを使って繋いでみましょう。ここではhomebrewを使ってインストールをしたものを利用してます。hostのipとportはSettingsのPortから確認できます。
$ mysql -uroot -p -h 192.168.99.100 -P 32776
Enter password: ← MySQL_ROOT_PASSWODで設定したパスワード
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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>
ということで、
アプリケーションを使用している人は設定でhostとportをDockerのものに変更してあげるだけで、
続けて、
最新のMySQL5.7を試してみる
左上にあるContainersの右にある+NEWボタンを押して新規のコンテナを追加します。

すると初回起動をした時と同じ画面に移ります。

そこで先ほどと同様にMySQLを検索バーに入力します。すると下のような検索結果がやはり表示されると思います。

前回はそのままCREATEボタンをクリックしましたが、

すると下のような画面が開き、

その後CREATEを行うとMySQL5.
Database is uninitialized and MYSQL_ROOT_PASSWORD not set Did you forget to add -e MYSQL_ROOT_PASSWORD=... ?
lastestで行った時と同様にMySQL_
$ mysql -uroot -p -h 192.168.99.100 -P 32779
Enter password: ← MySQL_ROOT_PASSWODで設定したパスワード
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.8-rc MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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>
このように簡単にMySQL5.
今回はMySQL5.
まとめ
今回はKitematic