mysql-python mysqldb
http://mysql-python.sourceforge.net/
http://sourceforge.net/projects/mysql-python/
python 2.6 で 2.7は最新、3.xはこれからのようです。
インストール
pip-python install MySQL-python
[localhost] out: The required version of distribute (>=0.6.28) is not available,
こんなメッセージが出たので更新してから再度
easy_install -U distribute
Cleaning up…
===
参考:fabric に設定して
fabric update_python_egg install_python_mysql -R all
で10数台1回で更新出来ます。
参考:fabric + cuisineで管理
Fabric, Cuisine and Watchdog for server administration in Python http://www.slideshare.net/ffunction/fabric-cuisine-and-watchdog-for-server-administration-in-python
===
使う。
http://mysql-python.sourceforge.net/MySQLdb.html
mysqlテスト
・接続
# 接続
db = _mysql.connect( passwd=options.password, host=options.hostname, db=options.database, port=options.port, user=options.user, connect_timeout=3)
db.query( options.sql )
# クエリ
r = db.store_result()
#
data = r.fetch_row(0)
# 0で全件取得
print data
# ((‘5n’,), (‘h4′,), (‘hq’,), (‘pj’,), (‘sy’,), (‘wn’,))
# 数
count = r.num_rows()
print count
# 6
db.close()
optionsはoptionParsetを利用しています。
slaveのチェックは、データと
show slave statusを確認
# nagiosのスクリプトに入れました。
show table status from dbname;
でUpdate_timeとか見ようとしたらmyisamじゃないとnullだった。件数とサイズとか入れておく。
http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html