先日は、共通テーブルスペース(Generated Tablespace)の紹介をさせて頂いたので、
5.7でより細かく設定出来るようになった
undo tablespaceとInnoDB temporary table tablespaceの設定
を紹介してみます。インスタンスの初期設定のタイミングで設定する必要がある為、
出来るだけインスタンスを構築する前にファイルパスなどの設計も行って頂ければ宜しいかと思います。
※まだ、GAになっていないのでRC(リリース候補)での確認のみなので、実際に本番環境で利用する場合は事前検証お願い致します。
■ Separate UNDO tablespace
–自動オンラインUNDOログ切り捨て(MySQL 5.7.5~)
–UNDOログファイルサイズの増加を回避する事が可能
※ログを切り捨てている時は、対象のテーブルスペースはOFFLINEになる為、
最低2個はテーブルスペースが必要となります。
■ 一時テーブル専用の表領域を新規追加
–CREATE/DROPのパフォーマンスを改善
–DDLによる変更が短縮され,一部ディスクI/Oも削減
インスタンスのインストールを行う為に、TARは現状最新版のMySQL5.7.7 RCを使いました。
ファイル: mysql-5.7.7-rc-linux-glibc2.5-x86_64.tar.gz
以下、インストールにおける変更点
※ InstallerがCとC++に代わって、Perlが不要になったので今回は、perlとperl-Data-Dumperはインストールせずに、
以下のlibaioとlibaio-develのみインストールしました。
[root@misc02 mysql]# yum install libaio
[root@misc02 mysql]# yum install libaio-devel
※ INSTANCEの初期設定
MySQL5.6まで: mysql_install_db
MySQL5.7から: mysqld –initialize か mysqld –initialize-insecure
mysqlアカウント追加とシンボリックリンク作成
[root@misc02 local]# groupadd mysql [root@misc02 local]# useradd -r -g mysql mysql [root@misc02 local]# ls bin etc games include lib lib64 libexec mysql-5.7.7-rc-linux-glibc2.5-x86_64 sbin share src [root@misc02 local]# ln -s mysql-5.7.7-rc-linux-glibc2.5-x86_64/ mysql [root@misc02 local]# ls -l 合計 4 drwxr-xr-x. 2 root root 6 6月 10 2014 bin drwxr-xr-x. 2 root root 6 6月 10 2014 etc drwxr-xr-x. 2 root root 6 6月 10 2014 games drwxr-xr-x. 2 root root 6 6月 10 2014 include drwxr-xr-x. 2 root root 6 6月 10 2014 lib drwxr-xr-x. 2 root root 6 6月 10 2014 lib64 drwxr-xr-x. 2 root root 6 6月 10 2014 libexec lrwxrwxrwx. 1 root root 37 4月 25 16:29 mysql -> mysql-5.7.7-rc-linux-glibc2.5-x86_64/ drwxr-xr-x. 9 7161 wheel 4096 3月 30 22:10 mysql-5.7.7-rc-linux-glibc2.5-x86_64 drwxr-xr-x. 2 root root 6 6月 10 2014 sbin drwxr-xr-x. 5 root root 46 4月 25 15:56 share drwxr-xr-x. 2 root root 56 4月 25 16:27 src [root@misc02 local]# [root@misc02 local]# cd mysql [root@misc02 mysql]# rm /etc/my.cnf rm: 通常ファイル `/etc/my.cnf' を削除しますか? y [root@misc02 mysql]# mkdir /home/mysql/ [root@misc02 mysql]# mkdir /home/mysql/data [root@misc02 mysql]# chown mysql:mysql /home/mysql [root@misc02 mysql]# chown -R mysql:mysql /home/mysql
my.cnfは、innodb_data_home_dir, innodb_temp_data_file_path, innodb_undo_tablespacesだけ変更しています。
※ちなみに、PAGESIZEを32K, 64Kにしたい場合はこの段階で行った方が良いかもしれません。
[root@misc02 mysql]# vi /etc/my.cnf [root@misc02 mysql]# cat /etc/my.cnf | grep innodb innodb_buffer_pool_size = 128M # Go up to 80% of your available RAM innodb_buffer_pool_chunk_size = 64M # Used when change size innodb_buffer Online # innodb_buffer_pool_instances = <n> # Bigger if huge InnoDB Buffer Pool or high concurrency innodb_file_per_table = 1 # Is the recommended way nowadays innodb_data_home_dir = /home/mysql/data # directory path for all InnoDB data files in the system tablespace. innodb_temp_data_file_path = ibtmp1:16M:autoextend # size for InnoDB temporary table tablespace data files. innodb_undo_tablespaces = 3 # When an undo tablespace is truncated, it is temporarily taken offline. innodb_flush_method = O_DIRECT # O_DIRECT is sometimes better for direct attached storage # innodb_write_io_threads = 8 # If you have a strong I/O system or SSD # innodb_read_io_threads = 8 # If you have a strong I/O system or SSD # innodb_io_capacity = 1000 # If you have a strong I/O system or SSD innodb_flush_log_at_trx_commit = 1 # 1 for durability, 0 or 2 for performance innodb_log_buffer_size = 8M # Bigger if innodb_flush_log_at_trx_commit= 0 innodb_log_file_size = 256M # Bigger means more write throughput but longer recovery time [root@misc02 mysql]#
my.cnfも設定が終わったので、インスタンを初期化します。
コマンドで指定しても問題ありません。
パスワードの変更方法は以下のコマンドを推奨しています。
MySQL 5.7.6 and later:
ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘MyNewPass';
MySQL 5.7.5 and earlier:
SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘MyNewPass’);
[root@misc02 mysql]# bin/mysqld --initialize --user=mysql 2015-04-25T08:19:31.323405Z 0 [Warning] The syntax '--log_warnings/-W' is deprecated and will be removed in a future release. Please use '--log_error_verbosity' instead. 2015-04-25T08:19:31.323953Z 0 [Warning] options --log-slow-admin-statements, --log-queries-not-using-indexes and --log-slow-slave-statements have no effect if --slow-query-log is not set 2015-04-25T08:19:31.323967Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2015-04-25T08:19:31.324019Z 0 [Note] Ignoring --secure-file-priv value as server is running with --initialize(-insecure) or --bootstrap. 2015-04-25T08:19:31.324052Z 0 [Note] bin/mysqld (mysqld 5.7.7-rc-log) starting as process 2556 ... 2015-04-25T08:19:31.331134Z 0 [Note] Creating the data directory /usr/local/mysql-5.7.7-rc-linux-glibc2.5-x86_64/data/ [root@misc02 mysql]# chown -R root . [root@misc02 mysql]# chown -R mysql data [root@misc02 mysql]# bin/mysqld_safe --user=mysql & [1] 2582 [root@misc02 mysql]# 150425 17:20:23 mysqld_safe Logging to '/usr/local/mysql/data/error.log'. 150425 17:20:23 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data [root@misc02 mysql]# [root@misc02 mysql]# cat ./data/error.log | grep password 2015-04-25T08:35:49.799907Z 1 [Warning] A temporary password is generated for root@localhost: lgwqmpDnK5/q [root@misc02 mysql]# ./bin/mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.7-rc-log 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. root@localhost [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password'; Query OK, 0 rows affected (0.00 sec) root@localhost [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) root@localhost [(none)]> select user,host from mysql.user; +------+-----------+ | user | host | +------+-----------+ | root | localhost | +------+-----------+ 1 row in set (0.01 sec) root@localhost [(none)]>
ファイルが意図した場所に出来ている事を確認
UNDO TABLESPACE: : undo001 ~ undo003
InnoDB TABLESPACEとSYSTEMとInnoDB Temp関連:/home/mysql/data/
[root@misc02 mysql]# ls -l data/ 合計 555168 -rw-r-----. 1 mysql mysql 56 4月 25 17:38 auto.cnf -rw-r-----. 1 mysql mysql 9652 4月 25 17:38 error.log -rw-r-----. 1 mysql mysql 268435456 4月 25 17:38 ib_logfile0 -rw-r-----. 1 mysql mysql 268435456 4月 25 17:35 ib_logfile1 -rw-r-----. 1 mysql mysql 6 4月 25 17:38 misc02.pid drwxr-x---. 2 mysql mysql 4096 4月 25 17:35 mysql -rw-r-----. 1 mysql mysql 99540 4月 25 17:35 mysql-bin.000001 -rw-r-----. 1 mysql mysql 437 4月 25 17:39 mysql-bin.000002 -rw-r-----. 1 mysql mysql 38 4月 25 17:38 mysql-bin.index -rw-rw----. 1 root root 5 4月 25 17:38 mysqld_safe.pid drwxr-x---. 2 mysql mysql 8192 4月 25 17:35 performance_schema drwxr-x---. 2 mysql mysql 8192 4月 25 17:35 sys -rw-r-----. 1 mysql mysql 10485760 4月 25 17:35 undo001 -rw-r-----. 1 mysql mysql 10485760 4月 25 17:38 undo002 -rw-r-----. 1 mysql mysql 10485760 4月 25 17:35 undo003 [root@misc02 mysql]# ls -l /home/mysql/data/ 合計 28676 -rw-r-----. 1 mysql mysql 420 4月 25 17:35 ib_buffer_pool -rw-r-----. 1 mysql mysql 12582912 4月 25 17:38 ibdata1 -rw-r-----. 1 mysql mysql 16777216 4月 25 17:38 ibtmp1 [root@misc02 mysql]#
起動ファイルの設定
[root@misc02 mysql]# cp -p ./support-files/mysql.server /etc/init.d/ [root@misc02 mysql]# chmod 755 /etc/init.d/mysql.server [root@misc02 mysql]# vi /etc/init.d/mysql.server [root@misc02 mysql]# /etc/init.d/mysql.server start Starting MySQL. SUCCESS!
UNDO TABLESPACEは、自動でTRUNCATE出来るので後程設定(innodb_undo_log_truncate)をONにしますが、基本的な設定が出来ているか確認してみます。
[root@misc02 mysql]# /usr/local/mysql/bin/mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.7-rc-log 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. root@localhost [(none)]> show variables like 'innodb_undo_log_truncate'; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | innodb_undo_log_truncate | OFF | +--------------------------+-------+ 1 row in set (0.01 sec) root@localhost [(none)]> show variables like 'innodb_max_undo_log_size'; +--------------------------+------------+ | Variable_name | Value | +--------------------------+------------+ | innodb_max_undo_log_size | 1073741824 | +--------------------------+------------+ 1 row in set (0.00 sec) root@localhost [(none)]> show variables like 'innodb_undo_tablespaces'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | innodb_undo_tablespaces | 3 | +-------------------------+-------+ 1 row in set (0.00 sec) root@localhost [(none)]> show variables like 'innodb_undo_directory'; +-----------------------+-------+ | Variable_name | Value | +-----------------------+-------+ | innodb_undo_directory | . | +-----------------------+-------+ 1 row in set (0.00 sec) root@localhost [(none)]> show variables like 'innodb_purge_rseg_truncate_frequency'; +--------------------------------------+-------+ | Variable_name | Value | +--------------------------------------+-------+ | innodb_purge_rseg_truncate_frequency | 128 | +--------------------------------------+-------+ 1 row in set (0.00 sec) root@localhost [(none)]>
InnoDB Temporary Tablespaceも意図した場所に出来ている事を確認
root@localhost [(none)]> show variables like 'innodb_temp%'; +----------------------------+-----------------------+ | Variable_name | Value | +----------------------------+-----------------------+ | innodb_temp_data_file_path | ibtmp1:16M:autoextend | +----------------------------+-----------------------+ 1 row in set (0.00 sec) root@localhost [(none)]> show variables like 'innodb_data%'; +-----------------------+------------------------+ | Variable_name | Value | +-----------------------+------------------------+ | innodb_data_file_path | ibdata1:12M:autoextend | | innodb_data_home_dir | /home/mysql/data | +-----------------------+------------------------+ 2 rows in set (0.00 sec) root@localhost [(none)]>
参照: 14.4.8 Truncating Undo Logs That Reside in Undo Tablespaces
innodb_temp_data_file_path
PlanetMySQL Voting: Vote UP / Vote DOWN