MySQLの最新バージョン8.
Dockerを使って試す
Dockerを使えば、
まずはdocker pullコマンドを使ってイメージをダウンロードします。その後、docker run --name=<コンテナ名> -d mysql/を実行します。たとえばMySQL5.docker run --name=mysql5720 -d mysql/のようにします。<MySQLのバージョン>となっているところはtag名で、
# docker pull mysql/mysql-server Using default tag: latest Trying to pull repository docker.io/mysql/mysql-server ... latest: Pulling from docker.io/mysql/mysql-server b0efbbec3b2e: Pull complete 4d06a7b7ca82: Pull complete 7ddc24d9f468: Pull complete 8b211b61b1a0: Pull complete Digest: sha256:f1cb1e3f0124601b1496f485e9f4401ad10138294b5a38d932089daafd555e34 Status: Downloaded newer image for docker.io/mysql/mysql-server:latest # docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/mysql/mysql-server latest 02d081b9c73e 2 months ago 300 MB # docker run --name=mysql1 -d mysql/mysql-server e98e7a0bfb4ec8473df4f92b30001966b45e51cb5200105ffe3cf1128f0fe171 # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e98e7a0bfb4e mysql/mysql-server "/entrypoint.sh my..." 8 seconds ago Up 6 seconds (health: starting) 3306/tcp, 33060/tcp mysql1
MySQLを起動することができました。
このMySQLに接続するにはdocker logsでMySQLのrootユーザーのパスワードを確認後、
# docker logs mysql1 ~ ~ [Entrypoint] GENERATED ROOT PASSWORD: (IfAH3l1YgCybtiSYSYb3wp4S$4 ~ ~
# docker exec -it mysql1 mysql -uroot -p'(IfAH3l1YgCybtiSYSYb3wp4S$4' mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 22 Server version: 8.0.11 Copyright (c) 2000, 2018, 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>
Dockerを使ってMySQLに接続することができました。
MySQL-Sandboxを利用する
MySQL-Sandboxは、
MySQL-Sandboxをインストール
MySQL-SandboxはPerlで作成されているため、
# curl -L cpanmin.us | perl - App::cpanminus # /usr/local/bin/cpanm MySQL::Sandbox
これで使用する準備は完了です。
MySQL-Sandboxを利用してMySQLを操作する
通常はMySQL-Sandboxを利用してMySQLの環境を構築するときはMySQLのbinarymake_を指定して実行します。今回はmake_コマンドを使い、
$ make_sandbox_from_url 5.7.22
2018-06-19 08:21:02 URL:https://raw.githubusercontent.com/datacharmer/mysql-docker-minimal/master/dbdata/available.txt [105/105] -> "/tmp/available.txt" [1]
wget -nv -O 5.7.22.tar.gz 'https://github.com/datacharmer/mysql-docker-minimal/blob/master/dbdata/5.7.22.tar.gz?raw=true'
2018-06-19 08:21:05 URL:https://raw.githubusercontent.com/datacharmer/mysql-docker-minimal/master/dbdata/5.7.22.tar.gz [43387997/43387997] -> "5.7.22.tar.gz" [1]
Executing low_level_make_sandbox --basedir=/home/mysql/opt/mysql/5.7.22 \
--sandbox_directory=msb_5_7_22 \
--install_version=5.7 \
--sandbox_port=5722 \
--no_ver_after_name \
--my_clause=log-error=msandbox.err
The MySQL Sandbox, version 3.2.16
(C) 2006-2018 Giuseppe Maxia
Installing with the following parameters:
upper_directory = /home/mysql/sandboxes
sandbox_directory = msb_5_7_22
sandbox_port = 5722
check_port =
no_check_port =
datadir_from = script
install_version = 5.7
basedir = /home/mysql/opt/mysql/5.7.22
tmpdir =
my_file =
operating_system_user = mysql
db_user = msandbox
remote_access = 127.%
bind_address = 127.0.0.1
ro_user = msandbox_ro
rw_user = msandbox_rw
repl_user = rsandbox
db_password = msandbox
repl_password = rsandbox
my_clause = log-error=msandbox.err
init_options =
init_my_cnf =
init_use_cnf =
master =
slaveof =
high_performance =
gtid =
pre_start_exec =
pre_grants_exec =
post_grants_exec =
pre_grants_sql =
post_grants_sql =
pre_grants_file =
post_grants_file =
load_plugin =
plugin_mysqlx =
mysqlx_port =
expose_dd_tables =
custom_mysqld =
prompt_prefix = mysql
prompt_body = [\h] {\u} (\d) >
force =
no_ver_after_name = 1
verbose =
load_grants = 1
no_load_grants =
no_run =
no_show =
keep_uuid =
keep_auth_plugin =
history_dir =
do you agree? ([Y],n) Y
# Starting server
. sandbox server started
# Loading grants
Your sandbox server was installed in $HOME/sandboxes/msb_5_7_22
インストールが完了しました。
MySQLクライアントを使ってアクセスするには、sandboxes/ディレクトリ内にあるuseを使ってアクセスします。
$ pwd
/home/mysql/sandboxes/msb_5_7_22
$ ./use
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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 [localhost] {msandbox} ((none)) >
起動、
$ sbtool -o delete --source_dir=/home/mysql/sandboxes/msb_5_7_22 sandbox at </home/mysql/sandboxes/msb_5_7_22> has been remove
他にも、
非常に便利なMySQL-Sandboxですが、
dbdeployer
dbdeployerも、
インストール
今回はdbdeployer1.
$ VERSION=1.5.2 $ origin=https://github.com/datacharmer/dbdeployer/releases/download/$VERSION $ wget $origin/dbdeployer-$VERSION.linux.tar.gz Resolving github.com (github.com)... (中略) HTTP request sent, awaiting response... 200 OK Length: 1852743 (1.8M) [application/octet-stream] Saving to: ‘dbdeployer-1.5.2.linux.tar.gz’ 100%[===========================================================================================================================================>] 1,852,743 637KB/s in 2.8s 2018-06-12 16:34:23 (637 KB/s) - ‘dbdeployer-1.5.2.linux.tar.gz’ saved [1852743/1852743] $ tar -xzf dbdeployer-$VERSION.linux.tar.gz $ chmod +x dbdeployer-$VERSION.linux $ sudo mv dbdeployer-$VERSION.linux /usr/local/bin/dbdeployer
dbdeployerは、dbdeployer deploy single <MySQLバージョン>を実行します。
$ wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz $ dbdeployer unpack mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz Unpacking tarball mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz to $HOME/opt/mysql/8.0.11 .........100.........200........289 $ dbdeployer deploy single 8.0.11 Database installed in $HOME/sandboxes/msb_8_0_11 run 'dbdeployer usage single' for basic instructions' ...... sandbox server started $ cd sandboxes/msb_8_0_11 $ ls add_option clear data grants.mysql init_db load_grants my my.sandbox.cnf mysqlsh restart sbdescription.json sb_include send_kill show_binlog show_log show_relaylog start status stop test_sb tmp use $ ./use Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.11 MySQL Community Server - GPL Copyright (c) 2000, 2018, 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-Sandboxと同様に検証環境を作成することができました。dbdeployer availableを利用すると、
$ dbdeployer available Basedir: /home/mysql/opt/mysql 5.0.96 5.7.19 5.7.22 8.0.11
MySQL-Sandboxとの比較
dbdeployerはMySQL-Sandboxを再設計して作成されたツールであるため、
詳細なMySQL-sandboexとの比較はdbdeployerのMySQL-Sandboxとの比較をご覧ください。
まとめ
今回はMySQLの検証環境の構築方法として、