LoginSignup
7
8

More than 5 years have passed since last update.

Zabbixで使用中のMySQLバージョンアップメモ

Last updated at Posted at 2014-10-08

はじめに

CentOS5.8+zabbix1.8の環境から新環境へ移行した際のメモです。

CentOS 5.8    → CentOS 6.4
MySQL:5.0.95  → MySQL:5.1.69
zabbix1.8    → zabbix2.0

新環境構築

新環境を別サーバに先に作っておき、mysqlのデータだけ移行を行いました。

データ移行

1. データファイルコピー

 旧環境のMySQLを止めて静的な状態のMysqlの全データを新環境へコピー。
 ※mysqldumpでバックアップしたファイルを新しいバージョンの環境へ持って行ってもエラーが発生してリストア出来なかった。

2. 新環境のmy.cnfを変更

 mysql 5.0 → 5.1 で変更になっているパラメータを修正
 ※default_character-set ⇒ character-set-server

3. 新環境でMySQLを起動

 起動すると、この段階ではログに色々エラーが出る。

4. mysql_upgradeを実行

# mysql_upgrade -u root -p

5. テーブルチェック

 mysql_upgradeでストレージエンジンがMyISAMのものは自動で修正されるが、InnoDBのものは手動で修正が必要。

テーブルチェック結果
# mysqlcheck -c -u root -p --all-databases
Enter password:
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.event                                        OK
mysql.func                                         OK
mysql.general_log
Error    : You can't use locks with log tables.
status   : OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.host                                         OK
mysql.ndb_binlog_index                             OK
mysql.plugin                                       OK
mysql.proc                                         OK
mysql.procs_priv                                   OK
mysql.servers                                      OK
mysql.slow_log
Error    : You can't use locks with log tables.
status   : OK
mysql.tables_priv                                  OK
mysql.time_zone                                    OK
mysql.time_zone_leap_second                        OK
mysql.time_zone_name                               OK
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
zabbix.acknowledges                                OK
zabbix.actions                                     OK
zabbix.alerts                                      OK
zabbix.applications
error    : Table upgrade required. Please do "REPAIR TABLE `applications`" or dump/reload to fix it!
zabbix.auditlog                                    OK
zabbix.auditlog_details                            OK
zabbix.autoreg_host
error    : Table upgrade required. Please do "REPAIR TABLE `autoreg_host`" or dump/reload to fix it!
zabbix.conditions                                  OK
zabbix.config                                      OK
zabbix.dchecks                                     OK
zabbix.dhosts                                      OK
zabbix.drules                                      OK
zabbix.dservices
error    : Table upgrade required. Please do "REPAIR TABLE `dservices`" or dump/reload to fix it!
zabbix.escalations                                 OK
zabbix.events                                      OK
zabbix.expressions                                 OK
zabbix.functions
error    : Table upgrade required. Please do "REPAIR TABLE `functions`" or dump/reload to fix it!
zabbix.globalmacro
error    : Table upgrade required. Please do "REPAIR TABLE `globalmacro`" or dump/reload to fix it!
zabbix.globalvars                                  OK
zabbix.graph_discovery                             OK
zabbix.graph_theme
error    : Table upgrade required. Please do "REPAIR TABLE `graph_theme`" or dump/reload to fix it!
zabbix.graphs
error    : Table upgrade required. Please do "REPAIR TABLE `graphs`" or dump/reload to fix it!
zabbix.graphs_items                                OK
zabbix.groups
error    : Table upgrade required. Please do "REPAIR TABLE `groups`" or dump/reload to fix it!
zabbix.help_items
error    : Table upgrade required. Please do "REPAIR TABLE `help_items`" or dump/reload to fix it!
zabbix.history                                     OK
zabbix.history_log                                 OK
zabbix.history_str                                 OK
zabbix.history_str_sync                            OK
zabbix.history_sync                                OK
zabbix.history_text                                OK
zabbix.history_uint                                OK
zabbix.history_uint_sync                           OK
zabbix.host_inventory                              OK
zabbix.hostmacro
error    : Table upgrade required. Please do "REPAIR TABLE `hostmacro`" or dump/reload to fix it!
zabbix.hosts
error    : Table upgrade required. Please do "REPAIR TABLE `hosts`" or dump/reload to fix it!
zabbix.hosts_groups                                OK
zabbix.hosts_templates                             OK
zabbix.housekeeper                                 OK
zabbix.httpstep                                    OK
zabbix.httpstepitem                                OK
zabbix.httptest
error    : Table upgrade required. Please do "REPAIR TABLE `httptest`" or dump/reload to fix it!
zabbix.httptestitem                                OK
zabbix.icon_map
error    : Table upgrade required. Please do "REPAIR TABLE `icon_map`" or dump/reload to fix it!
zabbix.icon_mapping                                OK
zabbix.ids
error    : Table upgrade required. Please do "REPAIR TABLE `ids`" or dump/reload to fix it!
zabbix.images
error    : Table upgrade required. Please do "REPAIR TABLE `images`" or dump/reload to fix it!
zabbix.interface
error    : Table upgrade required. Please do "REPAIR TABLE `interface`" or dump/reload to fix it!
zabbix.item_discovery                              OK
zabbix.items
error    : Table upgrade required. Please do "REPAIR TABLE `items`" or dump/reload to fix it!
zabbix.items_applications                          OK
zabbix.maintenances                                OK
zabbix.maintenances_groups                         OK
zabbix.maintenances_hosts                          OK
zabbix.maintenances_windows                        OK
zabbix.mappings                                    OK
zabbix.media                                       OK
zabbix.media_type                                  OK
zabbix.node_cksum
error    : Table upgrade required. Please do "REPAIR TABLE `node_cksum`" or dump/reload to fix it!
zabbix.nodes                                       OK
zabbix.opcommand                                   OK
zabbix.opcommand_grp                               OK
zabbix.opcommand_hst                               OK
zabbix.opconditions                                OK
zabbix.operations                                  OK
zabbix.opgroup                                     OK
zabbix.opmessage                                   OK
zabbix.opmessage_grp                               OK
zabbix.opmessage_usr                               OK
zabbix.optemplate                                  OK
zabbix.profiles
error    : Table upgrade required. Please do "REPAIR TABLE `profiles`" or dump/reload to fix it!
zabbix.proxy_autoreg_host                          OK
zabbix.proxy_dhistory                              OK
zabbix.proxy_history                               OK
zabbix.regexps
error    : Table upgrade required. Please do "REPAIR TABLE `regexps`" or dump/reload to fix it!
zabbix.rights                                      OK
zabbix.screens                                     OK
zabbix.screens_items                               OK
zabbix.scripts                                     OK
zabbix.service_alarms                              OK
zabbix.services                                    OK
zabbix.services_links                              OK
zabbix.services_times                              OK
zabbix.sessions
error    : Table upgrade required. Please do "REPAIR TABLE `sessions`" or dump/reload to fix it!
zabbix.slides                                      OK
zabbix.slideshows                                  OK
zabbix.sysmap_element_url
error    : Table upgrade required. Please do "REPAIR TABLE `sysmap_element_url`" or dump/reload to fix it!
zabbix.sysmap_url
error    : Table upgrade required. Please do "REPAIR TABLE `sysmap_url`" or dump/reload to fix it!
zabbix.sysmaps
error    : Table upgrade required. Please do "REPAIR TABLE `sysmaps`" or dump/reload to fix it!
zabbix.sysmaps_elements                            OK
zabbix.sysmaps_link_triggers                       OK
zabbix.sysmaps_links                               OK
zabbix.timeperiods                                 OK
zabbix.trends                                      OK
zabbix.trends_uint                                 OK
zabbix.trigger_depends                             OK
zabbix.trigger_discovery                           OK
zabbix.triggers                                    OK
zabbix.user_history                                OK
zabbix.users
error    : Table upgrade required. Please do "REPAIR TABLE `users`" or dump/reload to fix it!
zabbix.users_groups                                OK
zabbix.usrgrp
error    : Table upgrade required. Please do "REPAIR TABLE `usrgrp`" or dump/reload to fix it!
zabbix.valuemaps
error    : Table upgrade required. Please do "REPAIR TABLE `valuemaps`" or dump/reload to fix it!

