<?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, Python あたり</description>
	<lastBuildDate>Wed, 18 Jan 2012 15:52:48 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<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>rlwrapを使ってmysqlコマンドのプロンプトに色をつける</title>
		<link>http://tech.lampetty.net/tech/index.php/archives/434?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rlwrap%25e3%2582%2592%25e4%25bd%25bf%25e3%2581%25a3%25e3%2581%25a6mysql%25e3%2582%25b3%25e3%2583%259e%25e3%2583%25b3%25e3%2583%2589%25e3%2581%25ae%25e3%2583%2597%25e3%2583%25ad%25e3%2583%25b3%25e3%2583%2597%25e3%2583%2588%25e3%2581%25ab%25e8%2589%25b2%25e3%2582%2592%25e3%2581%25a4%25e3%2581%2591%25e3%2582%258b</link>
		<comments>http://tech.lampetty.net/tech/index.php/archives/434#comments</comments>
		<pubDate>Sat, 10 Dec 2011 23:24:43 +0000</pubDate>
		<dc:creator>oinume</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://tech.lampetty.net/tech/?p=434</guid>
		<description><![CDATA[どうもこんにちは。北海道に旅行中でこの記事は札幌のホテルから書いている oinume です。MySQL Casual Advent Calendarも11日目になりました。「MySQL Casualが全然カジュアルじゃな [...]]]></description>
			<content:encoded><![CDATA[<p>どうもこんにちは。北海道に旅行中でこの記事は札幌のホテルから書いている <a href="http://twitter.com/#!/oinume">oinume</a> です。<a href="http://atnd.org/events/22528">MySQL Casual Advent Calendar</a>も11日目になりました。「MySQL Casualが全然カジュアルじゃない！」という意見をよく耳にするので、今日はウルトラカジュアルなエントリーを書こうと思います。</p>
<h3>はじめに</h3>
<p>MySQLを使って開発をしていると、本番と開発用サーバの見分けがつかずに、間違って本番で重いクエリを発行しちゃったりします。そういうオペミスを少しでも防ぐために「本番環境ではmysqlコマンドのプロンプトの色を変える」という技を紹介したいと思います。</p>
<h3>rlwrap</h3>
<p>紹介といってもやり方は非常に簡単で、下記のように <a href="http://utopia.knoware.nl/~hlub/rlwrap/rlwrap.html">rlwrap</a> というコマンドを使って mysql コマンドを実行します。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rlwrap <span style="color: #660033;">-a</span> <span style="color: #660033;">-pRED</span> mysql <span style="color: #660033;">-uroot</span></pre></div></div>

<p>するとあら不思議！MySQLのプロンプトが下記のように赤くなりました！</p>
<p><a class="" rel="lightbox" title="pydoc -g" href="http://www.flickr.com/photos/8250493@N05/6486939925/"><img src="http://farm8.staticflickr.com/7030/6486939925_7ffb187781.jpg" alt="rlwrapでmysqlプロンプトに色をつけてみる"></a></p>
<p>というわけで、rlwrapがインストールされているマシンであれば、下記のように .bashrc 的なファイルに書いておくことでmysqlのプロンプトを常に赤くすることができてオペミスも減らせますね！</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-x</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rlwrap <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">mysql</span>=<span style="color: #ff0000;">'/usr/bin/rlwrap -a -pRED mysql'</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>ちなみに rlwrap は Debian(Ubuntu) であれば apt でインストールできます。</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> rlwrap</pre></div></div>

<p>CentOSの場合はepelリポジトリが追加されていれば yum でインストールできます。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> yum <span style="color: #c20cb9; font-weight: bold;">install</span> rlwrap</pre></div></div>

<h3>さいごに</h3>
<p>このウルトラカジュアルっぷりいかがでしたでしょうか。Advent Calendar 12日目は <a href="http://twitter.com/#!/ikasam_a">ikasam_a</a> さんです。よろしくお願いします！</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.lampetty.net/tech/index.php/archives/434/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/434" />
	</item>
		<item>
		<title>MySQL Casual Talks Vol.2 で話してきた</title>
		<link>http://tech.lampetty.net/tech/index.php/archives/423?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-casual-talks-vol-2-%25e3%2581%25a7%25e8%25a9%25b1%25e3%2581%2597%25e3%2581%25a6%25e3%2581%258d%25e3%2581%259f</link>
		<comments>http://tech.lampetty.net/tech/index.php/archives/423#comments</comments>
		<pubDate>Thu, 11 Aug 2011 11:31:36 +0000</pubDate>
		<dc:creator>oinume</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[日記]]></category>

		<guid isPermaLink="false">http://tech.lampetty.net/tech/?p=423</guid>
		<description><![CDATA[MySQL Casual Talks Vol.2で20分枠をもらって話してきた！こんなに長い時間人前で話すのは初めてだったので緊張しまくりでした。話した内容は仕事(ピグ)で利用しているMySQL上で運用しているNoSQL [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://togetter.com/li/172489">MySQL Casual Talks Vol.2</a>で20分枠をもらって話してきた！こんなに長い時間人前で話すのは初めてだったので緊張しまくりでした。話した内容は仕事(ピグ)で利用しているMySQL上で運用しているNoSQLのやり方について。MySQLの設定とかの話は一切せずJavaのコードがメインでした。</p>
<div style="width:510px" id="__ss_8819474"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/oinume/mysql-casual-talks220110809" title="MySQLでNoSQL - アメーバピグでのNoSQLの実例" target="_blank">MySQLでNoSQL &#8211; アメーバピグでのNoSQLの実例</a></strong> <object id="__sse8819474" width="510" height="426"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=mysqlcasualtalks220110809-110810111850-phpapp01&#038;stripped_title=mysql-casual-talks220110809&#038;userName=oinume" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse8819474" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=mysqlcasualtalks220110809-110810111850-phpapp01&#038;stripped_title=mysql-casual-talks220110809&#038;userName=oinume" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="510" height="426"></embed></object>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/oinume" target="_blank">Kazuhiro Oinuma</a> </div>
</p></div>
<p>正直、<a href="http://twitter.com/#!/myfinder">myfinder</a>さんに声をかけられたときはどうしようかと悩んだけど、こういう経験はなかなかできないので良かったです。場数を踏むっていうのも重要ですしね。懇親会では riywo さんとシステム運用のガチトークをできたし、DeNAの人とたくさん絡めてよかったですｗ riywo さんが「MySQL Formal Talksやっても来るメンバーって変わらないよね」って言ってたのがなんともこの勉強会を象徴していて妙に印象に残っていますｗ</p>
<p>Vol.3 があったら今度は弊社メンバーの誰かにFusion-IOの話をしてもらいたいなぁ。</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.lampetty.net/tech/index.php/archives/423/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/423" />
	</item>
		<item>
		<title>ブログのMySQLを5.1から5.5にバージョンアップ</title>
		<link>http://tech.lampetty.net/tech/index.php/archives/412?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=%25e3%2583%2596%25e3%2583%25ad%25e3%2582%25b0%25e3%2581%25aemysql%25e3%2582%25925-1%25e3%2581%258b%25e3%2582%25895-5%25e3%2581%25ab%25e3%2583%2590%25e3%2583%25bc%25e3%2582%25b8%25e3%2583%25a7%25e3%2583%25b3%25e3%2582%25a2%25e3%2583%2583%25e3%2583%2597</link>
		<comments>http://tech.lampetty.net/tech/index.php/archives/412#comments</comments>
		<pubDate>Fri, 03 Jun 2011 16:50:39 +0000</pubDate>
		<dc:creator>oinume</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://tech.lampetty.net/tech/?p=412</guid>
		<description><![CDATA[5.5ってどうなんだろう？と思ったので試しにこのブログのMySQLを5.1 -> 5.5にしてみた。 tar.gz のバイナリを取ってきて /usr/local/mysql-5.5.13-linux-2.6-i686 に [...]]]></description>
			<content:encoded><![CDATA[<p>5.5ってどうなんだろう？と思ったので試しにこのブログのMySQLを5.1 -> 5.5にしてみた。</p>
<p>tar.gz のバイナリを取ってきて /usr/local/mysql-5.5.13-linux-2.6-i686 に展開して /usr/local/mysql にsymlink (バージョンアップに失敗したときにすぐに戻せるように)。あとはstop start して起動するだけ。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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>mysql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysqld: error <span style="color: #000000; font-weight: bold;">while</span> loading shared libraries: libaio.so.1: cannot open shared object <span style="color: #c20cb9; font-weight: bold;">file</span>: No such <span style="color: #c20cb9; font-weight: bold;">file</span> or directory</pre></div></div>

<p>って言われるので、libaioをインストール(ubuntu)</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> libaio
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>ldconfig</pre></div></div>

<p>もう1回起動。今度は</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">110604</span>  <span style="color: #000000;">1</span>:<span style="color: #000000;">16</span>:<span style="color: #000000;">45</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>ERROR<span style="color: #7a0874; font-weight: bold;">&#93;</span> <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>mysql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysqld: unknown variable <span style="color: #ff0000;">'default-table-type=InnoDB'</span></pre></div></div>

<p>って怒られる。どうやら default-table-type は使えなくなったらしい。</p>
<pre>
default-storage-engine = InnoDB
</pre>
<p>としたら無事起動。</p>
<p>最後に</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># /usr/local/mysql/bin/mysql_upgrade</span></pre></div></div>

<p>して完了。今のところ無問題。</p>
<div class="tmkm-amazon-view">
	<p><a href="http://www.amazon.co.jp/%E3%82%A8%E3%82%AD%E3%82%B9%E3%83%91%E3%83%BC%E3%83%88%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AEMySQL-%E9%81%8B%E7%94%A8-%E7%AE%A1%E7%90%86-%E3%83%88%E3%83%A9%E3%83%96%E3%83%AB%E3%82%B7%E3%83%A5%E3%83%BC%E3%83%86%E3%82%A3%E3%83%B3%E3%82%B0%E3%82%AC%E3%82%A4%E3%83%89-%E5%A5%A5%E9%87%8E/dp/4774142948%3FSubscriptionId%3DAKIAJGVWECUONT35GEJA%26tag%3Dkazzhomeunixo-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4774142948"><img src="http://ecx.images-amazon.com/images/I/41oqE-9dM2L._SL160_.jpg" border="0" alt="" /></a></p>
	<p><a href="http://www.amazon.co.jp/%E3%82%A8%E3%82%AD%E3%82%B9%E3%83%91%E3%83%BC%E3%83%88%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AEMySQL-%E9%81%8B%E7%94%A8-%E7%AE%A1%E7%90%86-%E3%83%88%E3%83%A9%E3%83%96%E3%83%AB%E3%82%B7%E3%83%A5%E3%83%BC%E3%83%86%E3%82%A3%E3%83%B3%E3%82%B0%E3%82%AC%E3%82%A4%E3%83%89-%E5%A5%A5%E9%87%8E/dp/4774142948%3FSubscriptionId%3DAKIAJGVWECUONT35GEJA%26tag%3Dkazzhomeunixo-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4774142948">エキスパートのためのMySQL[運用+管理]トラブルシューティングガイド</a></p>
	<p><em>著者／訳者：</em>奥野 幹也</p>
	<p><em>出版社：</em>技術評論社( 2010-06-12 )</p>
	<p>大型本 ( 520 ページ )</p>
<hr class="tmkm-amazon-clear" /></div>
]]></content:encoded>
			<wfw:commentRss>http://tech.lampetty.net/tech/index.php/archives/412/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/412" />
	</item>
		<item>
		<title>MuninでMySQLプラグインのグラフが描画されない時の解決方法</title>
		<link>http://tech.lampetty.net/tech/index.php/archives/369?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=munin%25e3%2581%25a7mysql%25e3%2583%2597%25e3%2583%25a9%25e3%2582%25b0%25e3%2582%25a4%25e3%2583%25b3%25e3%2581%25ae%25e3%2582%25b0%25e3%2583%25a9%25e3%2583%2595%25e3%2581%258c%25e6%258f%258f%25e7%2594%25bb%25e3%2581%2595%25e3%2582%258c%25e3%2581%25aa%25e3%2581%2584%25e6%2599%2582%25e3%2581%25ae%25e8%25a7%25a3%25e6%25b1%25ba</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?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-5-1%25e3%2581%25ae%25e6%259c%2580%25e6%2596%25b0%25e3%2581%25ae%25e3%2582%25bd%25e3%2583%25bc%25e3%2582%25b9%25e3%2581%258b%25e3%2582%2589deb%25e3%2582%2592%25e4%25bd%259c%25e6%2588%2590%25e3%2581%2599%25e3%2582%258b</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?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql%25e3%2581%25aedrop-table%25e3%2581%25a7%25e3%2581%25af%25e8%25a4%2587%25e6%2595%25b0%25e3%2581%25ae%25e3%2583%2586%25e3%2583%25bc%25e3%2583%2596%25e3%2583%25ab%25e3%2582%2592%25e4%25b8%2580%25e6%25b0%2597%25e3%2581%25ab%25e5%2589%258a%25e9%2599%25a4%25e3%2581%25a7%25e3%2581%258d%25e3%2582%258b</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 fu [...]]]></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>
<div class="tmkm-amazon-view">
	<p><a href="http://www.amazon.co.jp/%E3%82%A8%E3%82%AD%E3%82%B9%E3%83%91%E3%83%BC%E3%83%88%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AEMySQL-%E9%81%8B%E7%94%A8-%E7%AE%A1%E7%90%86-%E3%83%88%E3%83%A9%E3%83%96%E3%83%AB%E3%82%B7%E3%83%A5%E3%83%BC%E3%83%86%E3%82%A3%E3%83%B3%E3%82%B0%E3%82%AC%E3%82%A4%E3%83%89-%E5%A5%A5%E9%87%8E/dp/4774142948%3FSubscriptionId%3DAKIAJGVWECUONT35GEJA%26tag%3Dkazzhomeunixo-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4774142948"><img src="http://ecx.images-amazon.com/images/I/41oqE-9dM2L._SL160_.jpg" border="0" alt="" /></a></p>
	<p><a href="http://www.amazon.co.jp/%E3%82%A8%E3%82%AD%E3%82%B9%E3%83%91%E3%83%BC%E3%83%88%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AEMySQL-%E9%81%8B%E7%94%A8-%E7%AE%A1%E7%90%86-%E3%83%88%E3%83%A9%E3%83%96%E3%83%AB%E3%82%B7%E3%83%A5%E3%83%BC%E3%83%86%E3%82%A3%E3%83%B3%E3%82%B0%E3%82%AC%E3%82%A4%E3%83%89-%E5%A5%A5%E9%87%8E/dp/4774142948%3FSubscriptionId%3DAKIAJGVWECUONT35GEJA%26tag%3Dkazzhomeunixo-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4774142948">エキスパートのためのMySQL[運用+管理]トラブルシューティングガイド</a></p>
	<p><em>著者／訳者：</em>奥野 幹也</p>
	<p><em>出版社：</em>技術評論社( 2010-06-12 )</p>
	<p>大型本 ( 520 ページ )</p>
<hr class="tmkm-amazon-clear" /></div>
]]></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?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hbstudy5%25e3%2581%25ab%25e5%258f%2582%25e5%258a%25a0%25e3%2581%2597%25e3%2581%25a6%25e3%2581%258d%25e3%2581%25be%25e3%2581%2597%25e3%2581%259f</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?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-5-1%25e3%2581%25ae%25e6%259c%2580%25e6%2596%25b0%25e7%2589%2588%25e3%2581%25aedeb%25e3%2583%2591%25e3%2583%2583%25e3%2582%25b1%25e3%2583%25bc%25e3%2582%25b8%25e3%2582%2592%25e4%25bd%259c%25e6%2588%2590%25e3%2581%2599%25e3%2582%258b%25e6%2596%25b9%25e6%25b3%2595</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?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysqldump%25e3%2581%25a7%25e3%2583%2590%25e3%2583%2583%25e3%2582%25af%25e3%2582%25a2%25e3%2583%2583%25e3%2583%2597%25e3%2582%2592%25e3%2581%2599%25e3%2582%258b%25e6%2599%2582%25e3%2581%25ab%25e3%2581%25a4%25e3%2581%2591%25e3%2582%258b%25e3%2582%25aa%25e3%2583%2597%25e3%2582%25b7%25e3%2583%25a7%25e3%2583%25b3</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;add [...]]]></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.co.jp/%E3%82%A8%E3%82%AD%E3%82%B9%E3%83%91%E3%83%BC%E3%83%88%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AEMySQL-%E9%81%8B%E7%94%A8-%E7%AE%A1%E7%90%86-%E3%83%88%E3%83%A9%E3%83%96%E3%83%AB%E3%82%B7%E3%83%A5%E3%83%BC%E3%83%86%E3%82%A3%E3%83%B3%E3%82%B0%E3%82%AC%E3%82%A4%E3%83%89-%E5%A5%A5%E9%87%8E/dp/4774142948%3FSubscriptionId%3DAKIAJGVWECUONT35GEJA%26tag%3Dkazzhomeunixo-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4774142948"><img src="http://ecx.images-amazon.com/images/I/41oqE-9dM2L._SL160_.jpg" border="0" alt="" /></a></p>
	<p><a href="http://www.amazon.co.jp/%E3%82%A8%E3%82%AD%E3%82%B9%E3%83%91%E3%83%BC%E3%83%88%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AEMySQL-%E9%81%8B%E7%94%A8-%E7%AE%A1%E7%90%86-%E3%83%88%E3%83%A9%E3%83%96%E3%83%AB%E3%82%B7%E3%83%A5%E3%83%BC%E3%83%86%E3%82%A3%E3%83%B3%E3%82%B0%E3%82%AC%E3%82%A4%E3%83%89-%E5%A5%A5%E9%87%8E/dp/4774142948%3FSubscriptionId%3DAKIAJGVWECUONT35GEJA%26tag%3Dkazzhomeunixo-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4774142948">エキスパートのためのMySQL[運用+管理]トラブルシューティングガイド</a></p>
	<p><em>著者／訳者：</em>奥野 幹也</p>
	<p><em>出版社：</em>技術評論社( 2010-06-12 )</p>
	<p>大型本 ( 520 ページ )</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?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql%25e3%2582%25a4%25e3%2583%25b3%25e3%2582%25b9%25e3%2583%2588%25e3%2583%25bc%25e3%2583%25ab%25e5%25be%258c%25e3%2581%25ab%25e8%25a8%25ad%25e5%25ae%259a%25e3%2581%2599%25e3%2582%258b%25e9%25a0%2585%25e7%259b%25ae</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 = mysql pid [...]]]></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?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql%25e3%2581%25a7%25e3%2583%2586%25e3%2583%25bc%25e3%2583%2596%25e3%2583%25ab%25e3%2581%25ae%25e3%2582%25b3%25e3%2583%2594%25e3%2583%25bc%25e3%2582%2592%25e7%25b0%25a1%25e5%258d%2598%25e3%2581%25ab%25e4%25bd%259c%25e3%2582%258b%25e6%2596%25b9%25e6%25b3%2595</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 ho [...]]]></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.co.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.co.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>

