[PR]

[PR] DB

[PR] AD

[PR] SQL

  • 1012 月

    wgetのバージョンにより、cssの扱い方が変わると聞いたので確認してみた。

    http://ja.wikipedia.org/wiki/GNU_Wget
    Wget 1.12 (2009年9月リリース)ウェブ上のCSSからのURL解析機能と国際化資源識別子(IRI)の取り扱いが追加された。

    http://wget.addictivecode.org/FrequentlyAskedQuestions?action=show&redirect=Faq

    5.2. Can Wget download links found in CSS?
    Thanks to code supplied by Ted Mielczarek, Wget can now parse embedded CSS stylesheet data
    and text/css files to find additional links for recursion, as of version 1.12.

    ■比較
    ——————————————————————————–

    [root@colinux tools]# wget –version
    GNU Wget 1.10.2 (Red Hat modified)
    [root@colinux 1.10.2]# wget -p -H http://kakaku.com/

    終了しました –10:09:00–
    ダウンロード完了: 519,822 バイト、76 ファイル
    [root@colinux 1.10.2]#

    [root@colinux wget-1.13]# wget –version
    GNU Wget 1.13 built on linux-gnu.
    [root@colinux 1.13]# wget -p -H http://kakaku.com/

    FINISHED –2011-12-10 10:15:15–
    Total wall clock time: 4.6s
    Downloaded: 121 files, 601K in 0.3s (2.35 MB/s)

    [root@colinux test]# wget -p -H -e robots=off http://kakaku.com/

    FINISHED –2011-12-10 11:09:12–
    Total wall clock time: 6.1s
    Downloaded: 136 files, 727K in 0.3s (2.54 MB/s)
    [root@colinux test]#

    ——————————————————————————–


    CSS1.13ではCSSに書かれている画像全てをダウンロードしてきている。
    htmlを表示する為に、必要な画像以外もダウンロードしてきている?

    [root@colinux wget_compare]# ls -l 1.10.2/ 1.13/
    1.10.2/:
    合計 24
    drwxr-xr-x 3 root root 4096 2011-12-10 10:23 image.akiba.kakaku.com
    drwxr-xr-x 5 root root 4096 2011-12-10 10:23 img.kakaku.com
    drwxr-xr-x 3 root root 4096 2011-12-10 10:23 img2.kakaku.k-img.com
    drwxr-xr-x 4 root root 4096 2011-12-10 10:23 kakaku.com
    drwxr-xr-x 2 root root 4096 2011-12-10 10:23 notice.kakaku.com
    drwxr-xr-x 2 root root 4096 2011-12-10 10:23 www.googleadservices.com

    1.13/:
    合計 24
    drwxr-xr-x 3 root root 4096 2011-12-10 10:28 image.akiba.kakaku.com
    drwxr-xr-x 5 root root 4096 2011-12-10 10:28 img.kakaku.com
    drwxr-xr-x 3 root root 4096 2011-12-10 10:28 img2.kakaku.k-img.com
    drwxr-xr-x 4 root root 4096 2011-12-10 10:28 kakaku.com
    drwxr-xr-x 2 root root 4096 2011-12-10 10:28 notice.kakaku.com
    drwxr-xr-x 2 root root 4096 2011-12-10 10:28 www.googleadservices.com
    [root@colinux wget_compare]#

    [root@colinux wget_compare]# cat wget_1.10.log | egrep -i http:// | awk ‘{print $2}’ > wget_1.10_http.log
    [root@colinux wget_compare]# cat wget_1.13.log | egrep -i http:// | awk ‘{print $3}’ > wget_1.13_http.log

    [root@colinux wget_compare]# diff wget_1.10_http.log wget_1.13_http.log
    77a78,122
    > http://img.kakaku.com/images/home/home_header_bg.gif
    > http://img.kakaku.com/images/icon_login.gif
    > http://img.kakaku.com/images/icon_guide.gif
    > http://img.kakaku.com/images/icon_register.gif
    > http://img.kakaku.com/images/icon_mypage.gif
    > http://img.kakaku.com/images/icon_history.gif
    > http://img.kakaku.com/images/h1_btm.gif
    > http://img.kakaku.com/images/h1bg.gif
    > http://img.kakaku.com/images/itemview/item/bm_tweetn-ja.png
    > http://img.kakaku.com/images/itemview/item/icon_guide.gif
    > http://img.kakaku.com/images/dot_999999.gif
    > http://img.kakaku.com/images/itemview/item/arrow_pagetop.gif
    > http://img.kakaku.com/images/article/pickup/template/link_bk.jpg
    > http://img.kakaku.com/images/home/arrow_next01.gif
    > http://img.kakaku.com/images/itemview/item/tab_bar_default.gif
    > http://img.kakaku.com/images/balloonhelp/balloon_tp.png
    > http://img.kakaku.com/images/balloonhelp/balloon_tp2.png
    > http://img.kakaku.com/images/balloonhelp/balloon_tp3.png
    > http://img.kakaku.com/images/balloonhelp/balloon_md.png
    > http://img.kakaku.com/images/balloonhelp/balloon_bt.png
    > http://img.kakaku.com/images/balloonhelp/balloon_bt2.png
    > http://img.kakaku.com/images/balloonhelp/balloon_bt3.png
    > http://img.kakaku.com/images/category/btn_search_sub.gif
    > http://img.kakaku.com/images/itemlist/btn_search.gif
    > http://img.kakaku.com/images/home/icon_all.png
    > http://img.kakaku.com/images/home/box_bg_in.png
    > http://img.kakaku.com/images/home/box_bg.png
    > http://img.kakaku.com/images/home/h2_top_all.png
    > http://img.kakaku.com/images/home/dotline01.gif
    > http://img.kakaku.com/images/home/bg_search.png
    > http://img.kakaku.com/images/home/bg_category.png
    > http://img.kakaku.com/images/home/home_icon_category.png
    > http://img.kakaku.com/images/home/home_icon_group.png
    > http://img.kakaku.com/images/home/icon_all.gif
    > http://img.kakaku.com/images/home/icon_slider.png
    > http://img.kakaku.com/images/home/h2_sub_all.png
    > http://img.kakaku.com/images/home/icon_reviewall.gif
    > http://img.kakaku.com/images/home/icon_mag.png
    > http://img.kakaku.com/images/home/icon_akiba_all.png
    > http://img.kakaku.com/images/home/trendnews_category.png
    > http://img.kakaku.com/images/home/icon_tv.png
    > http://img.kakaku.com/images/home/menu_boxall_h2.png
    > http://img.kakaku.com/images/home/dotline02.gif
    > http://img.kakaku.com/images/home/attention_arrow.gif
    > http://img.kakaku.com/images/home/menu_group_h2.gif
    [root@colinux wget_compare]#

    [root@colinux css]# cat global_new.css | grep home_header_bg.gif
    background: url(http://img.kakaku.com/images/home/home_header_bg.gif) repeat-x left bottom;
    [root@colinux css]#

    [root@colinux css]# cat home_common.css | grep attention_arrow.gif
    background:url(http://img.kakaku.com/images/home/attention_arrow.gif) no-repeat left top;
    [root@colinux css]#

    wgetのバージョンによって挙動がかわっている事は確認出来た。

    ■インストール
    ——————————————————————————–

    [root@colinux wget-1.13]# wget http://ftp.gnu.org/gnu/wget/wget-1.13.tar.gz
    [root@colinux wget-1.13]# tar zxvf wget-1.13.tar.gz
    [root@colinux wget-1.13]# ./configure –with-ssl=openssl
    [root@colinux wget-1.13]# make
    [root@colinux wget-1.13]# make install
    [root@colinux wget-1.13]# whereis wget
    wget: /usr/local/bin/wget
    [root@colinux wget-1.13]# ln -s /usr/local/bin/wget /usr/bin/wget
    [root@colinux wget-1.13]# wget –version
    GNU Wget 1.13 built on linux-gnu.

    ■古いwgetをアンインストール
    ———————————————————————————

    [root@colinux wget-1.13]# yum list installed | grep wget
    wget.i386 1.10.2-15.fc7 installed
    [root@colinux wget-1.13]# yum remove wget.i386
    Setting up Remove Process
    fedora 100% |=========================| 2.1 kB 00:00
    updates 100% |=========================| 2.3 kB 00:00
    Resolving Dependencies
    –> Running transaction check
    —> Package wget.i386 0:1.10.2-15.fc7 set to be erased
    –> Finished Dependency Resolution

    Transaction Test Succeeded
    Running Transaction
    Erasing : wget ######################### [1/1]

    Removed: wget.i386 0:1.10.2-15.fc7
    Complete!
    [root@colinux wget-1.13]# yum list installed | grep wget
    [root@colinux wget-1.13]#

    ■その他必要だったパツケージの事前インストール
    ———————————————————————————

    [root@colinux wget-1.13]# yum search openssl | grep dev
    openssl-devel.i386 : Files for development of applications which will use OpenSSL
    openssl-devel.i386 : Files for development of applications which will use OpenSSL
    xmlsec1-openssl-devel.i386 : OpenSSL crypto plugin for XML Security Library
    tcltls-devel.i386 : Header files for the OpenSSL extension for Tcl
    [root@colinux wget-1.13]# yum install openssl-devel.i386 xmlsec1-openssl-devel.i386 tcltls-devel.i386
    Setting up Install Process
    Parsing package install arguments
    Resolving Dependencies
    –> Running transaction check
    —> Package tcltls-devel.i386 0:1.5.0-11.fc6 set to be updated
    –> Processing Dependency: tcltls = 1.5.0-11.fc6 for package: tcltls-devel
    —> Package xmlsec1-openssl-devel.i386 0:1.2.9-8.1 set to be updated
    –> Processing Dependency: libxslt-devel >= 1.1.0 for package: xmlsec1-openssl-devel
    –> Processing Dependency: libxml2-devel >= 2.6.0 for package: xmlsec1-openssl-devel
    –> Processing Dependency: xmlsec1 = 1.2.9 for package: xmlsec1-openssl-devel
    –> Processing Dependency: xmlsec1-devel = 1.2.9 for package: xmlsec1-openssl-devel
    –> Processing Dependency: libxmlsec1-openssl.so.1 for package: xmlsec1-openssl-devel
    –> Processing Dependency: xmlsec1-openssl = 1.2.9 for package: xmlsec1-openssl-devel
    —> Package openssl-devel.i386 0:0.9.8b-15.fc7 set to be updated
    –> Processing Dependency: zlib-devel for package: openssl-devel
    –> Processing Dependency: krb5-devel for package: openssl-devel
    –> Running transaction check
    —> Package libxslt-devel.i386 0:1.1.24-1.fc7 set to be updated
    –> Processing Dependency: libgcrypt-devel for package: libxslt-devel
    —> Package libxml2-devel.i386 0:2.6.31-1.fc7 set to be updated
    —> Package xmlsec1.i386 0:1.2.9-8.1 set to be updated
    —> Package tcltls.i386 0:1.5.0-11.fc6 set to be updated
    —> Package krb5-devel.i386 0:1.6.1-9.fc7 set to be updated
    –> Processing Dependency: e2fsprogs-devel for package: krb5-devel
    —> Package xmlsec1-devel.i386 0:1.2.9-8.1 set to be updated
    —> Package zlib-devel.i386 0:1.2.3-10.fc7 set to be updated
    —> Package xmlsec1-openssl.i386 0:1.2.9-8.1 set to be updated
    –> Running transaction check
    —> Package e2fsprogs-devel.i386 0:1.40.2-3.fc7 set to be updated
    —> Package libgcrypt-devel.i386 0:1.2.4-1 set to be updated
    –> Processing Dependency: libgpg-error-devel for package: libgcrypt-devel
    –> Running transaction check
    —> Package libgpg-error-devel.i386 0:1.4-2 set to be updated
    –> Finished Dependency Resolution

    Dependencies Resolved

    =============================================================================
    Package Arch Version Repository Size
    =============================================================================
    Installing:
    tcltls-devel i386 1.5.0-11.fc6 fedora 4.3 k
    xmlsec1-openssl-devel i386 1.2.9-8.1 fedora 87 k
    Installing for dependencies:
    e2fsprogs-devel i386 1.40.2-3.fc7 updates 627 k
    krb5-devel i386 1.6.1-9.fc7 updates 1.1 M
    libgcrypt-devel i386 1.2.4-1 fedora 274 k
    libgpg-error-devel i386 1.4-2 fedora 17 k
    libxml2-devel i386 2.6.31-1.fc7 updates 2.1 M
    libxslt-devel i386 1.1.24-1.fc7 updates 324 k
    openssl-devel i386 0.9.8b-15.fc7 updates 1.8 M
    tcltls i386 1.5.0-11.fc6 fedora 28 k
    xmlsec1 i386 1.2.9-8.1 fedora 176 k
    xmlsec1-devel i386 1.2.9-8.1 fedora 667 k
    xmlsec1-openssl i386 1.2.9-8.1 fedora 71 k
    zlib-devel i386 1.2.3-10.fc7 fedora 81 k

    Transaction Summary
    =============================================================================
    Install 14 Package(s)
    Update 0 Package(s)
    Remove 0 Package(s)

    Total download size: 7.4 M
    Is this ok [y/N]:

    その他参考になるURL
    Compare cURL Features with Other Download Tools
    http://curl.haxx.se/docs/comparison-table.html

    Tags:

  • 249 月

    MYSQLでの日付比較演算子の確認

    ## 月跨ぎでページがエラーになってしまっていた。


    $query = "select GET_D,TRUNCATE(avg(TAKEN),2) AVGT from T_Confirmation
    where GET_D > CURDATE() - 8 group by GET_D";

    ## DB側にてデータの確認

    mysql> select GET_D,TRUNCATE(avg(TAKEN),2) AVGT from T_Confirmation
    where GET_D > CURDATE() - 8 group by GET_D;
    Empty set, 1 warning (0.02 sec)

    ## データはあるので、where句の部分を確認。
    ## 実際にQueryを実行してみると以下のような日付が返ってきた。


    mysql>select CURDATE() - 8;
    +—————+
    | CURDATE() - 8 |
    +—————+
    | 20100893 |
    +—————+
    1 row in set (0.00 sec)


    mysql> select CURRENT_DATE() - 8;
    +——————–+
    | CURRENT_DATE() - 8 |
    +——————–+
    | 20100893 |
    +——————–+
    1 row in set (0.00 sec)

    ## 日付の表示を正しいものに修正する為に、DATA_ADDを利用する事にした。

    mysql> SELECT DATE_ADD(CURRENT_DATE,INTERVAL 8 DAY);
    +—————————————+
    | DATE_ADD(CURRENT_DATE,INTERVAL 8 DAY) |
    +—————————————+
    | 2010-09-09 |
    +—————————————+
    1 row in set (0.00 sec)

    mysql> SELECT DATE_ADD(CURRENT_DATE,INTERVAL -8 DAY);
    +—————————————-+
    | DATE_ADD(CURRENT_DATE,INTERVAL -8 DAY) |
    +—————————————-+
    | 2010-08-24 |
    +—————————————-+
    1 row in set (0.00 sec)

    mysql>

    ## 正しくデータが表示される事を確認

    mysql> select GET_D,TRUNCATE(avg(TAKEN),2) AVGT from T_Confirmationwhere GET_D > DATE_ADD(CURRENT_DATE,INTERVAL -8 DAY) group by GET_D;
    +————+——+
    | GET_D | AVGT |
    +————+——+
    | 2010-08-25 | 0.77 |
    | 2010-08-26 | 0.48 |
    | 2010-08-27 | 0.32 |
    | 2010-08-28 | 0.30 |
    | 2010-08-29 | 0.28 |
    | 2010-08-30 | 0.35 |
    | 2010-08-31 | 0.34 |
    +————+——+
    7 rows in set (0.02 sec)

    mysql>


    select substring(GET_T,1,2) as GET_T,COUNT(*) as TOTAL from
    T_Confirmation where MONTH(GET_D)= MONTH(DATE_ADD(CURRENT_DATE,INTERVAL -1 DAY))
    AND TAKEN >= 10 Group by substring(GET_T,1,2);

    MONTH(DATE_ADD(CURRENT_DATE,INTERVAL -1 DAY))

    ## 全てのPHPファイルを修正する為に、ワンライナーで一気に書き換えで終了。
    ## ワンライナーでフォルダー配下のPHPを全て修正して解決!!

    perl -pi -e 's/CURDATE\(\) - 8/DATE_ADD\(CURRENT_DATE,INTERVAL -8 DAY\)/' *.php

    Tags: , , , , ,

  • 249 月

    MYSQLにてテーブルサイズの調査を行う。


    select
    table_name, engine, table_rows as tbl_rows, avg_row_length as rlen,
    floor((data_length+index_length)/1024/1024) as allMB,
    floor((data_length)/1024/1024) as dMB,
    floor((index_length)/1024/1024) as iMB
    from information_schema.tables
    where table_schema=database()
    order by (data_length+index_length) desc;


    +------------------+--------+----------+-------+-------+------+------+
    | table_name | engine | tbl_rows | rlen | allMB | dMB | iMB |
    +------------------+--------+----------+-------+-------+------+------+
    | mt_searchlog | MyISAM | 2799447 | 146 | 418 | 390 | 27 |
    | mt_entry | MyISAM | 9434 | 12629 | 114 | 113 | 1 |
    | mt_log | MyISAM | 59543 | 257 | 17 | 14 | 3 |
    | mt_entryphotoAll | MyISAM | 80260 | 47 | 5 | 3 | 1 |
    | mt_trackback | MyISAM | 8908 | 278 | 2 | 2 | 0 |
    | mt_template | MyISAM | 373 | 2870 | 1 | 1 | 0 |
    | mt_placement | MyISAM | 9447 | 18 | 0 | 0 | 0 |
    | mt_entryphoto | MyISAM | 9079 | 37 | 0 | 0 | 0 |
    | mt_session | MyISAM | 2536 | 96 | 0 | 0 | 0 |
    | mt_tbping | MyISAM | 493 | 473 | 0 | 0 | 0 |
    | mt_rfdata | MyISAM | 256 | 288 | 0 | 0 | 0 |
    | mt_plugindata | MyISAM | 7 | 3074 | 0 | 0 | 0 |
    | mt_category | MyISAM | 151 | 52 | 0 | 0 | 0 |
    | mt_errorlist | MyISAM | 19 | 572 | 0 | 0 | 0 |
    | mt_blog | MyISAM | 4 | 379 | 0 | 0 | 0 |
    | mt_tag | MyISAM | 5 | 22 | 0 | 0 | 0 |
    | mt_templatemap | MyISAM | 12 | 77 | 0 | 0 | 0 |
    | mt_author | MyISAM | 3 | 114 | 0 | 0 | 0 |
    | mt_permission | MyISAM | 14 | 88 | 0 | 0 | 0 |
    | mt_categoryinfo | MyISAM | 11 | 207 | 0 | 0 | 0 |
    | mt_config | MyISAM | 1 | 80 | 0 | 0 | 0 |
    | test2 | MyISAM | 2 | 7 | 0 | 0 | 0 |
    | mt_accessranking | MyISAM | 0 | 0 | 0 | 0 | 0 |
    | mt_comment | MyISAM | 0 | 0 | 0 | 0 | 0 |
    | mt_notification | MyISAM | 0 | 0 | 0 | 0 | 0 |
    | mt_objecttag | MyISAM | 0 | 0 | 0 | 0 | 0 |
    | mt_fileinfo | MyISAM | 0 | 0 | 0 | 0 | 0 |
    | mt_ipbanlist | MyISAM | 0 | 0 | 0 | 0 | 0 |
    | mt_sendping | MyISAM | 0 | 0 | 0 | 0 | 0 |
    +------------------+--------+----------+-------+-------+------+------+
    29 rows in set (0.00 sec)

    mysql>

    ■参考
    http://opendatabaselife.blogspot.com/2009_08_01_archive.html
    http://webmemo.uzuralife.com/category/pkweryrfvid.html/?search=&opt=0&order=0&from=380

    Tags: , ,

  • 161 月

    HDDの速度を測りたい場合は、hdparm コマンドを使用して調査する事が出来ます。

    [root@colinux data]# /bin/df -h
    Filesystem サイズ 使用 残り 使用% マウント位置
    /dev/cobd0 3.8G 2.6G 1009M 73% /
    tmpfs 126M 0 126M 0% /dev/shm
    /dev/shm 32M 0 32M 0% /usr/local/tmp
    [root@colinux data]# /sbin/hdparm -v /dev/cobd0

    /dev/cobd0:
    readonly = 0 (off)
    readahead = 256 (on)
    HDIO_GETGEO failed: Inappropriate ioctl for device
    [root@colinux data]# /sbin/hdparm -t /dev/cobd0

    /dev/cobd0:
    Timing buffered disk reads: 74 MB in 3.07 seconds = 24.10 MB/sec

    hdparm

    -T
    ベンチマーク及び比較目的で、キャッシュ読み込みを測定する。
    有意な結果を得るためには、少なくとも数メガバイトの空きメモリがあり、
    他にアクティブなプロセスがない状態で、この操作を 2, 3 回繰り返すべきである。
    これは、ディスクアクセスなしに、Linux のバッファキャッシュから直接読み出す速度を表示する。
    これは、テスト環境下でのプロセッサ・キャッシュ・メモリの基本的な処理能力を測定するものである。
    -t フラグが同時に指定された場合には、 -T の出力を元にした補正係数が -t 操作の結果に加味される。

    -t
    ベンチマーク及び比較目的で、デバイス読み込みを測定する。
    有意な結果を得るためには、少なくとも数メガバイトの空きメモリがあり、
    他にアクティブなプロセスがない状態で、この操作を 2, 3 回繰り返すべきである。
    これはデータのキャッシュがない状態から、バッファキャッシュを通してディスクを読み出す
    速度を表示する。これは、ファイルシステムのオーバーヘッドなしに、そのドライブが
    Linux でどれだけ連続データ読み込み速度を維持できるかを測定するものである。
    測定の正確さを上げたいのであれば、 -t の実行の間に BLKFLSBUF ioctl を使って
    バッファキャッシュをクリアする。 -T フラグが同時に指定された場合には、 -T の出力
    を元にした補正係数が -t 操作の結果に加味される。

    hdparm_t

    ハードディスクの設定の表示や変更は、hdparmコマンドを使って行うことができる。
    ただし変更すれば必ず良い結果がもたらされるというわけではなく、man hdparm
    を実行すればhdparmコマンドの全オプションを見ることができ、危険なオプションについては
    「DANGEROUS」と表記されている。

    ※最初に試す最適化は、転送の高速化のためにドライブが直接メモリ
    にデータを保存できるようにするDMA(Direct Memory Access)を使用する。
    /sbin/hdparm -d1 /dev/hda
    ※multcountは、一度の操作で読み取ることのできるセクタ数を示すパラメータ。

    hdparm_man

    最小値と最大値を捨て、残りの値の平均を取り適切な測定結果を得る。
    for ((i=0;i<6;i++)) do /sbin/hdparm -t /dev/cobd0; done

    hdparm_loop

      参考サイト


    Linuxのパフォーマンスを改善する3つのTips


    ファイルシステムのアクセスを最適化する


    hdparm でハードディスクを高速化する


    HDDのアクセスが妙に遅く感じるときは

    Tags: , ,

  • 161 月

    mysqlslap — クライアント負荷エミュレーション

    mysqlslapはMySQLサーバのクライアント負荷をエミュレートし、各ステージのタイミングを報告する
    診断プログラムです。サーバにたいして複数のクライアントがアクセスしているかのように作動します。
    mysqlslapはMySQL 5.1.4.から提供されています。

    [root@colinux data]# mysqlslap --no-defaults -V
    mysqlslap Ver 1.0 Distrib 5.5.0-m2, for pc-linux-gnu (i686)
    [root@colinux data]#
    —————————————————————————
    [root@colinux data]# mysqlslap –no-defaults -?
    mysqlslap Ver 1.0 Distrib 5.5.0-m2, for pc-linux-gnu (i686)
    Copyright (C) 2005 MySQL AB
    This software comes with ABSOLUTELY NO WARRANTY. This is free software,
    and you are welcome to modify and redistribute it under the GPL license

    Run a query multiple times against the server

    Usage: mysqlslap [OPTIONS]

    Default options are read from the following files in the given order:
    /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
    The following groups are read: mysqlslap client
    The following options may be given as the first argument:
    --print-defaults Print the program argument list and exit
    --no-defaults Don’t read default options from any options file
    --defaults-file=# Only read default options from the given file #
    --defaults-extra-file=# Read this file after the global files are read
    -?, --help Display this help and exit.
    -a, --auto-generate-sql
    Generate SQL where not supplied by file or command line.
    --auto-generate-sql-add-autoincrement
    Add an AUTO_INCREMENT column to auto-generated tables.
    --auto-generate-sql-execute-number=#
    Set this number to generate a set number of queries to
    run.
    --auto-generate-sql-guid-primary
    Add GUID based primary keys to auto-generated tables.
    --auto-generate-sql-load-type=name
    Specify test load type: mixed, update, write, key, or
    read; default is mixed.
    --auto-generate-sql-secondary-indexes=#
    Number of secondary indexes to add to auto-generated
    tables.
    --auto-generate-sql-unique-query-number=#
    Number of unique queries to generate for automatic tests.
    --auto-generate-sql-unique-write-number=#
    Number of unique queries to generate for
    auto-generate-sql-write-number.
    --auto-generate-sql-write-number=#
    Number of row inserts to perform for each thread (default
    is 100).
    --commit=# Commit records every X number of statements.
    -C, --compress Use compression in server/client protocol.
    -c, --concurrency=name
    Number of clients to simulate for query to run.
    --create=name File or string to use create tables.
    --create-schema=name
    Schema to run tests in.
    --csv[=name] Generate CSV output to named file or to stdout if no file
    is named.
    -#, --debug[=#] This is a non-debug version. Catch this and exit.
    --debug-check Check memory and open file usage at exit.
    -T, --debug-info Print some debug info at exit.
    -F, --delimiter=name
    Delimiter to use in SQL statements supplied in file or
    command line.
    --detach=# Detach (close and reopen) connections after X number of
    requests.
    -e, --engine=name Storage engine to use for creating the table.
    -h, --host=name Connect to host.
    -i, --iterations=# Number of times to run the tests.
    -x, --number-char-cols=name
    Number of VARCHAR columns to create in table if
    specifying –auto-generate-sql.
    -y, --number-int-cols=name
    Number of INT columns to create in table if specifying
    –auto-generate-sql.
    --number-of-queries=#
    Limit each client to this number of queries (this is not
    exact).
    --only-print This causes mysqlslap to not connect to the databases,
    but instead print out what it would have done instead.
    -p, --password[=name]
    Password to use when connecting to server. If password is
    not given it’s asked from the tty.
    -P, --port=# Port number to use for connection.
    --post-query=name Query to run or file containing query to execute after
    tests have completed.
    --post-system=name system() string to execute after tests have completed.
    --pre-query=name Query to run or file containing query to execute before
    running tests.
    --pre-system=name system() string to execute before running tests.
    --protocol=name The protocol of connection (tcp,socket,pipe,memory).
    -q, --query=name Query to run or file containing query to run.
    -s, --silent Run program in silent mode - no output.
    -S, --socket=name Socket file to use for connection.
    -u, --user=name User for login if not current user.
    -v, --verbose More verbose output; you can use this multiple times to
    get even more verbose output.
    -V, --version Output version information and exit.
    [root@colinux data]#
    —————————————————————————

    ————————————————————————————————————————–
    ここではDBをSLAPという名前で指定してますが、DBはmysqlslapを実行すると
    自動作成(CREATE)されて最後に自動削除(DROP)されます。
    既存のDB名を指定して実行する場合はバックアップしておかないとDBが無くなって
    しまいますので注意が必要です。
    ————————————————————————————————————————–
    MyIsamを指定してmysqlslapを実行してます

    mysqlslap --no-defaults --create-schema=SLAP --auto-generate-sql --auto-generate-sql-guid-primary --engine=myisam --number-int-cols=3 --number-char-cols=5 --concurrency=10 --auto-generate-sql-write-number=1000 --auto-generate-sql-execute-number=1000 --auto-generate-sql-load-type=mixed -u root -p

    InnoDBを指定してmysqlslapを実行してます

    mysqlslap --no-defaults --create-schema=SLAP --auto-generate-sql --auto-generate-sql-guid-primary --engine=InnoDB --number-int-cols=3 --number-char-cols=5 --concurrency=10 --auto-generate-sql-write-number=1000 --auto-generate-sql-execute-number=1000 --auto-generate-sql-load-type=mixed -u root -p

    --no-defaultsを最初に付けないと、
    mysqlslap: unknown variable ‘default-character-set=utf8′というエラーが出てきたので
    オプションファイルのDefaultをSkipしてテストしています。

    mysqlslap

    Benchmark
    Running for engine myisam
    Average number of seconds to run all queries: 5.391 seconds
    Minimum number of seconds to run all queries: 5.391 seconds
    Maximum number of seconds to run all queries: 5.391 seconds
    Number of clients running queries: 10
    Average number of queries per client: 1000

    Benchmark
    Running for engine InnoDB
    Average number of seconds to run all queries: 9.250 seconds
    Minimum number of seconds to run all queries: 9.250 seconds
    Maximum number of seconds to run all queries: 9.250 seconds
    Number of clients running queries: 10
    Average number of queries per client: 1000

    参考サイト

    7.16. mysqlslap — クライアント負荷エミュレーション

    Tags: ,

  • 2912 月

    InnoDB_Pluginについて

    13.6. The InnoDB Storage Engineからの抜粋
    At the 2008 MySQL User Conference, Innobase announced availability of an InnoDB Plugin for MySQL.
    This plugin for MySQL exploits the “pluggable storage engine” architecture of MySQL.
    The InnoDB Plugin is included in MySQL 5.5 releases as the built-in version of InnoDB.
    The version of the InnoDB Plugin is 1.0.6 as of MySQL 5.5.1 and is considered of Release Candidate (RC) quality.

    The InnoDB Plugin offers new features, improved performance and scalability, enhanced reliability
    and new capabilities for flexibility and ease of use.
    Among the features of the InnoDB Plugin are ….. 以下プラグイン概要….

    ————————————————————————-
    ① Fast index creation
    ② Table and index compression
    ③ File format management
    ④ New INFORMATION_SCHEMA tables
    ⑤ Capacity tuning
    ⑥ Multiple background I/O threads
    ⑦ Group commit.
    ————————————————————————-

    詳細は以下のinnodb.comを参照
    InnoDB Plugin 1.0 for MySQL 5.1 (Early Adopter Release) User’s Guide

    先日、MYSQL5.5をインストールしたので、Innodb_pluginはディフォルトで有効になっている。
    以下のコマンドでバージョンを確認する事が出来ます。


    select PLUGIN_NAME,PLUGIN_VERSION,PLUGIN_STATUS
    from information_schema.plugins;

    SELECT @@innodb_version;

    innodb_plugin_version

    メモ: INFORMATION_SCHEMA.PLUGINSテーブルにはマイナーバージョン番号は表示されないようです。
    Note that the PLUGIN_VERSION column in the table INFORMATION_SCHEMA.PLUGINS does not
    display the third component of the version number, only the first and second components, as in 1.0.

    その他留意事項
    ———————————————————————————————————-
    1.5. Operational Restrictions
    ———————————————————————————————————-
    Because the InnoDB Plugin introduces a new file format, with new on-disk data structures within
    both the database and log files, there are important restrictions on the use of the plugin in typical user
    environments. Specifically, you should pay special attention to the information presented here about
    file format compatibility with respect to the following scenarios:

    1) Downgrading from the InnoDB Plugin to the built-in InnoDB, or otherwise using different
    versions of InnoDB with database files created by the InnoDB Plugin
    2) Using mysqldump
    3) Using MySQL replication
    4) Using InnoDB Hot Backup

    WARNING: Once you use the InnoDB Plugin on a set of database files, care must be taken to avoid
    crashes and corruptions when using those files with an earlier version of InnoDB, as might happen by
    opening the database with MySQL when the plugin is not installed. It is strongly recommended that
    you use a “slow shutdown” (SET GLOBAL innodb_fast_shutdown=0) when stopping the MySQL server
    when the InnoDB Plugin is enabled. This will ensure log files and other system information written by the
    plugin will not cause problems when using a prior version of InnoDB.
    11.3, “How to Downgrade”.

    WARNING:If you dump a database containing compressed tables with mysqldump,
    the dump file may contain CREATE TABLE commands that attempt to create compressed tables,
    or those using ROW_FORMAT=DYNAMIC in the new database. Therefore, you should be sure
    the new database is running the InnoDB Plugin, with the proper settings for innodb_file_format and innodb_file_per_table, if you want to have the tables re-created as they exist in the original database.
    Typically, however, when the mysqldump file is loaded, MySQL and InnoDB will ignore
    CREATE TABLE options they do not recognize, and the table(s) will be created in a format
    used by the running server.

    WARNING: If you use MySQL replication, you should be careful to ensure all slaves are configured
    with the InnoDB Plugin, with the same settings for innodb_file_format and innodb_file_per_table.
    If you do not do so, and you create tables that require the new “Barracuda” file format, replication
    errors may occur. If a slave MySQL server is running the built-in InnoDB, it will ignore the
    CREATE TABLE options to create a compressed table or one with ROW_FORMAT=DYNAMIC,
    and create the table uncompressed, with ROW_FORMAT=COMPACT.

    WARNING: The current version of InnoDB Hot Backup does not support the new “Barracuda” file
    format. Using InnoDB Hot Backup Version 3 to backup databases in this format will cause
    unpredictable behavior. A future version of InnoDB Hot Backup will support databases used
    with the InnoDB Plugin. As an alternative, you may back up such databases with mysqldump.

    ———————————————————————————————————-

    Innovative Technologiesfor Performance andData Protection

    mysql> select Variable_name from
    -> information_schema.GLOBAL_VARIABLES
    -> where Variable_name like ‘innodb_%’;
    +———————————+
    | Variable_name |
    +———————————+
    | INNODB_VERSION |
    | INNODB_LOCKS_UNSAFE_FOR_BINLOG |
    | INNODB_BUFFER_POOL_SIZE |
    | INNODB_CONCURRENCY_TICKETS |
    | INNODB_OLD_BLOCKS_PCT |
    | INNODB_LOG_BUFFER_SIZE |
    | INNODB_MAX_PURGE_LAG |
    | INNODB_DOUBLEWRITE |
    | INNODB_IO_CAPACITY |
    | INNODB_TABLE_LOCKS |
    | INNODB_AUTOEXTEND_INCREMENT |
    | INNODB_THREAD_SLEEP_DELAY |
    | INNODB_REPLICATION_DELAY |
    | INNODB_STATS_ON_METADATA |
    | INNODB_ROLLBACK_ON_TIMEOUT |
    | INNODB_CHANGE_BUFFERING |
    | INNODB_FILE_FORMAT |
    | INNODB_DATA_FILE_PATH |
    | INNODB_STRICT_MODE |
    | INNODB_MAX_DIRTY_PAGES_PCT |
    | INNODB_AUTOINC_LOCK_MODE |
    | INNODB_COMMIT_CONCURRENCY |
    | INNODB_MIRRORED_LOG_GROUPS |
    | INNODB_SUPPORT_XA |
    | INNODB_SYNC_SPIN_LOOPS |
    | INNODB_ADAPTIVE_FLUSHING |
    | INNODB_ADAPTIVE_HASH_INDEX |
    | INNODB_DATA_HOME_DIR |
    | INNODB_READ_IO_THREADS |
    | INNODB_WRITE_IO_THREADS |
    | INNODB_FORCE_RECOVERY |
    | INNODB_LOG_FILES_IN_GROUP |
    | INNODB_OPEN_FILES |
    | INNODB_FILE_FORMAT_CHECK |
    | INNODB_READ_AHEAD_THRESHOLD |
    | INNODB_LOG_GROUP_HOME_DIR |
    | INNODB_FAST_SHUTDOWN |
    | INNODB_THREAD_CONCURRENCY |
    | INNODB_STATS_SAMPLE_PAGES |
    | INNODB_FLUSH_LOG_AT_TRX_COMMIT |
    | INNODB_FLUSH_METHOD |
    | INNODB_CHECKSUMS |
    | INNODB_LOG_FILE_SIZE |
    | INNODB_SPIN_WAIT_DELAY |
    | INNODB_FILE_PER_TABLE |
    | INNODB_LOCK_WAIT_TIMEOUT |
    | INNODB_OLD_BLOCKS_TIME |
    | INNODB_ADDITIONAL_MEM_POOL_SIZE |
    | INNODB_USE_SYS_MALLOC |
    +———————————+
    49 rows in set (0.00 sec)

    mysql>

      新機能として

    [innodb_file_format」
    InnoDBのファイルフォーマットを指定可能
    Antelope  従来のファイルフォーマット
    Barracuda 圧縮機能サポートファイルフォーマット

    innodb_file_format

    検証
    CREATE DATABASE `T_INNODB` /*!40100 DEFAULT CHARACTER SET utf8 */


    CREATE TABLE `T_Antelope` (
    `number` int(11) DEFAULT NULL,
    `comment` varchar(100) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;


    CREATE TABLE `T_Barracuda` (
    `number` int(11) DEFAULT NULL,
    `comment` varchar(100) DEFAULT NULL
    ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8 DEFAULT CHARSET=utf8;

    ROW_FORMAT

    * REDUNDANT
    * COMPACT
    * DYNAMIC (Barracuda format & No Compress)
    * COMPRESSED: (Barracuda format & Compress)

    innodb_plugin_test

    よく見てみると、上記QueryはWarrningが出ていてテーブルが圧縮されていない事が分かった。

    オプションファイルに以下の設定を入れて再度、MYSQLを再起動して設定を反映させた。
    innodb_file_format= Barracuda

    innodb_file_format_bara

    mysql> show variables like 'innodb_file%';

    barracuda

    ファイルフォーマットがBarracudaに変わったので再度テーブルを作成してみる。


    CREATE TABLE `T_Antelope` (
    `number` int(11) DEFAULT NULL,
    `comment` varchar(100) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;


    CREATE TABLE `T_Barracuda` (
    `number` int(11) DEFAULT NULL,
    `comment` varchar(100) DEFAULT NULL
    ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4 DEFAULT CHARSET=utf8
    /* BLOCKサイズを4に変更した */;


    select TABLE_SCHEMA,TABLE_NAME,ENGINE,ROW_FORMAT
    from information_schema.tables
    where TABLE_SCHEMA = 'T_INNODB';

    innodb_file_formatを変更した事でwarrningが消えた事を確認
    barracuda_confirm

    実際のファイルを確認してみるとファイルサイズが違う。
    ※ ブロックサイズを8で作成してもファイルサイズはBarracudaの方が小さい。

    compare

    information_schema.INNODB_CMPの変化の確認。
    圧縮を行った回数(compress_ops), 圧縮が成功した回数(compress_ops_ok)
    などを見て圧縮への対応を検討していく事が可能です。


    CREATE TABLE `T_Antelope_Key` (
    `number` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `comment` varchar(100) DEFAULT NULL,
    PRIMARY KEY (`number`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;


    CREATE TABLE `T_Barracuda_Key` (
    `number` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `comment` varchar(100) DEFAULT NULL,
    PRIMARY KEY (`number`)
    ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8 DEFAULT CHARSET=utf8;

    select * from information_schema.INNODB_CMP;

    innodb_cmp

    【メモ:パフォーマンス検証の際は、以下の値を確認】
    innodb_buffer_pool_size
    innodb_flush_methodをO_DIRECT

    参考サイト
    ——————————————
    INNOBASE
    InnoDB Plugin Change History
    13.6. The InnoDB Storage Engine
    InnoDB Plugin 1.0.4 - InnoDB史上極めて重要なリリース

    Tags: , ,

  • 2812 月


    SELECT TABLE_SCHEMA,TABLE_NAME,ENGINE
    FROM information_schema.tables
    where TABLE_SCHEMA = 'information_schema';

    mysql55_information_schema

    ■CHARACTER_SETS | MEMORY | 利用できる文字セットに関する情報
    ■COLLATIONS | MEMORY | 各文字セットの照合に関する情報
    ■COLLATION_CHARACTER_SET_APPLICABILITY | MEMORY | どの文字セットがどの照合に適用できるかを示します
    ■COLUMNS | MyISAM | テーブルのカラムに関する情報
    ■COLUMN_PRIVILEGES | MEMORY | カラムの権限に関する情報
    ■ENGINES | MEMORY | ストレージ エンジンに関する情報
    ■EVENTS | MyISAM | 計画したイベントに関する情報
    ■FILES | MEMORY | NDBディスクデータテーブルが保存されるファイルに関する情報
    ■GLOBAL_STATUS | MEMORY | サーバーのステータス変数に関する情報(GLOBAL)
    ■GLOBAL_VARIABLES | MEMORY | サーバーのステータス変数に関する情報(GLOBAL)
    ■KEY_COLUMN_USAGE | MEMORY | どのキーカラムに制約があるかを説明
    ■PARTITIONS | MyISAM | テーブルの分割に関する情報 (パーティショニング)
    ■PLUGINS | MyISAM | サーバーのプラグインに関する情報
    ■PROCESSLIST | MyISAM | 動作しているスレッドに関する情報
    ■PROFILING | MEMORY | プロファイリング情報(SHOW PROFILES/SHOW PROFILE)
    ■REFERENTIAL_CONSTRAINTS | MEMORY | 外部キーに関する情報
    ■ROUTINES | MyISAM | 保存されたルーチンに関する情報
    ■SCHEMATA | MEMORY | データベースに関する情報
    ■SCHEMA_PRIVILEGES | MEMORY | スキーマ(データベース)権限に関する情報
    ■SESSION_STATUS | MEMORY | サーバーのステータス変数に関する情報(SESSION)
    ■SESSION_VARIABLES | MEMORY | サーバーのステータス変数に関する情報(SESSION)
    ■STATISTICS | MEMORY | テーブル インデックスの情報
    ■TABLES | MEMORY | データベースのテーブルに関する情報
    ■TABLE_CONSTRAINTS | MEMORY | テーブルに制約があるか情報
    ■TABLE_PRIVILEGES | MEMORY | テーブル権限に関する情報
    ■TRIGGERS | MyISAM | トリガに関する情報
    ■USER_PRIVILEGES | MEMORY | グルーバル権限に関する情報
    ■VIEWS | MyISAM | データベースの表示に関する情報
    ■INNODB_CMP_RESET | MEMORY | InnoDB Plugin関連(圧縮テーブルに関する情報/統計)
    ■INNODB_TRX | MEMORY | InnoDB Plugin関連(実行中のトランザクション)
    ■INNODB_CMPMEM_RESET | MEMORY | InnoDB Plugin関連(Buffer pool内の圧縮されたPageに関する情報)
    ■INNODB_LOCK_WAITS | MEMORY | InnoDB Plugin関連(Blocking/Requestingトランザクション情報)
    ■INNODB_CMPMEM | MEMORY | InnoDB Plugin関連(Buffer pool内の圧縮されたPageに関する情報)
    ■INNODB_CMP | MEMORY | InnoDB Plugin関連(圧縮テーブルに関する情報/統計)
    ■INNODB_LOCKS | MEMORY | InnoDB Plugin関連(ロック競合が発生しているトランザクション)

    INFORMATION_SCHEMA ON MYSQL5.5 (基本)
    information_schema_55_basic

    INFORMATION_SCHEMA ON MYSQL5.5 (INNODB_PLUGIN関連)
    information_schema_55_innodb_p

    参考サイト
    ————————————————————————
    Chapter 6. InnoDB INFORMATION_SCHEMA tables

    Tags: , , ,

  • 2612 月

    最近のMYSQLのリリースの方法が変わったのか。。。
    5.4になるとJOINの処理が早くなると言われていたのでGAリリースを待ち望んでいたが、
    MySQL 5.4のサイトへ行くと
    5.4.3-betaで止まっている。にもかかわらず、MySQL 5.5がリリースされている。
    しかもマイルストーンリリース。

    【以下MYSQL5.5のサイトから抜粋】

    ■This brings me back to where I started the blog entry: the SELECT VERSION() statement,
    which doesn’t say “-alpha” nor “-beta” but “-m2″ (where “m2″ stands for “second milestone”).

    Getting you faster access to new features is a key idea behind the new milestones.
    Milestones don’t map one-to-one on version numbers, so hence the first 5.5 release can be
    the second milestone (with the first milestone being in the already community tested
    5.4 tree,which won’t get any further updates
    ).

    ■Is the MySQL 5.5 quality good enough to merit your testing?
    Yes, we think it is. Although MySQL Server 5.5-M2 isn’t production ready, we think it’s
    suitable for testing and feedback by you, because we have significantly increased our
    internal testing in order to avoid accepting unstable code into the milestone.
    A sign of this is that we do have other new code written, i.e. functionality brewing but not
    accepted into the milestone because it doesn’t fit our quality requirements at this point
    in time.

    STEP1) まずは何はともあれダウンロードしてみる

    wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.0-m2-linux-i686-icc-glibc23.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/

    STEP2) 展開してMYSQLを自分の運用パスに移動
    ①展開
    [root@colinux src]# tar zxvf mysql-5.5.0-m2-linux-i686-icc-glibc23.tar.gz
    ②移動
    [root@colinux src]# mv mysql-5.5.0-m2-linux-i686-icc-glibc23 /usr/local/

    STEP3) MYSQLフォルダーのパーミッション設定

    [root@colinux local]# chown -R mysql:mysql mysql-5.5.0-m2-linux-i686-icc-glibc23/
    [root@colinux local]# chmod -R 755 mysql-5.5.0-m2-linux-i686-icc-glibc23/

    mysql_55m

    STEP4) 既存のMYSQLのアップグレードを開始(5.1.41-log —> 5.5.0-m2)

    ①既存のバージョン確認
    5141-log

    ②データコピー前に既存のMYSQLサービスを停止
    [root@colinux local]# /etc/init.d/mysql.server stop
    Shutting down MySQL. SUCCESS!
    [root@colinux local]#

    ③ データフォルダーをMYSQL5.5用にコピー
    [root@colinux local]# cp -rp mysql/data mysql-5.5.0-m2-linux-i686-icc-glibc23/
    [root@colinux local]#

    ④ シンボリックリンクを古いバージョンから新しいバージョンへ切り替え
    [root@colinux local]#rm mysql
    [root@colinux local]# ln -s mysql-5.5.0-m2-linux-i686-icc-glibc23/ mysql

    symbol

    ※ バージョンに応じてオプションファイル(my.cnf)の変更もすべきだと思いますが、後で調整するのでここでは割愛してます。

    ⑤ MYSQLのサービスを再開
    [root@colinux local]# /etc/init.d/mysql.server start
    Starting MySQL…. SUCCESS!
    [root@colinux local]#

    ⑥ MYSQLのシステムテーブルをアップグレード
    [root@colinux bin]# pwd
    /usr/local/mysql/bin
    [root@colinux bin]#./mysql_upgrade -u root -p

    mysql55_system

    Running ‘mysql_fix_privilege_tables’…OK

    STEP5) MYSQLのアップグレード状態を確認

    mysql> select @@version;

    version55

    mysql> show tables from information_schema;
    information_schema_55m2

    ————————————————————————————————————————-


    select TABLE_SCHEMA,TABLE_NAME,ENGINE,CREATE_TIME
    from information_schema.tables
    where TABLE_SCHEMA = 'information_schema'
    Order by CREATE_TIME desc;

    information_schema_55_created

    Tags: , , , ,

  • 2212 月

    MYSQL5.1.41がリリースされていたので、アップグレード
    C.1.2. Changes in MySQL 5.1.41 (05 November 2009)

    ■InnoDB Plugin has been upgraded to version 1.0.5. This version is considered of
     Release Candidate (RC) quality.
    ■The InnoDB buffer pool is divided into two sublists: A new sublist containing blocks
     that are heavily used by queries, and an old sublist containing less-used blocks and from
     which candidates for eviction are taken.
     innodb_old_blocks_pct / innodb_old_blocks_time
    ■Important Change: Security Fix
    Bug#32167, CVE-2008-2079 / Bug#47320, CVE-2009-4028 / Bug#46922
    Partitioning: Bug#44059
    Replication: Bug#48297 / Bug#48216 / Bug#47678 / Bug#47323 / Bug#47287/ Bug#46640
    Bug#42829 / Bug#34582 / Bug#48370 / Bug#48295 / Bug#48293
    その他多数……………………….

    1) 現在のバージョン確認
    original_20091221

    http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.41-linux-i686-icc-glibc23.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/

    2) 最新版のダウンロード
    [root@colinux src]# wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.41-linux-i686-icc-glibc23.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/
    –00:06:43– http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.41-linux-i686-icc-glibc23.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/

    wget_5141

    3) ダウンロードしたtarを解凍
    [root@colinux src]# tar zxvf mysql-5.1.41-linux-i686-icc-glibc23.tar.gz
    tar_zxvf

    4) 展開したtarを自分が希望するパスへ移動 (これはオプション)
    mv_mysql5141

    5) 新しく展開したフォルダーのパーミッションの変更
    [root@colinux local]# chown -R mysql:mysql mysql-5.1.41-linux-i686-icc-glibc23/
    [root@colinux local]# chmod -R 755 mysql-5.1.41-linux-i686-icc-glibc23/

    6) 現在稼動している、MYSQLサービスを停止します。
    mysql_5141_migration

    7) シンボリックリンクの削除
    [root@colinux local]# pwd
    [root@colinux local]# rm mysql

    8) アップグレード前のまで利用していた、MYSQLのdataフォルダーを新しいバージョンのMYSQLにコピー

    [root@colinux local]# cp -rp mysql-5.1.40-linux-i686-icc-glibc23/data mysql-5.1.41-linux-i686-icc-glibc23/

    9) シンボリックリンクの作成とサービスの再開
    [root@colinux local]# ln -s mysql-5.1.41-linux-i686-icc-glibc23/ mysql

    mysql5141_symbolic

    [root@colinux local]# /etc/init.d/mysql.server start
    Starting MySQL…. SUCCESS!
    [root@colinux local]#

    10) システムデータベースのアップグレード(information_schema / mysql )

    [root@colinux local]# /usr/local/mysql/bin/mysql_upgrade -u root -p

    mysql_5141_sqlupgrade

    11) バージョンアップの確認

    ※ mysql_upgrade_infoファイルの確認
    [root@colinux data]# cat /usr/local/mysql/data/mysql_upgrade_info
    upgrade_info

    ※ エラーログの確認
    mysql_5141_log_confirmation

    ※ information_schemaとmysqlスキーマの確認
    select TABLE_SCHEMA,TABLE_NAME,ENGINE,CREATE_TIME,UPDATE_TIME
    from information_schema.tables where
    TABLE_SCHEMA = 'information_schema' or TABLE_SCHEMA = 'mysql'
    and CREATE_TIME is not NULL and UPDATE_TIME is not null
    order by CREATE_TIME desc;

    system_tables

    ※ バージョン確認 (mysql> select @@version;)
    version_5141

    Tags: , , ,

  • 1912 月

    1つのテーブルには最大6つのトリガーを作成する事が出来ます。
    内訳は、INSERT,UPDATE,DELETEにBEFORE,AFTERの2つずつ作成する事が出来ます。

    BEFORE INSERT ON table_name
    AFTER INSERT ON table_name
    BEFORE UPDATE ON table_name
    AFTER UPDATE ON table_name
    BEFORE DELETE ON table_name
    AFTER DELETE ON table_name

    BEFORE UPDATEトリガー


    DELIMITER //
    CREATE TRIGGER dbcomp_before_update_log
    BEFORE UPDATE ON dbcomp FOR EACH ROW
    BEGIN
    INSERT INTO dbcomp_update_log( new_name, old_name )
    VALUES ( NEW.name, OLD.name );
    -- NEW.nameは更新後、OLD.nameは更新前の値を表す
    END//
    DELIMITER ;

    trigger_review

    mysql> update dbcomp set name = '5.1.40-log';
    を実行すると以下のトリガーが実行されて値が自動更新される。

    INSERT INTO dbcomp_update_log( new_name, old_name )
    VALUES ( NEW.name, OLD.name );
    -- NEW.nameは更新後、OLD.nameは更新前の値を表す

    trigger_review_action

    mysql> update dbcomp set name = '5.4.0';
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1 Changed: 1 Warnings: 0

    mysql> select * from dbcomp;
    +——-+
    | name |
    +——-+
    | 5.4.0 |
    +——-+
    1 row in set (0.00 sec)

    mysql> select * from dbcomp_update_log;
    +————+————+
    | old_name | new_name |
    +————+————+
    | MySQL | 5.1.40-log |
    | 5.1.40-log | 5.4.0 |
    +————+————+
    2 rows in set (0.00 sec)

    mysql>

    INSERTによって起動されたトリガではNEWのみが有効で、それがDELETEであればOLDのみが有効になる。
    たとえば前の例でデータ追加・削除時の状況も記録できるようにするには、以下のトリガを追加する。


    DELIMITER //
    -- データ追加時に起動されるトリガ
    CREATE TRIGGER dbcomp_before_insert_log BEFORE INSERT ON dbcomp FOR EACH ROW
    BEGIN
    INSERT INTO dbcomp_update_log( new_name )
    VALUES ( NEW.name );
    END//

    BEFORE INSERT
    before_insert


    -- データ削除時に起動されるトリガ
    CREATE TRIGGER dbcomp_before_delete_log BEFORE DELETE ON dbcomp FOR EACH ROW
    BEGIN
    INSERT INTO dbcomp_update_log( old_name )
    VALUES ( OLD.name );
    END//

    BEFORE DELETE
    trigger_before_delete

    ————————————————————————————————–
    トリガの処理においては、その起動の対象となったテーブルに対して
    INSERT / UPDATE / DELETEを実行することはできないのだが、唯一の例外がある。
    それは、BEFORE INSERTもしくはBEFORE UPDATEのトリガにおいて、
    NEW.nameのような、これから追加・更新しようとする値だけはトリガ内で変更できる
    ————————————————————————————————–

    トリガを削除するには、以下のようなDROP TRIGGER構文を実行する。
    スキーマ名称およびトリガ名称はCREATE TRIGGERで設定済みのものでなければならない。
    ただしIF EXISTSを付けた場合は、存在しないトリガを指定してもエラーではなくwarningとなる。

    DROP TRIGGER [IF EXISTS] [スキーマ名称.]トリガ名称;

    トリガーの確認
    show triggers from データベース\G

    show-_triggers_from_db

    show create trigger dbcomp_before_delete_log
    show_create_trigger


    SELECT * FROM information_schema.triggers
    where action_timing = 'BEFORE' AND event_manipulation = 'DELETE' \G

    information_schema_triggers

    MYSQL Triggers
    [MySQL] MySQLのトリガとイベントスケジューラ

    Tags: , , , ,

« Previous Entries