6. エラーになったテーブルのダンプ

 テーブルチェックで「Table upgrade required」が出たものは一度dumpして入れなおす。
 ※innodbを使用しているテーブルは「REPAIR TABLE」コマンドは使えない。(REPAIR TABLE が使えるのは MyISAM のみ)

テーブルのダンプ
# mysqldump -uroot -p zabbix applications > applications.sql

7. テーブルのインポート

 ※入れなおす前に外部キーチェックを外しておく。でないとインポート時にエラーになる。

テーブルのインポート

mysql> set foreign_key_checks=0 ;

# mysql -uroot -p zabbix < applications.sql

mysql> set foreign_key_checks=1 ;

シェルスクリプトで実行

数が多くて面倒なのでシェルスクリプトを作成
ダンプ⇒インポート⇒チェックをリストに従って行う。

# ./mysql_upgrade_table_repair.sh table_list.txt

mysql_upgrade_table_repair.sh
#!/bin/bash
filename=$1
MYSQL_USER="root"
MYSQL_PASS="hogehoge"
DB_NAME="zabbix"
MYSQL_CONN="mysql -u ${MYSQL_USER} -p${MYSQL_PASS} ${DB_NAME}"

#########################

echo "set foreign_key_checks=0 ;" | ${MYSQL_CONN}

while read line ; do
    echo "##### ${line}"
    mysqldump -u ${MYSQL_USER} -p${MYSQL_PASS} ${DB_NAME} ${line} > ${line}.sql
    ${MYSQL_CONN} < ${line}.sql
    mysqlcheck -c ${DB_NAME} ${line} -u ${MYSQL_USER} -p${MYSQL_PASS}
done < ${filename}

echo "set foreign_key_checks=1 ;" | ${MYSQL_CONN}
table_list.txt
applications
autoreg_host
dservices
functions
globalmacro
graph_theme
graphs
groups
help_items
hostmacro
hosts
httptest
icon_map
ids
images
interface
items
node_cksum
profiles
regexps
sessions
sysmap_element_url
sysmap_url
sysmaps
users
usrgrp
valuemaps
7
8
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
8