<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>おいぬま日報 &#187; MySQL</title>
	<atom:link href="http://tech.lampetty.net/tech/index.php/archives/category/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://tech.lampetty.net/tech</link>
	<description>Apache, MySQL, Perl, WordPressあたり</description>
	<lastBuildDate>Sun, 18 Jul 2010 19:00:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://tech.lampetty.net/tech/index.php/archives/category/mysql/feed" />
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>MuninでMySQLプラグインのグラフが描画されない時の解決方法</title>
		<link>http://tech.lampetty.net/tech/index.php/archives/369</link>
		<comments>http://tech.lampetty.net/tech/index.php/archives/369#comments</comments>
		<pubDate>Tue, 09 Mar 2010 14:09:58 +0000</pubDate>
		<dc:creator>oinume</dc:creator>
				<category><![CDATA[Munin]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://tech.lampetty.net/tech/?p=369</guid>
		<description><![CDATA[先日設定したサーバでMuninをインストールして監視していたのですが、どうもMySQL関連のプラグイン(mysql_bytes, mysql_queries, mysql_threadsなど)でグラフが描画されず、どうし [...]]]></description>
			<content:encoded><![CDATA[<p>先日設定したサーバでMuninをインストールして監視していたのですが、どうもMySQL関連のプラグイン(mysql_bytes, mysql_queries, mysql_threadsなど)でグラフが描画されず、どうしたものかと思ってぐぐってみたところ、<a href="http://www.mydigitallife.info/2007/08/25/fix-for-munin-mysql-monitoring-plugin-graph-not-showing-or-blank/">このエントリ</a>を見つけました。まさにビンゴで /etc/munin/plugin-conf.d/munin-node に以下の行を足してmunin-nodeをrestartしたところ、うまくグラフが描画されるようになりました。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">env.mysqladmin <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysqladmin</pre></div></div>

<p>Muninの問題なのか何なのか、自分のケースでは mysql 関連のコマンドを /usr/local/bin/ 配下にインストールしてたので、ここにPATHが通っていなかったのが問題のようです。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-umunin</span> munin-run mysql_bytes</pre></div></div>

<p>と実行してもうまく数値が出てきたのでどうしたものかと悩んでいたのですが、解決してすっきりしました。</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.lampetty.net/tech/index.php/archives/369/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://tech.lampetty.net/tech/index.php/archives/369" />
	</item>
		<item>
		<title>MySQL 5.1の最新のソースからdebを作成する</title>
		<link>http://tech.lampetty.net/tech/index.php/archives/360</link>
		<comments>http://tech.lampetty.net/tech/index.php/archives/360#comments</comments>
		<pubDate>Sun, 03 Jan 2010 09:06:08 +0000</pubDate>
		<dc:creator>oinume</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://tech.lampetty.net/tech/?p=360</guid>
		<description><![CDATA[以前というエントリを書いたのですが、Ubuntuの最新の開発版パッケージではなく、MySQLが出している最新のMySQLのソースをビルドしてdebパッケージを作成する方法を見つけたのでメモしておきます。ちなみにMySQL [...]]]></description>
			<content:encoded><![CDATA[<p>以前<a href="http://tech.lampetty.net/tech/index.php/archives/331" class="permalinker_link">MySQL 5.1の最新版のdebパッケージを作成する方法</a>というエントリを書いたのですが、Ubuntuの最新の開発版パッケージではなく、MySQLが出している最新のMySQLのソースをビルドしてdebパッケージを作成する方法を見つけたのでメモしておきます。ちなみにMySQL以外にもperlとかのパッケージもこの方法で最新にすることが出来ると思います。</p>
<h3>debを作成するための準備</h3>
<p>まずはビルドする人間のメールアドレスと名前を環境変数で設定しておきます。適当に自分のものに置き換えて下さい。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DEBEMAIL</span>=<span style="color: #ff0000;">&quot;hogehoge@foo.com&quot;</span>
$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DEBFULLNAME</span>=<span style="color: #ff0000;">&quot;Your Name&quot;</span></pre></div></div>

<p>次にパッケージをビルドするために必要なものをインストールします。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> dh-make devscripts debhelper fakeroot lintian <span style="color: #c20cb9; font-weight: bold;">sudo</span> pbuilder piuparts dpatch build-essential
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> build-dep mysql-server-<span style="color: #000000;">5.1</span></pre></div></div>

<h3>ソースの取得</h3>
<p>Ubuntuのdebを作成するのに使われているソースを取得します。ソースはカレントディレクトリに展開されるので、必要があれば適当なディレクトリに cd しておいてください。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #7a0874; font-weight: bold;">source</span> mysql-server-<span style="color: #000000;">5.1</span></pre></div></div>

<p>次に最新のMySQLのソースを<a href="http://dev.mysql.com/downloads/mysql/5.1.html#source">mysql.com</a>より取得します。&#8221;Select Platform&#8221;というプルダウンで&#8221;Source Code&#8221;を選択し、&#8221;Generic Linux (Architecture Independent), Compressed TAR Archive&#8221;をダウンロードして下さい。現在の最新版は5.1.42になるので、mysql-5.1.42.tar.gz としてダウンロードしています。</p>
<h3>ビルド</h3>
<p>ではビルドを始めます。uupdate というコマンドを使うと、自動的に引数で指定した最新のソースパッケージを展開しそこにDebianのパッケージを作成するためのファイルが生成されます。(つーか<br />
uupdate便利過ぎ！)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> mysql-dfsg-<span style="color: #000000;">5.1</span>-5.1.37
$ uupdate ..<span style="color: #000000; font-weight: bold;">/</span>mysql-5.1.42.tar.gz</pre></div></div>

<p>&#8220;cd ../mysql-dfsg-5.1-5.1.42 しろ&#8221;と言われるので、cd してパッケージをビルドします。(私はAthlon X2 5050eの環境で約2.5時間かかりました)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ dpkg-buildpackage <span style="color: #660033;">-uc</span> <span style="color: #660033;">-us</span> <span style="color: #660033;">-rfakeroot</span></pre></div></div>

<h3>インストール</h3>
<p>ビルドが完了すると .deb パッケージがソースパッケージのディレクトリに作成されているので、必要なものをdpkg -iしてインストールします。ただし、依存関係が若干複雑なのでエラーが出たら依存しているものを先にインストールすると良いでしょう。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> \
libmysqlclient16_5.1.42-0ubuntu1_amd64.deb \
libmysqlclient-dev_5.1.42-0ubuntu1_amd64.deb \
libmysqlclient16-dev_5.1.42-0ubuntu1_all.deb \
mysql-common_5.1.42-0ubuntu1_all.deb \
mysql-client-<span style="color: #000000;">5.1</span>_5.1.42-0ubuntu1_amd64.deb \
mysql-client_5.1.42-0ubuntu1_all.deb \
mysql-server-<span style="color: #000000;">5.1</span>_5.1.42-0ubuntu1_amd64.deb \
mysql-server-core-<span style="color: #000000;">5.1</span>_5.1.42-0ubuntu1_amd64.deb \
mysql-server_5.1.42-0ubuntu1_all.deb \
libmysqld-dev_5.1.42-0ubuntu1_amd64.deb \
libmysqld-pic_5.1.42-0ubuntu1_amd64.deb</pre></div></div>

<p>無事にインストールできれば、これでmysql-server-5.1が最新版になっています。mysqlコマンドでSQLを発行して動作を確認してみて下さい。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ mysql <span style="color: #660033;">-uroot</span> <span style="color: #660033;">-pxxxxx</span>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection <span style="color: #c20cb9; font-weight: bold;">id</span> is <span style="color: #000000;">72</span>
Server version: 5.1.42-0ubuntu1-log <span style="color: #7a0874; font-weight: bold;">&#40;</span>Ubuntu<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://tech.lampetty.net/tech/index.php/archives/360/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://tech.lampetty.net/tech/index.php/archives/360" />
	</item>
		<item>
		<title>MySQLのdrop tableでは複数のテーブルを一気に削除できる</title>
		<link>http://tech.lampetty.net/tech/index.php/archives/356</link>
		<comments>http://tech.lampetty.net/tech/index.php/archives/356#comments</comments>
		<pubDate>Wed, 23 Dec 2009 16:25:31 +0000</pubDate>
		<dc:creator>oinume</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://tech.lampetty.net/tech/?p=356</guid>
		<description><![CDATA[タイトル通りなんですが、今までは複数のテーブルを削除する時は

&#62; drop table hoge;
&#62; drop table fuga;

なんてやってましたが、

&#62; drop table hoge [...]]]></description>
			<content:encoded><![CDATA[<p>タイトル通りなんですが、今までは複数のテーブルを削除する時は</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> drop table hoge;
<span style="color: #000000; font-weight: bold;">&gt;</span> drop table fuga;</pre></div></div>

<p>なんてやってましたが、</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> drop table hoge fuga;</pre></div></div>

<p>って書けるんですね。豆知識。</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.lampetty.net/tech/index.php/archives/356/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://tech.lampetty.net/tech/index.php/archives/356" />
	</item>
		<item>
		<title>hbstudy#5に参加してきました</title>
		<link>http://tech.lampetty.net/tech/index.php/archives/347</link>
		<comments>http://tech.lampetty.net/tech/index.php/archives/347#comments</comments>
		<pubDate>Sat, 14 Nov 2009 16:56:33 +0000</pubDate>
		<dc:creator>oinume</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[勉強会]]></category>

		<guid isPermaLink="false">http://tech.lampetty.net/tech/?p=347</guid>
		<description><![CDATA[インフラエンジニアじゃないけどインフラエンジニア勉強会 hbstudy#5に参加してきました。もともとこのイベントには参加したいなぁと思っていて、参加登録したらいいタイミングで松信さんが講演することにw 貴重なMySQL [...]]]></description>
			<content:encoded><![CDATA[<p>インフラエンジニアじゃないけど<a href="http://heartbeats.jp/hbstudy/2009/11/hbstudy5.html">インフラエンジニア勉強会 hbstudy#5</a>に参加してきました。もともとこのイベントには参加したいなぁと思っていて、参加登録したらいいタイミングで松信さんが講演することにw 貴重なMySQLのチューニングの話が生で聞けてとてもよかったよかった。</p>
<p>あと、最初にPostgreSQLの話をしていた永安さんのセッションもよかった。普通DBの入門の話ってあまりつっこんだ運用の話は出てこないと思うのですが、運用を意識した入門編でこういうのはすごい貴重だったのではないかと。</p>
<h3>PostgreSQL安定運用のコツ2009</h3>
<p>永安さんの話は<a href="http://www.slideshare.net/uptimejp/postgresql2009-hbstudy5">スライド</a>を見てもらえばほぼ全てわかります。スライドが充実し過ぎていてあまりメモを取っていなかったのですが、最近のポスグレはAuto Vacuumなんて仕組みがあって、あまりVacuumを意識しなくてよいのだなぁと。あとポスグレもチューニングはいかに共有バッファをうまく使うかっていうところで、あんまりMySQLと変わらないんだなって思いました。</p>
<h3>Linux MySQLサーバーのパフォーマンスチューニング</h3>
<p><a href="http://www.mysql.gr.jp/frame/modules/bwiki/index.php?plugin=attach&#038;refer=matsunobu&#038;openfile=Linux-MySQL-PT.pdf">資料(PDF)</a><br />
MySQLのチューニングの基本はデータサイズを小さくしていかにメモリにのっけるか、という話。たとえば、日時を格納するカラムはDATETIME(8byte使用)じゃなくてTIMESTAMP(4byte)を使えとか。statusみたいな1/0しか入らないカラムは文字列型じゃなくてTINYINTかENUM使えとか。ちなみに日時は2038年問題が気にならないのであれば、UNIXTIME化してINT型のフィールドにしてしまうという荒技もありますよね。アプリケーション側でいちいち変換しなくてはいけないですが。</p>
<p>あと「巨大なTEXT/BLOBはクエリ効率を悪化させる」という話で、巨大なデータを格納するカラムは別テーブルにすると、それ以外のカラムのデータをSELECTするときに悪影響が出ないらしい。ちょっとどういう話か失念してしまったので、資料が公開されたら復習します。一定以上の大きさのテキストフィールドを別領域に保存するストレージエンジンとして、Falcon, PBXTがあるとのこと。ちなみに、HDDが一秒間に処理できるランダムI/Oはせいぜい数百ぐらいなので、とても遅いですと。</p>
<p>あとは実データを引かずにCovering Index(インデックスだけを読む検索)でうまく処理する方法もあるそうで、</p>
<ul>
<li>テーブルのレコードにアクセスする必要がなくなるので、高速になる</li>
<li>Indexのサイズが大きくなるので、更新のコストが高くなる</li>
<li>Limit句を使うときにも効果がある</li>
</ul>
<p>というメリットデメリットがあるそうです。</p>
<ul>
<li>メモリを十分に確保してダイレクトI/Oを活用する</li>
<li>オンライン処理のあとに、バッチ処理で巨大なテーブルに対してフルスキャンするのは問題がある</li>
<li>バッチ処理によるバッファプールが占有され、オンラインのバッファプールが追い出されてしまうため</li>
<li>OOM Killerに注意する</li>
<li>ダイレクトI/Oを使うとプロセス内にデータが置かれるので、プロセスのサイズが大きくなる</li>
<li>DBサーバとしてはファイルシステムキャッシュを縮小してほしい</li>
<li># echo 0 > /proc/sys/vm/swappiness = 0</li>
<li>-> Direct I/Oとセットで使うことが多い</li>
<li>cpで大きいファイルをコピー</li>
<li>cpに対してファイルシステムキャッシュが使われる</li>
<li>InnoDBのプロセスのデータがスワップに追い出される->これは避けたい</li>
<li>ファイルシステムはext3
<ul>
<li>もっとも使われていて安全</li>
<li>dir_index, noatime(relatime)</li>
<li>xfsはDirect I/Oだと並列で書き込める</li>
<li>xfsは巨大なファイルのコピーがはやい</li>
<li>でもxfs使っている人少なすぎなので、おすすめできないｗ</li>
</ul>
</li>
<li>監視の方法
<ul>
<li>iotop: プロセス単位でI/O量を取る kernel 2.6.20以降</li>
<li>ネットワーク統計: MySQL Cluster使う人には必要かも</li>
<li>mtstat: 一秒おきに受信/送信byte数を表示</li>
<li>/proc/net/dev をみればわかる情報</li>
</ul>
</li>
<li>SSD
<ul>
<li>ランダムリードはHDD: 200回にたいして、25000回のI/O (Intel X25E)</li>
<li>書き込み性能は製品による差が激しい</li>
<li>write cache必須</li>
<li>バッテリーで守れていることが重要。RAIDコントローラに任せるものとSSD自身で持つものがある(RAID Controllerの場合はそれがSSDに対応していることが重要)</li>
<li>SSDは並列性が重要。Crystalなんとかのベンチはシングルプロセスの話なのであてにならない
</li>
<li>PCI-E型SSDにも注目 -> I/Fの速度が速い(300MB -> 2GB)</li>
</ul>
</li>
</ul>
<p>途中から殴り書きですが、TIMESTAMP型が4byteとDATETIMEの半分で済むことにこの日初めて知りました。その他Covering Indexなど、知らなかったテクニックなのでとても勉強になりました。あとSSDは本当もうすぐそこまで来ていて、これを入れるだけで数倍DBのI/Oが速くなることを考えるとすごいなぁと。しかし色々ベンチ取られていて、すごく説得力のあるお話でした。この人にコンサル頼んだらいくらかかるんだろう&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.lampetty.net/tech/index.php/archives/347/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://tech.lampetty.net/tech/index.php/archives/347" />
	</item>
		<item>
		<title>MySQL 5.1の最新版のdebパッケージを作成する方法</title>
		<link>http://tech.lampetty.net/tech/index.php/archives/331</link>
		<comments>http://tech.lampetty.net/tech/index.php/archives/331#comments</comments>
		<pubDate>Sat, 29 Aug 2009 23:28:23 +0000</pubDate>
		<dc:creator>oinume</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://tech.lampetty.net/tech/?p=331</guid>
		<description><![CDATA[Ubuntu 9.04にはMySQL 5.1のパッケージが用意されているのですが、バージョンが5.1.31であり最新ではないので(現時点で最新は5.1.37)、最新版のdebパッケージを作成する方法を紹介します。debを [...]]]></description>
			<content:encoded><![CDATA[<p>Ubuntu 9.04にはMySQL 5.1のパッケージが用意されているのですが、バージョンが5.1.31であり最新ではないので(現時点で最新は5.1.37)、最新版のdebパッケージを作成する方法を紹介します。debを作成するといっても、開発中のUbuntuに入っているmysql-server-5.1のソースを持ってきてビルドするだけなので、比較的お手軽にできます。</p>
<h3>debを作成するための準備</h3>
<p>まずはビルドする人間のメールアドレスと名前を環境変数で設定しておきます。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DEBEMAIL</span>=<span style="color: #ff0000;">&quot;hogehoge@foo.com&quot;</span>
$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DEBFULLNAME</span>=<span style="color: #ff0000;">&quot;Your Name&quot;</span></pre></div></div>

<p>次にパッケージをビルドするために必要なものをインストールします。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> dh-make devscripts debhelper fakeroot lintian <span style="color: #c20cb9; font-weight: bold;">sudo</span> pbuilder piuparts dpatch</pre></div></div>

<h3>ソースの取得</h3>
<p><a href="https://launchpad.net/ubuntu/+source/mysql-dfsg-5.1">“mysql-dfsg-5.1” source package in Ubuntu</a>よりdevelopmentのkarmicの方のリンクをクリックして、その先の画面で以下の3つのファイルをダウンロードします。</p>
<ul>
<li>mysql-dfsg-5.1_5.1.37.orig.tar.gz &#8211; ソースtarボール</li>
<li>mysql-dfsg-5.1_5.1.37-1ubuntu2.diff.gz &#8211; debを作成するためのdiff</li>
<li>mysql-dfsg-5.1_5.1.37-1ubuntu2.dsc &#8211; パッケージングのルールを記載したファイル</li>
</ul>
<p>今回は ~/deb というディレクトリを作成してその中で作業するので、debディレクトリにダウンロードしておきます。</p>
<h3>mysql-dfsg-5.1のビルド</h3>
<p>mysql-dfsg-5.1のビルドに必要なパッケージをインストールしておきます。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> build-dep mysql-server-<span style="color: #000000;">5.1</span></pre></div></div>

<p>次にソースを展開します。dpkg-source -x を実行するとソースを展開するだけはなく、パッチも自動的に当ててくれます。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ dpkg-source <span style="color: #660033;">-x</span> mysql-dfsg-<span style="color: #000000;">5.1</span>_5.1.37-1ubuntu2.dsc
dpkg-source: warning: extracting unsigned <span style="color: #7a0874; font-weight: bold;">source</span> package <span style="color: #7a0874; font-weight: bold;">&#40;</span>mysql-dfsg-<span style="color: #000000;">5.1</span>_5.1.37-1ubuntu2.dsc<span style="color: #7a0874; font-weight: bold;">&#41;</span>
dpkg-source: extracting mysql-dfsg-<span style="color: #000000;">5.1</span> <span style="color: #000000; font-weight: bold;">in</span> mysql-dfsg-<span style="color: #000000;">5.1</span>-5.1.37
dpkg-source: info: unpacking mysql-dfsg-<span style="color: #000000;">5.1</span>_5.1.37.orig.tar.gz
dpkg-source: info: applying mysql-dfsg-<span style="color: #000000;">5.1</span>_5.1.37-1ubuntu2.diff.gz</pre></div></div>

<p>そしていよいよビルドです。(私はAthlon X2 5050eの環境で約2時間かかりました)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> mysql-dfsg-<span style="color: #000000;">5.1</span>-5.1.37
$ debuild <span style="color: #660033;">-us</span> <span style="color: #660033;">-uc</span></pre></div></div>

<p>場合によっては「&#8221;hardening-wrapper&#8221;というパッケージがないよ」というエラーになってビルドできないかもしれないので、このパッケージをaptitudeでインストールしておきます。</p>
<p>完了すると .deb パッケージが~/deb/配下に作成されているので、必要なものをdpkg -iしてインストールします。ただし、依存関係が若干複雑なのでエラーが出たら依存しているものを先にインストールすると良いでしょう。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> mysql-common_5.1.37-1ubuntu2_all.deb ¥ 
 libmysqlclient16_5.1.37-1ubuntu2_amd64.deb ¥
 mysql-client_5.1.37-1ubuntu2_all.deb ¥
 mysql-client-<span style="color: #000000;">5.1</span>_5.1.37-1ubuntu2_amd64.deb
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> mysql-server-core-<span style="color: #000000;">5.1</span>_5.1.37-1ubuntu2_amd64.deb ¥
 mysql-server-<span style="color: #000000;">5.1</span>_5.1.37-1ubuntu2_amd64.deb ¥
 mysql-server-<span style="color: #000000;">5.1</span>_5.1.37-1ubuntu2_amd64.deb</pre></div></div>

<p>なお、5.0から5.1にアップグレードするような場合、my.cnfに使えなくなったオプションを書いていたりするとmysqldの起動に失敗するので、エラーログを見て適切に対処しましょう。例えば私の場合は &#8211;skip-bdb というオプションが使えなくなっていてエラーになっていました。</p>
<p>無事にインストールできれば、これでmysql-server-5.1が最新版になっています。mysqlコマンドでSQLを発行して動作を確認してみて下さい。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ mysql <span style="color: #660033;">-uroot</span> <span style="color: #660033;">-pxxxxx</span>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection <span style="color: #c20cb9; font-weight: bold;">id</span> is <span style="color: #000000;">68</span>
Server version: 5.1.37-1ubuntu2-log <span style="color: #7a0874; font-weight: bold;">&#40;</span>Ubuntu<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<h3>補足</h3>
<p>今回はUbuntu 9.04で試しましたが、Debianでも同じ手順でパッケージを作成することができるはずです。また、debパッケージの作成にあたって<a href="http://wiki.debian.org/HidekiYamane?action=AttachFile&#038;do=get&#038;target=20080916_ylug_upload.pdf">Debianパッケージ60分クッキング(PDF)</a>を参考にさせて頂きました。</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.lampetty.net/tech/index.php/archives/331/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://tech.lampetty.net/tech/index.php/archives/331" />
	</item>
		<item>
		<title>mysqldumpでバックアップをする時につけるオプション</title>
		<link>http://tech.lampetty.net/tech/index.php/archives/292</link>
		<comments>http://tech.lampetty.net/tech/index.php/archives/292#comments</comments>
		<pubDate>Sat, 18 Apr 2009 03:44:17 +0000</pubDate>
		<dc:creator>oinume</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://tech.lampetty.net/tech/?p=292</guid>
		<description><![CDATA[MySQLのデータベースをバックアップする際にmysqldumpを使用しますが、個人的に「これはつけたらよさそう」と思っているオプションを紹介します。
 &#8211;opt
&#8211;quick &#8211;ad [...]]]></description>
			<content:encoded><![CDATA[<p>MySQLのデータベースをバックアップする際にmysqldumpを使用しますが、個人的に「これはつけたらよさそう」と思っているオプションを紹介します。</p>
<h3> &#8211;opt</h3>
<p>&#8211;quick &#8211;add-drop-table &#8211;add-locks &#8211;extended-insert &#8211;lock-tables を指定するのと同じです。ダンプしたデータをMySQL サーバに読み込むための最速ダンプを提供します。(マニュアルそのまんま)</p>
<h3> &#8211;single-transaction</h3>
<p>ダンプする際に先頭にBEGINをつけるため、ダンプ時のデータのトランザクションの一貫性を保つことができます。ただしInnoDBなどのトランザクションが有効なストレージエンジンではないと意味がないです。</p>
<h3> &#8211;flush-logs</h3>
<p>ダンプを開始する前に、MySQL サーバ内のログファイルをフラッシュします。バイナリログを保存するような設定になっている場合はこれがフラッシュされます。ダンプしたデータとバイナリログを使用してデータを復元する場合に有用です。</p>
<h3> &#8211;master-data</h3>
<p>CHANGE MASTER TOコマンドをダンプの先頭に付加します。&#8211;master-data=2を指定するとCHANGE MASTER TOがコメントアウトされた状態になります。&#8211;maser-data=1と指定するとコメントアウトされずにダンプされます。</p>
<h3> &#8211;default-character-set</h3>
<p>ダンプする際の文字コードを指定します。</p>
<h3> &#8211;hex-blob</h3>
<p>バイナリ型のデータをエスケープ処理を行わずに実際に格納された値の16進表記でダンプします。 これを指定しないと default-character-set がSJIS系の場合エスケープ処理に失敗し、バイナリデータが壊れてしまう場合があります。</p>
<h3>まとめ</h3>
<p>自分はこんな感じでバックアップをとっています。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ mysqldump <span style="color: #660033;">-uroot</span> <span style="color: #660033;">-pxxxxxxxx</span> <span style="color: #660033;">--opt</span> <span style="color: #660033;">--flush-logs</span> <span style="color: #660033;">--single-transaction</span> <span style="color: #660033;">--master-data</span>=<span style="color: #000000;">2</span> <span style="color: #660033;">--default-character-set</span>=utf8 <span style="color: #660033;">--hex-blob</span> <span style="color: #000000; font-weight: bold;">&lt;</span>database<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<div class="tmkm-amazon-view">
	<p><a href="http://www.amazon.jp/Linux-DB-%E3%82%B7%E3%82%B9%E3%83%86%E3%83%A0%E6%A7%8B%E7%AF%89-%E9%81%8B%E7%94%A8%E5%85%A5%E9%96%80-Magazine-SELECTION/dp/4798120723%3FSubscriptionId%3DAKIAJGVWECUONT35GEJA%26tag%3Dkazzhomeunixo-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4798120723"><img src="http://ecx.images-amazon.com/images/I/51iVgs86%2B2L._SL160_.jpg" border="0" alt="" /></a></p>
	<p><a href="http://www.amazon.jp/Linux-DB-%E3%82%B7%E3%82%B9%E3%83%86%E3%83%A0%E6%A7%8B%E7%AF%89-%E9%81%8B%E7%94%A8%E5%85%A5%E9%96%80-Magazine-SELECTION/dp/4798120723%3FSubscriptionId%3DAKIAJGVWECUONT35GEJA%26tag%3Dkazzhomeunixo-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4798120723">Linux-DB システム構築/運用入門 (DB Magazine SELECTION)</a></p>
	<p><em>著者／訳者：</em>松信 嘉範</p>
	<p><em>出版社：</em>翔泳社( 2009-09-17 )</p>
	<p>単行本（ソフトカバー） ( 392 ページ )</p>
<hr class="tmkm-amazon-clear" /></div>
]]></content:encoded>
			<wfw:commentRss>http://tech.lampetty.net/tech/index.php/archives/292/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://tech.lampetty.net/tech/index.php/archives/292" />
	</item>
		<item>
		<title>MySQLをインストールした後に設定する項目</title>
		<link>http://tech.lampetty.net/tech/index.php/archives/174</link>
		<comments>http://tech.lampetty.net/tech/index.php/archives/174#comments</comments>
		<pubDate>Wed, 14 Jan 2009 16:00:35 +0000</pubDate>
		<dc:creator>oinume</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://tech.lampetty.net/tech/?p=174</guid>
		<description><![CDATA[自分がMySQLをインストールしたあとに行う設定を備忘録がてら書いてみます。サーバのスペックによって若干変動するところもありますが、チューニングする項目というのは大体こんなもんでしょう。

user            [...]]]></description>
			<content:encoded><![CDATA[<p>自分がMySQLをインストールしたあとに行う設定を備忘録がてら書いてみます。サーバのスペックによって若干変動するところもありますが、チューニングする項目というのは大体こんなもんでしょう。</p>
<pre>
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
language        = /usr/share/mysql/english
skip-external-locking
# ここまではわりとお決まりの設定。環境によってファイルのパスは適宜変えます。

# サーバ側で使用する文字コードの設定
default-character-set = utf8
# クライアント/サーバ側での文字コード変換を行わない
skip-character-set-client-handshake
# CREATE TABLE する際に ENGINE=InnoDB の指定をしなくてもInnoDBにする
default-table-type = InnoDB
# クライアント/サーバがやり取りすることのできるパケットサイズを指定
# 巨大なデータをやり取りする場合は指定した方がよい
max_allowed_packet      = 16M

# MyISAMで使用するINDEXのキャッシュサイズ
key_buffer              = 64M
# スレッドのスタック領域のサイズ
thread_stack            = 128K
# 生成されたコネクション用のスレッドをキャッシュしておく数
thread_cache_size       = 16
# 最大同時接続数。メモリ搭載量にもよるが100〜300ぐらいが良いらしい
max_connections        = 150
# MyISAMで一度開いたテーブルをキャッシュしておく数
table_cache            = 128
# 同時に実行できるスレッド数。CPUのコア数の2倍を設定
thread_concurrency     = 2

# query cacheの設定
# 0: OFF, 1:ON, 2:DEMAND
query_cache_type      = 1
# キャッシュするクエリ結果の最大サイズ
query_cache_limit       = 1M
# クエリキャッシュに割り当てるメモリ量
query_cache_size        = 16M

# slow logの設定
log_slow_queries       = /var/log/mysql/mysql-slow.log
# 3秒以上かかったクエリは上記ログファイルに出力
long_query_time = 3

# ここからレプリケーションの設定
#  MySQLサーバごとに固有のID
server-id               = 1
# バイナリログ出力先
log_bin                 = /var/log/mysql/mysql-bin.log
# データ書き込み(トランザクションのコミット)を何回行ったらバイナリログを
# フラッシュするかの回数。0の場合はデータ書き込みがあってもバイナリログをフラッシュしない
sync_binlog             = 0
# バイナリログを保持しておく日数
expire_logs_days        = 60
# バイナリログの1ファイルあたりの最大サイズ
max_binlog_size         = 1024M
# バイナリログを出力する対象のDB
binlog_do_db           = hoge
# バイナリログの出力対象外とするDB
binlog_ignore_db        = mysql information_schema

# Berkley DBは使わない
skip-bdb

# InnoDBのデータファイルの名前とどのぐらいで自動拡張するか
innodb_data_file_path = ibdata1:128M:autoextend
# テーブルごとに.ibdのデータファイルを作成するかどうか
innodb_file_per_table = 1
# InnoDBの内部データなどを保持するための領域
innodb_additional_mem_pool_size = 20M
# InnoDBのデータやインデックスをキャッシュするためのメモリ上の領域
# DBサーバ専用のマシンの場合はメモリの50%-80%を指定
innodb_buffer_pool_size         = 256M
# InnoDBの更新ログを記録するメモリ上の領域
innodb_log_buffer_size          = 8M
# InnoDBの更新ログを記録するディスク上のファイルのサイズ
# 大きくするとパフォーマンスはあがるがクラッシュ時のリカバリに時間がかかるようになる
innodb_log_file_size            = 64M
# データをファイルに書き込む際のメソッド。
# Linuxの場合は O_DIRECTがパフォーマンス的にはよい
innodb_flush_method             = O_DIRECT
# InnoDBのログバッファをInnoDBログファイルに書き込むタイミングを決める
# 基本的には1
innodb_flush_log_at_trx_commit  = 1
# 2相コミットを行うかどうか
innodb_support_xa               = OFF
# クラッシュ対策としてデータの二重書き込みを無効にする
skip-innodb_doublewrite
</pre>
<p>innodb_で始まるInnoDB関連の設定項目の詳細については<a href="http://www.klab.jp/media/mysql/index3.html">MySQL5開拓団 ストレージエンジンの吟味 (2)</a>にとても詳しく載っているので一読してみた方がよいです。あとは<a href="http://dsas.blog.klab.org/archives/50860867.html">DSAS開発者の部屋:5分でできる、MySQLのメモリ関係のチューニング！</a>も非常に参考になるでしょう。MySQLの設定はなかなか奥が深いですが、設定項目の意味を理解していればよいパフォーマンスを引き出せると思います。</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.lampetty.net/tech/index.php/archives/174/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://tech.lampetty.net/tech/index.php/archives/174" />
	</item>
		<item>
		<title>MySQLでテーブルのコピーを簡単に作る方法</title>
		<link>http://tech.lampetty.net/tech/index.php/archives/273</link>
		<comments>http://tech.lampetty.net/tech/index.php/archives/273#comments</comments>
		<pubDate>Sat, 22 Nov 2008 22:56:18 +0000</pubDate>
		<dc:creator>oinume</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://tech.lampetty.net/tech/?p=273</guid>
		<description><![CDATA[hogeテーブルをhoge_20081123というテーブルにコピーする方法。

/* hogeテーブルのスキーマをコピーしてテーブル作成 */
&#62; CREATE TABLE hoge_20081123 LIKE h [...]]]></description>
			<content:encoded><![CDATA[<p>hogeテーブルをhoge_20081123というテーブルにコピーする方法。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/*</span> hogeテーブルのスキーマをコピーしてテーブル作成 <span style="color: #000000; font-weight: bold;">*/</span>
<span style="color: #000000; font-weight: bold;">&gt;</span> CREATE TABLE hoge_20081123 LIKE hoge;
<span style="color: #000000; font-weight: bold;">/*</span> hogeテーブルのデータをINSERT <span style="color: #000000; font-weight: bold;">*/</span>
<span style="color: #000000; font-weight: bold;">&gt;</span> INSERT INTO hoge_20081123 SELECT <span style="color: #000000; font-weight: bold;">*</span> FROM hoge;</pre></div></div>

<p>たまにしかやらないのですが、いっつも忘れているのでメモ。</p>
<div class="tmkm-amazon-view">
	<p><a href="http://www.amazon.jp/%E5%AE%9F%E8%B7%B5%E3%83%8F%E3%82%A4%E3%83%91%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%B3%E3%82%B9MySQL-%E7%AC%AC2%E7%89%88-Baron-Schwartz/dp/4873114268%3FSubscriptionId%3DAKIAJGVWECUONT35GEJA%26tag%3Dkazzhomeunixo-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4873114268"><img src="http://ecx.images-amazon.com/images/I/51s%2Bp62hCgL._SL160_.jpg" border="0" alt="" /></a></p>
	<p><a href="http://www.amazon.jp/%E5%AE%9F%E8%B7%B5%E3%83%8F%E3%82%A4%E3%83%91%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%B3%E3%82%B9MySQL-%E7%AC%AC2%E7%89%88-Baron-Schwartz/dp/4873114268%3FSubscriptionId%3DAKIAJGVWECUONT35GEJA%26tag%3Dkazzhomeunixo-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4873114268">実践ハイパフォーマンスMySQL 第2版</a></p>
	<p><em>著者／訳者：</em>Baron Schwartz Peter Zaitsev Vadim Tkachenko Jeremy D. Zawodny Arjen Lentz Derek J. Balling </p>
	<p><em>出版社：</em>オライリージャパン( 2009-12-14 )</p>
	<p>大型本 ( 736 ページ )</p>
<hr class="tmkm-amazon-clear" /></div>
]]></content:encoded>
			<wfw:commentRss>http://tech.lampetty.net/tech/index.php/archives/273/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://tech.lampetty.net/tech/index.php/archives/273" />
	</item>
	</channel>
</rss>
