<?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>clicktx::Tech::Memo &#187; MySQL</title>
	<atom:link href="http://perl.no-tubo.net/category/rdbms/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://perl.no-tubo.net</link>
	<description>perl、 MySQL、オープンソース系、ウェブ系ネタ。なぜか鯖管メモがほとんどを占めている...</description>
	<lastBuildDate>Mon, 23 Jan 2012 10:51:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</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://perl.no-tubo.net/category/rdbms/mysql/feed/" />
		<item>
		<title>MAMP(Apache+MySQL)を使ってローカルでらくらくperl開発</title>
		<link>http://perl.no-tubo.net/2011/12/15/manmpapachemysql%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%ad%e3%83%bc%e3%82%ab%e3%83%ab%e3%81%a7%e3%82%89%e3%81%8f%e3%82%89%e3%81%8fperl%e9%96%8b%e7%99%ba/</link>
		<comments>http://perl.no-tubo.net/2011/12/15/manmpapachemysql%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%ad%e3%83%bc%e3%82%ab%e3%83%ab%e3%81%a7%e3%82%89%e3%81%8f%e3%82%89%e3%81%8fperl%e9%96%8b%e7%99%ba/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 03:34:59 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[webプログラミング]]></category>
		<category><![CDATA[cpanm]]></category>
		<category><![CDATA[MacPorts]]></category>
		<category><![CDATA[MANP]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[開発環境]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=2177</guid>
		<description><![CDATA[MAMP
Apache+MySQLサーバをmacで動作させる事ができる。macにはもともとApacheもperlもインストールされているけど、バージョンが古いし、管理も面倒なのでMANPを使うメリットはおおいにあると思う [...]]]></description>
			<content:encoded><![CDATA[<h3>MAMP</h3>
<p>Apache+MySQLサーバをmacで動作させる事ができる。macにはもともとApacheもperlもインストールされているけど、バージョンが古いし、管理も面倒なのでMANPを使うメリットはおおいにあると思う。もともとはPHP+MySQLのローカル環境を構築するためのもの&#8230;かな？</p>
<p>参考：<a href="http://gabs.cc/blog/bun/topic20090608-1456.php">Mac OS Xのローカル環境(MAMP+MacPorts)で Movable Typeを動かしてみよう &#8211; 準備編　 [ 09.06.24 update ] 【 gabs.log｜おしゃべり好きなWEB制作者のたわごと 】</a></p>
<h4>MAMPをインストール</h4>
<p><a href="http://perl.no-tubo.net/wp-content/uploads/2011/11/ad742af065c3a8cba15a777a8bb696dd.png"><img src="http://perl.no-tubo.net/wp-content/uploads/2011/11/ad742af065c3a8cba15a777a8bb696dd-499x346.png" alt="MAMP" title="MAMP" width="499" height="346" class="alignnone size-medium wp-image-2180" /></a></p>
<p><a href="http://www.mamp.info/en/index.html">MAMP</a>からダウンロードしてインストールする。</p>
<h3>MacPortsのインストール</h3>
<p>makeとか使うのでXCodeが必要。OSのバージョンにあったものをダウンロードする。</p>
<li><a href="http://www.macports.org/install.php">The MacPorts Project &#8212; Download &#038; Installation</a></li>
<h4>MacPortsの初期化＆設定</h4>
<p>Terminalでコマンドを実行</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'export PATH=$PATH:/opt/local/bin:/opt/local/sbin/'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'export MANPATH=$MANPATH:/opt/local/man'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'source ~/.bashrc'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bash_profile
<span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #660033;">-d</span> selfupdate
<span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #660033;">-d</span> <span style="color: #c20cb9; font-weight: bold;">sync</span></pre></div></div></div>

<h4>perlのPATHを変更</h4>
<p>元のperlをperl.bakにリネームして、シンボリックリンクを貼る。これをしておかないと元々インストールしてあるperl(/usr/bin/perl)を参照してしまうため。</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</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>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> perl.bak
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>opt<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><span style="color: #c20cb9; font-weight: bold;">perl</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><span style="color: #c20cb9; font-weight: bold;">perl</span></pre></div></div></div>

<h3>cpanmをインストール</h3>
<p>perlモジュールを簡単にインストールできるcpanmをインストールする。</p>
<li><a href="http://artifactsauce.blogspot.com/2010/10/cpanmmac-os-x.html">ArtifactSauce: cpanmをMac OS Xにインストールする</a></li>
<p>sudoでインストールすると /opt/local/lib 以下にインストールされる。</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> cpanm Mojolicious
or
cpanm <span style="color: #660033;">-S</span> Mojolicious</pre></div></div></div>

<p>ユーザー権限でインストールした場合は、ホームディレクトリ ~/perl5/lib/ 以下にインストールされるので、この場合はPATHの指定が必要。コード側に書くか、あらかじめ設定しておく必要がある。<br />
Apacheのconfigに設定するのが吉かな？</p>
<p>httpd.confに記述</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">SetEnv</span> PERL5LIB /Users/clicktx/perl5/lib/perl5</pre></div></div></div>

<li><a href="http://www.xdelta.net/wiki/Perl/@INC.html">KMsWiki: Perl/@INC &#8211; Perlのライブラリの検索PATHを格納した配列のこと。 例えば、コマンド&#8230;</a></li>
<li><a href="http://okwave.jp/qa/q3543374.html">CGIでの環境変数PERL5LIBの設定 | OKWave</a></li>
<h4>MAMPでCGI(perl)を実行できるようにする</h4>
<p>/Applications/MAMP/conf/apache/httpd.conf を編集する。自分の場合は /Applications/MAMP/htdocs以下全部で実行したいので以下の場所を変更。</p>
<p>453行目付近</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">    <span style="color: #adadad; font-style: italic;">#AddHandler cgi-script .cgi</span>
    <span style="color: #00007f;">AddHandler</span> cgi-<span style="color: #00007f;">script</span> .cgi .pl .pm ←追記</pre></div></div></div>

<p>httpd.confを編集したらMANPを再起動して設定を反映させる。</p>
<h3>CGI実行テスト</h3>
<p>/アプリケーション/MAMP/htdocs/ に test.cgiを作成する。</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/env perl</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Content-type:text/html<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Hello, World!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">exit</span><span style="color: #339933;">;</span></pre></div></div></div>

<p>test.cgi に実行権を与える。</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>MANP<span style="color: #000000; font-weight: bold;">/</span>htdocs
$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> test.cgi</pre></div></div></div>

<p>webブラウザで http://localhost/test.cgi にアクセスして表示されたら成功。</p>
<p>ちなみにMAMPの読み方はまんｐーでいいんじゃないでしょうか？</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/12/15/manmpapachemysql%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%ad%e3%83%bc%e3%82%ab%e3%83%ab%e3%81%a7%e3%82%89%e3%81%8f%e3%82%89%e3%81%8fperl%e9%96%8b%e7%99%ba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/12/15/manmpapachemysql%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%ad%e3%83%bc%e3%82%ab%e3%83%ab%e3%81%a7%e3%82%89%e3%81%8f%e3%82%89%e3%81%8fperl%e9%96%8b%e7%99%ba/" />
	</item>
		<item>
		<title>DBIx::Customでデータベースの関数（MySQLのADDDATE()とかSUBDATE()とか）を使う</title>
		<link>http://perl.no-tubo.net/2011/07/29/dbixcustom%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e9%96%a2%e6%95%b0%ef%bc%88mysql%e3%81%aeadddate%e3%81%a8%e3%81%8bsubdate%e3%81%a8%e3%81%8b%ef%bc%89%e3%82%92/</link>
		<comments>http://perl.no-tubo.net/2011/07/29/dbixcustom%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e9%96%a2%e6%95%b0%ef%bc%88mysql%e3%81%aeadddate%e3%81%a8%e3%81%8bsubdate%e3%81%a8%e3%81%8b%ef%bc%89%e3%82%92/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 10:00:38 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[perlモジュール]]></category>
		<category><![CDATA[DBIx::Custom]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=1869</guid>
		<description><![CDATA[DBIx::Customが生SQL感覚でも使えてお気に入りなのだけれど、ちょっこしハマったのでメモ。
DBIx::Custom &#8211; search.cpan.org 
MySQL（に限らないと思う）でwhere [...]]]></description>
			<content:encoded><![CDATA[<p>DBIx::Customが生SQL感覚でも使えてお気に入りなのだけれど、ちょっこしハマったのでメモ。</p>
<p><a href="http://search.cpan.org/~kimoto/DBIx-Custom/lib/DBIx/Custom.pm">DBIx::Custom &#8211; search.cpan.org</a> </p>
<p>MySQL（に限らないと思う）でwhereに関数を利用したい時は多々あると思います。<br />
例えば、更新時刻を見て7日以上古ければ選択しないという条件をwhereに指定したい時、</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span>  <span style="color: #ff0000;">`table`</span> <span style="color: #66cc66;">&#40;</span>
    <span style="color: #ff0000;">`name`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">5</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">,</span>
    <span style="color: #ff0000;">`update_time`</span> <span style="color: #993333; font-weight: bold;">TIMESTAMP</span>
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`table`</span> <span style="color: #993333; font-weight: bold;">WHERE</span> update_time <span style="color: #66cc66;">&gt;</span> SUBDATE<span style="color: #66cc66;">&#40;</span>NOW<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">INTERVAL</span> <span style="color: #cc66cc;">7</span> <span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div></div>

<p>このようなSQLだとします。</p>
<p><a href="http://d.hatena.ne.jp/perlcodesample/20110210/1300165343">行の選択 select / DBIx::Custom リファレンス &#8211; サンプルコードによるPerl入門</a>によれば、where句の設定は、</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">where <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>title <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Perl'</span><span style="color: #339933;">,</span> author <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Ken'</span><span style="color: #009900;">&#125;</span></pre></div></div></div>

<p>と、ハッシュリファレンスで渡すことになっています。</p>
<p>=  以外での比較は DBIx::Custom::Whereオブジェクト を作成して渡すことになっているのですが、ハッシュリファレンスで SUBDATE(NOW(),  interval 7 day) を渡すとうまくいかないので悩んでいました。</p>
<p>append =&gt; &#8221; で文字列を追加できるので、無理やり実装してみたのですが作者にツイートしてみたところ、</p>
<p><a href="http://perl.no-tubo.net/wp-content/uploads/2011/07/2bfc96a45921677282a36721a07709ca1.png"><img src="http://perl.no-tubo.net/wp-content/uploads/2011/07/2bfc96a45921677282a36721a07709ca1-500x307.png" alt="twitterのキャプチャ" title="twitterのキャプチャ" width="500" height="307" class="alignnone size-medium wp-image-1881" /></a></p>
<p>がーん、そうなのか。恥ずかしい。。さらに、</p>
<p><a href="http://perl.no-tubo.net/wp-content/uploads/2011/07/d8eddf5329882d76f0b5323c6fd8e79a.png"><img src="http://perl.no-tubo.net/wp-content/uploads/2011/07/d8eddf5329882d76f0b5323c6fd8e79a-500x319.png" alt="twitterのキャプチャ2" title="twitterのキャプチャ2" width="500" height="319" class="alignnone size-medium wp-image-1883" /></a></p>
<p>がーん、DBIx::Custom::Where でも文字列が指定できたのか。。。（恥恥</p>
<p>という事で、</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> DBIx<span style="color: #339933;">::</span><span style="color: #006600;">Custom</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbi</span> <span style="color: #339933;">=</span> DBIx<span style="color: #339933;">::</span><span style="color: #006600;">Custom</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">connect</span><span style="color: #009900;">&#40;</span>
    <span style="color: #339933;">...........</span>  端折ります
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">select</span><span style="color: #009900;">&#40;</span>
    table <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'table'</span><span style="color: #339933;">,</span>
    where <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'create_time &gt; SUBDATE(NOW(),  interval 7 day)'</span><span style="color: #339933;">,</span> 
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div></div>

<p>あるいは、</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> DBIx<span style="color: #339933;">::</span><span style="color: #006600;">Custom</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$where</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">where</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$where</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">clause</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
    <span style="color: #ff0000;">'and'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'create_time &gt; SUBDATE(NOW(),  interval 7 day)'</span>
<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">select</span><span style="color: #009900;">&#40;</span>
    table <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'table'</span><span style="color: #339933;">,</span>
    where <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$where</span><span style="color: #339933;">,</span> 
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div></div>

<p>で、出来るって事なんですね。（ソース嫁！）</p>
<p>id:perlcodesampleさんありがとうございました！<br />
DBIx::Customいいよー。</p>
<h3>ところで </h3>
<p>SYNOPSYSにあるinsertとかupdateとかが失敗するのはボクの日頃の行いが悪いせいでしょうか？</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;"># Insert </span>
    <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Perl'</span><span style="color: #339933;">,</span> author <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Ken'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> table  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'book'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Update </span>
    <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">update</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Perl'</span><span style="color: #339933;">,</span> author <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Ken'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> table  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'book'</span><span style="color: #339933;">,</span>
      where  <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>id <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div></div>


<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;"># Insert </span>
    <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">insert</span><span style="color: #009900;">&#40;</span> param <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>title <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Perl'</span><span style="color: #339933;">,</span> author <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Ken'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> table  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'book'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Update </span>
    <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">update</span><span style="color: #009900;">&#40;</span> param <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>title <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Perl'</span><span style="color: #339933;">,</span> author <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Ken'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> table  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'book'</span><span style="color: #339933;">,</span>
      where  <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>id <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div></div>

<p>だと性交いや、成功するのですが。<br />
param が必要？？（だからソース嫁！）</p>
<p>追記：DBIx::Customのバージョンが 0.168 だったからのようです&#8230;APIが追加された模様。</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/07/29/dbixcustom%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e9%96%a2%e6%95%b0%ef%bc%88mysql%e3%81%aeadddate%e3%81%a8%e3%81%8bsubdate%e3%81%a8%e3%81%8b%ef%bc%89%e3%82%92/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/07/29/dbixcustom%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e9%96%a2%e6%95%b0%ef%bc%88mysql%e3%81%aeadddate%e3%81%a8%e3%81%8bsubdate%e3%81%a8%e3%81%8b%ef%bc%89%e3%82%92/" />
	</item>
		<item>
		<title>perl SpeedyCGIでデータベースの接続を永続化する</title>
		<link>http://perl.no-tubo.net/2011/04/01/perl-speedycgi%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e6%8e%a5%e7%b6%9a%e3%82%92%e6%b0%b8%e7%b6%9a%e5%8c%96%e3%81%99%e3%82%8b/</link>
		<comments>http://perl.no-tubo.net/2011/04/01/perl-speedycgi%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e6%8e%a5%e7%b6%9a%e3%82%92%e6%b0%b8%e7%b6%9a%e5%8c%96%e3%81%99%e3%82%8b/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 07:36:53 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[DBI]]></category>
		<category><![CDATA[speedyCGI]]></category>
		<category><![CDATA[データベース]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=1555</guid>
		<description><![CDATA[perlスクリプトをSpeedyCGIスクリプトとして動作させる場合、グローバル変数の値は保持され続ける。なので、一度接続したデータベースハンドルを使い回すことでデータベースへの接続コストを削減できる。
テスト用スクリプ [...]]]></description>
			<content:encoded><![CDATA[<p>perlスクリプトをSpeedyCGIスクリプトとして動作させる場合、グローバル変数の値は保持され続ける。なので、一度接続したデータベースハンドルを使い回すことでデータベースへの接続コストを削減できる。</p>
<p>テスト用スクリプト<span id="more-1555"></span></p>
<pre>#!/usr/bin/speedy

use strict;
use warnings;
use DBI;

<span style="color: #ff9900;">#DB用設定</span>
my $db_user = 'db_user_name';
my $db_pass = 'db_password';
my $db_name = 'db_name';
my $db_host = 'localhost';
my $dbi = "DBI:mysql:$db_name:$db_host";

<span style="color: #ff9900;"># テスト用</span>
print "content-type:text/html;\n\n";
our $c;
$c=1 if !$c;
print "($c回目)\n";
$c++;

our $dbh;    <span style="color: #ff9900;"># データベースハンドルは our でグローバル変数を宣言する必要がある。</span>
my  $db_connect_flag;

<span style="color: #ff9900;"># $dbhがある場合データベースハンドルが有効かチェック</span>
eval{
    $db_connect_flag = $dbh-&gt;ping;
    print "DB check.\n";  <span style="color: #ff9900;"># ２回目以降はチェック(テスト用)</span>
} if defined($dbh);

<span style="color: #ff9900;"># 未接続ならDBに接続する</span>
if(!$db_connect_flag){
    eval {
        $dbh = DBI-&gt;connect($dbi, $db_user, $db_pass)|| die $dbh-&gt;errstr;
    };
    <span style="color: #ff9900;"># 接続エラーならエラー処理</span>
    error("DB could not connect.")  if $@;
    print "DB conect OK.\n";   <span style="color: #ff9900;"># 初回は接続(テスト用)</span>
}
exit;</pre>
<p>ポイントとしては our $dbh; としてグローバル変数宣言する事。my でレキシカル変数を宣言してしまうと毎回初期化されてしまう。</p>
<p>defined で $dbh が定義済みか調べて、定義済みなら ping を送って有効か調べる。無効ならデータベースへ接続する。</p>
<p>必要な部分はこんな感じ。</p>
<pre>our $dbh;
my  $db_connect_flag;

<span style="color: #ff9900;"># $dbhがある場合データベースハンドルが有効かチェック</span>
eval{ $db_connect_flag = $dbh-&gt;ping; } if defined($dbh);

<span style="color: #ff9900;"># 未接続ならDBに接続する</span>
if(!$db_connect_flag){
    eval {
        $dbh = DBI-&gt;connect($dbi, $db_user, $db_pass) || die $dbh-&gt;errstr;
    };
    <span style="color: #ff9900;"># 接続エラーならエラー処理</span>
    error("DB could not connect.")  if $@;
}</pre>
<p>あくまでSpeedyCGIでのスクリプトで、FastCGIの場合とかは違うかも。</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/04/01/perl-speedycgi%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e6%8e%a5%e7%b6%9a%e3%82%92%e6%b0%b8%e7%b6%9a%e5%8c%96%e3%81%99%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/04/01/perl-speedycgi%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e6%8e%a5%e7%b6%9a%e3%82%92%e6%b0%b8%e7%b6%9a%e5%8c%96%e3%81%99%e3%82%8b/" />
	</item>
		<item>
		<title>MySQL で年月日等の日付別に集計する</title>
		<link>http://perl.no-tubo.net/2010/06/04/mysql-%e3%81%a7%e5%b9%b4%e6%9c%88%e6%97%a5%e7%ad%89%e3%81%ae%e6%97%a5%e4%bb%98%e5%88%a5%e3%81%ab%e9%9b%86%e8%a8%88%e3%81%99%e3%82%8b/</link>
		<comments>http://perl.no-tubo.net/2010/06/04/mysql-%e3%81%a7%e5%b9%b4%e6%9c%88%e6%97%a5%e7%ad%89%e3%81%ae%e6%97%a5%e4%bb%98%e5%88%a5%e3%81%ab%e9%9b%86%e8%a8%88%e3%81%99%e3%82%8b/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 11:21:40 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=535</guid>
		<description><![CDATA[いまさら月次集計や年毎の集計など


集計をする際は、主にGROUP BYを多く用いる。
YEAR(), MONTH(), DAY(), DAYNAME(), EXTRACT()が便利。


WHERE で条件しぼるんじ [...]]]></description>
			<content:encoded><![CDATA[<p>いまさら月次集計や年毎の集計など</p>
<ul>
<blockquote>
<li>集計をする際は、主にGROUP BYを多く用いる。</li>
<li>YEAR(), MONTH(), DAY(), DAYNAME(), EXTRACT()が便利。</li>
</blockquote>
</ul>
<p>WHERE で条件しぼるんじゃないらしい（ｦｲ）</p>
<p>2010-05 2010-06 等で年月別の集計なら、</p>
<pre>SELECT EXTRACT(YEAR_MONTH FROM `datetime`) as 'year_month' ,
SUM(`price`) as price
FROM `hoge_table`
GROUP BY EXTRACT(YEAR_MONTH FROM `datetime `);</pre>
<p>とか。（参照ページの例文に間違い有り as が抜けているのと エイリアスとして year_month と言う文字列を指定する場合はクォートで囲まないとエラーになる）</p>
<pre>year_month	price
200811	34259
200812	49258
200901	67447</pre>
<p>結果はこんな感じになる。</p>
<p>参照：<a href="http://www.flatz.jp/archives/75">MySQLの知っていると便利な構文（その2）</a></p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2010/06/04/mysql-%e3%81%a7%e5%b9%b4%e6%9c%88%e6%97%a5%e7%ad%89%e3%81%ae%e6%97%a5%e4%bb%98%e5%88%a5%e3%81%ab%e9%9b%86%e8%a8%88%e3%81%99%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2010/06/04/mysql-%e3%81%a7%e5%b9%b4%e6%9c%88%e6%97%a5%e7%ad%89%e3%81%ae%e6%97%a5%e4%bb%98%e5%88%a5%e3%81%ab%e9%9b%86%e8%a8%88%e3%81%99%e3%82%8b/" />
	</item>
		<item>
		<title>MySQLのINT等の整数型カラム(UNSIGNED)から減算する時に注意</title>
		<link>http://perl.no-tubo.net/2009/10/29/mysql%e3%81%aeint%e7%ad%89%e3%81%ae%e6%95%b4%e6%95%b0%e5%9e%8b%e3%82%ab%e3%83%a9%e3%83%a0unsigned%e3%81%8b%e3%82%89%e6%b8%9b%e7%ae%97%e3%81%99%e3%82%8b%e6%99%82%e3%81%ab%e6%b3%a8%e6%84%8f/</link>
		<comments>http://perl.no-tubo.net/2009/10/29/mysql%e3%81%aeint%e7%ad%89%e3%81%ae%e6%95%b4%e6%95%b0%e5%9e%8b%e3%82%ab%e3%83%a9%e3%83%a0unsigned%e3%81%8b%e3%82%89%e6%b8%9b%e7%ae%97%e3%81%99%e3%82%8b%e6%99%82%e3%81%ab%e6%b3%a8%e6%84%8f/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 10:53:17 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=275</guid>
		<description><![CDATA[MySQL4.xでは大丈夫だったけど、MySQL5.xに移行してから起こった出来事。
整数型カラムをUNSIGNEDして利用している時、負の数にならないのをいい事に0から減算して負の数の場合は0と自動で処理してくるものだ [...]]]></description>
			<content:encoded><![CDATA[<h4>MySQL4.xでは大丈夫だったけど、MySQL5.xに移行してから起こった出来事。</h4>
<p>整数型カラムをUNSIGNEDして利用している時、負の数にならないのをいい事に0から減算して負の数の場合は0と自動で処理してくるものだと思っていた。（MySQL4.x時にはそのように処理されていた。）</p>
<p>本当はプログラム側で処理するべきなのかもしれないけれど、楽してそのようなスクリプトを書いていた。</p>
<p>で、先日MySQL5.xの環境に移行したらデータがおかしくなっていた。</p>
<p>とてつもなく大きな数字となっており？？？状態。</p>
<p>どうやら、UNSIGNEDしているカラムが0で、そこから1を引くと4294967295のような値になってしまうようだ。</p>
<p>これを回避するにはコマンドラインオプションで</p>
<blockquote><p>&#8211;sql-mode=NO_UNSIGNED_SUBTRACTION</p></blockquote>
<p>とするか、SQL発行時に</p>
<blockquote><p>SET SQL_MODE=&#8217;NO_UNSIGNED_SUBTRACTION&#8217;;</p></blockquote>
<p>とすると大丈夫のようだ。</p>
<p>参考： <a href="http://mlog.euqset.org/archives/ml@mysql.gr.jp/14844.html">http://mlog.euqset.org/archives/ml@mysql.gr.jp/14844.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2009/10/29/mysql%e3%81%aeint%e7%ad%89%e3%81%ae%e6%95%b4%e6%95%b0%e5%9e%8b%e3%82%ab%e3%83%a9%e3%83%a0unsigned%e3%81%8b%e3%82%89%e6%b8%9b%e7%ae%97%e3%81%99%e3%82%8b%e6%99%82%e3%81%ab%e6%b3%a8%e6%84%8f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2009/10/29/mysql%e3%81%aeint%e7%ad%89%e3%81%ae%e6%95%b4%e6%95%b0%e5%9e%8b%e3%82%ab%e3%83%a9%e3%83%a0unsigned%e3%81%8b%e3%82%89%e6%b8%9b%e7%ae%97%e3%81%99%e3%82%8b%e6%99%82%e3%81%ab%e6%b3%a8%e6%84%8f/" />
	</item>
		<item>
		<title>CentOS5.3 PostfixをMySQL対応にする</title>
		<link>http://perl.no-tubo.net/2009/10/02/centos5-3-postfix%e3%82%92mysql%e5%af%be%e5%bf%9c%e3%81%ab%e3%81%99%e3%82%8b/</link>
		<comments>http://perl.no-tubo.net/2009/10/02/centos5-3-postfix%e3%82%92mysql%e5%af%be%e5%bf%9c%e3%81%ab%e3%81%99%e3%82%8b/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 09:40:04 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[CentOS5.x]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[メールサーバ]]></category>

		<guid isPermaLink="false">http://pet.no-tubo.net/?p=182</guid>
		<description><![CDATA[2010-12-04追記
どうやらCentOS5.5ではRPMが用意されている模様
64bit http://ftp.riken.jp/Linux/centos/5.5/centosplus/x86_64/RPMS/po [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>2010-12-04追記<br />
どうやらCentOS5.5ではRPMが用意されている模様<br />
64bit http://ftp.riken.jp/Linux/centos/5.5/centosplus/x86_64/RPMS/postfix-2.3.3-2.1.centos.mysql_pgsql.x86_64.rpm<br />
32bit http://ftp.riken.jp/Linux/centos/5.5/centosplus/i386/RPMS/postfix-2.3.3-2.1.centos.mysql_pgsql.i386.rpm<br />
あれ？前からあったのか？？</p></blockquote>
<p>yumでインストールされていたらアンインストール</p>
<pre>yum erase postfix</pre>
<h3>ダウンロード</h3>
<p><a href="http://ftp.riken.jp/Linux/centos/">最新版の確認</a>（/5.x/centosplus/SRPMS/より）</p>
<pre>rpm -ivh http://ftp.riken.jp/Linux/centos/5.4/centosplus/SRPMS/postfix-2.3.3-2.1.centos.mysql_pgsql.src.rpm</pre>
<h3>コンパイル前の下準備</h3>
<p>Postfix をMySQL対応にするためpostfix.specを編集。</p>
<pre>cd /usr/src/redhat/SPECS/
vi postfix.spec
..
%define MYSQL 1　<span style="color: #ff9900;">←確認（0なら1に修正）</span>
%define PGSQL 0　<span style="color: #ff9900;">←postgreSQLを使わないなら1から0に修正</span>
..</pre>
<h3>コンパイル</h3>
<p>srpmからrpmを作成する。</p>
<blockquote><p>エラー: ビルド依存性の失敗:<br />
pcre-devel は postfix-2.3.3-2.1.centos.mysql_pgsql.i386 に必要とされています</p></blockquote>
<p>などのエラーが出たら<br />
yum install pcre-devel<br />
でインストール後に再度実行。</p>
<pre>rpmbuild -bb postfix.spec</pre>
<h3>インストール</h3>
<p>出来上がったRPMをインストールする。</p>
<pre>cd /usr/src/redhat/RPMS/i386/
rpm -ivh postfix-2.3.3-2.1.centos.mysql_pgsql.i386.rpm</pre>
<h3>yumの自動アップデートから外す</h3>
<p>yum update で postfix* なパッケージがアップデートされなくなる。</p>
<p>これをしないとyumの自動アップデート時にMySQL非対応に戻ってしまう。</p>
<pre>vi /etc/yum.conf
exclude=postfix*　<span style="color: #ff9900;">←最終業に追記</span></pre>
<p>↑手動でもやりましたけど<br />
<a href="http://perl.no-tubo.net/2010/03/08/postfixをyumでアップデートしてしまった-orz/">Postfixをyumでアップデートしてしまった orz&#8230;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2009/10/02/centos5-3-postfix%e3%82%92mysql%e5%af%be%e5%bf%9c%e3%81%ab%e3%81%99%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2009/10/02/centos5-3-postfix%e3%82%92mysql%e5%af%be%e5%bf%9c%e3%81%ab%e3%81%99%e3%82%8b/" />
	</item>
		<item>
		<title>MySQL DATETIME型へのINDEX注意点</title>
		<link>http://perl.no-tubo.net/2009/05/18/mysql-datetime%e5%9e%8b%e3%81%b8%e3%81%aeindex%e6%b3%a8%e6%84%8f%e7%82%b9/</link>
		<comments>http://perl.no-tubo.net/2009/05/18/mysql-datetime%e5%9e%8b%e3%81%b8%e3%81%aeindex%e6%b3%a8%e6%84%8f%e7%82%b9/#comments</comments>
		<pubDate>Mon, 18 May 2009 08:15:34 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://pet.no-tubo.net/?p=126</guid>
		<description><![CDATA[MySQLのDATETIME型へインデックスをつける場合注意が必要。
例えばこんなSQLではインデックスが使用されない。
SELECT * FROM  `table` WHERE  `datetime` LIKE  '2 [...]]]></description>
			<content:encoded><![CDATA[<p>MySQLのDATETIME型へインデックスをつける場合注意が必要。<br />
例えばこんなSQLではインデックスが使用されない。</p>
<pre>SELECT * FROM  `table` WHERE  `datetime` LIKE  '2009-05-17%'</pre >
検索結果は2009-05-17分全てが抽出されるが、フルスキャンがかかる。
この場合、以下のようなSQLが良い。
<pre>SELECT * FROM  `table`
WHERE  `date_time` BETWEEN '2009-05-17' AND '2009-05-17' + INTERVAL 1 DAY</pre>
<p>実行時間計測の例<br />
行数：13,776行<br />
データ：2,935KB<br />
インデックス：datetime</p>
<hr />
<pre>SELECT SUM(  `col` ) FROM  `table`
WHERE  `datetime` LIKE  '2009-05-17%'</pre>
<p>フルスキャン<br />
実行時間：0.0235 秒</p>
<hr />
<pre>SELECT SUM(  `col` ) FROM  `table`
WHERE  DATE(datetime) =  '2009-05-17'</pre>
<p>フルスキャン<br />
実行時間：0.0383 秒</p>
<hr />
<pre>SELECT SUM(  `col` ) FROM  `table`
WHERE `date_time` BETWEEN  '2009-05-17' AND  '2009-05-17' + INTERVAL 1 DAY</pre>
<p>インデックス使用<br />
実行時間：0.0009 秒</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2009/05/18/mysql-datetime%e5%9e%8b%e3%81%b8%e3%81%aeindex%e6%b3%a8%e6%84%8f%e7%82%b9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2009/05/18/mysql-datetime%e5%9e%8b%e3%81%b8%e3%81%aeindex%e6%b3%a8%e6%84%8f%e7%82%b9/" />
	</item>
		<item>
		<title>DBIでMysql を使う時の文字コード指定</title>
		<link>http://perl.no-tubo.net/2009/04/11/dbi%e3%81%a7mysql-%e3%82%92%e4%bd%bf%e3%81%86%e6%99%82%e3%81%ae%e6%96%87%e5%ad%97%e3%82%b3%e3%83%bc%e3%83%89%e6%8c%87%e5%ae%9a/</link>
		<comments>http://perl.no-tubo.net/2009/04/11/dbi%e3%81%a7mysql-%e3%82%92%e4%bd%bf%e3%81%86%e6%99%82%e3%81%ae%e6%96%87%e5%ad%97%e3%82%b3%e3%83%bc%e3%83%89%e6%8c%87%e5%ae%9a/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 08:23:18 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[DBI]]></category>

		<guid isPermaLink="false">http://pet.no-tubo.net/?p=132</guid>
		<description><![CDATA[接続時

my $dbh = DBI-&#62;connect(&#8216;DBI:mysql:database=sandbox;host=localhost;mysql_read_default_file=/etc/m [...]]]></description>
			<content:encoded><![CDATA[<p style="margin-top: 10px; margin-right: 12px; margin-bottom: 10px; margin-left: 12px; font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #444444; line-height: 1.4; padding: 0px;">接続時</p>
<blockquote>
<p style="margin-top: 10px; margin-right: 12px; margin-bottom: 10px; margin-left: 12px; font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #444444; line-height: 1.4; padding: 0px;">my $dbh = DBI-&gt;connect(<br style="font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #111111; padding: 0px; margin: 0px;" />&#8216;DBI:mysql:database=sandbox;host=localhost;mysql_read_default_file=/etc/mysql/my.cnf&#8217;,<br style="font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #111111; padding: 0px; margin: 0px;" />qw/id password/,<br style="font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #111111; padding: 0px; margin: 0px;" />);</p>
</blockquote>
<p style="margin-top: 10px; margin-right: 12px; margin-bottom: 10px; margin-left: 12px; font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #444444; line-height: 1.4; padding: 0px;">または接続後に<br style="font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #111111; padding: 0px; margin: 0px;" /></p>
<blockquote>
<p style="margin-top: 10px; margin-right: 12px; margin-bottom: 10px; margin-left: 12px; font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #444444; line-height: 1.4; padding: 0px;">$dbh-&gt;{ mysql_enable_utf8 } = 1;</p>
</blockquote>
<p style="margin-top: 10px; margin-right: 12px; margin-bottom: 10px; margin-left: 12px; font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #444444; line-height: 1.4; padding: 0px;"><br style="font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #111111; padding: 0px; margin: 0px;" />この辺の記事<br style="font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #111111; padding: 0px; margin: 0px;" /><a style="font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #333333; text-decoration: underline; padding: 0px; margin: 0px;" href="http://www.geminium.com/chiba_blog/2009/02/" target="_blank">http://www.geminium.com/chiba_blog/2009/02/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2009/04/11/dbi%e3%81%a7mysql-%e3%82%92%e4%bd%bf%e3%81%86%e6%99%82%e3%81%ae%e6%96%87%e5%ad%97%e3%82%b3%e3%83%bc%e3%83%89%e6%8c%87%e5%ae%9a/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2009/04/11/dbi%e3%81%a7mysql-%e3%82%92%e4%bd%bf%e3%81%86%e6%99%82%e3%81%ae%e6%96%87%e5%ad%97%e3%82%b3%e3%83%bc%e3%83%89%e6%8c%87%e5%ae%9a/" />
	</item>
		<item>
		<title>PhpMyAdminの導入</title>
		<link>http://perl.no-tubo.net/2009/02/17/phpmyadmin%e3%81%ae%e5%b0%8e%e5%85%a5/</link>
		<comments>http://perl.no-tubo.net/2009/02/17/phpmyadmin%e3%81%ae%e5%b0%8e%e5%85%a5/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 07:53:13 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[phpmyadmin]]></category>

		<guid isPermaLink="false">http://pet.no-tubo.net/?p=112</guid>
		<description><![CDATA[phpmyadminインストール
yum install phpmyadmin
/usr/share/phpmyadmin にインストールされる。
/usr/share/phpmyadmin/config.inc.php [...]]]></description>
			<content:encoded><![CDATA[<p>phpmyadminインストール</p>
<blockquote><p>yum install phpmyadmin</p></blockquote>
<p>/usr/share/phpmyadmin にインストールされる。<br />
/usr/share/phpmyadmin/config.inc.phpを編集<br />
$cfg['blowfish_secret']を設定。</p>
<blockquote><p>/*<br />
* This is needed for cookie based authentication to encrypt password in<br />
* cookie<br />
*/<br />
$cfg['blowfish_secret'] = &#8216;*************&#8217;; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */</p></blockquote>
<p>「mcrypt 拡張をロードできません。PHP の設定を確認してください」というエラーが出たのでインストール。</p>
<blockquote><p>yum -y install php-mbstring<br />
yum -y install php-mcrypt</p></blockquote>
<p>phpでマルチバイト処理をするには「php-mbstring」が必要.<br />
CentOS5だと上記でよいが、CentOS4だとインストールされない。</p>
<p>CentOS4での手順<br />
１．mcryptを組み込むのに必要なlibmcryptをrpmforgeからインストールします。</p>
<blockquote><p># yum -y &#8211;enablerepo=rpmforge install libmcrypt-devel</p></blockquote>
<p>２．php用のmcrypt拡張モジュールをPHPRPMsよりダウンロードします。</p>
<blockquote><p># cd /usr/src/redhat/RPMS/i386/<br />
# wget http://jaist.dl.sourceforge.net/sourceforge/phprpms/php-mcrypt-4.3.9-3.2.1.i386.rpm</p></blockquote>
<p>最新版は <a style="font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #ff6699; text-decoration: underline; padding: 0px; margin: 0px;" href="http://phprpms.sourceforge.net/mcrypt" target="_blank">http://phprpms.sourceforge.net/mcrypt</a> で確認して下さい。<br />
CentOSはRHEL互換なのでRHEL4の物を落としました。<br />
X86_64で無いならばi386で問題ありません。</p>
<p>３．ダウンロードしたrpmをインストールします。</p>
<blockquote><p># rpm -Uvh php-mcrypt-4.3.9-3.2.1.i386.rpm</p></blockquote>
<p>参考： <a style="font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #333333; text-decoration: underline; padding: 0px; margin: 0px;" href="http://centossrv.com/bbshtml/webpatio/364.shtml" target="_blank">http://centossrv.com/bbshtml/webpatio/364.shtml</a></p>
<p>・・・が、<a style="font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #333333; text-decoration: underline; padding: 0px; margin: 0px;" href="http://phprpms.sourceforge.net/mcrypt" target="_blank">http://phprpms.sourceforge.net/mcrypt</a>は現在無い&#8230;。<br />
しょうがないので、<a style="font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #ff6699; text-decoration: underline; padding: 0px; margin: 0px;" href="http://rpm.pbone.net/" target="_blank">http://rpm.pbone.net/</a>で探す。<br />
キーワード「php-mcrypt」CentOS 4 とRedHat EL 4 にチェックを入れサーチ。</p>
<blockquote><p># php -v</p></blockquote>
<p>でPHP 4.3.9dだったので、<br />
RedHat EL 4 ftp.sourceforge.net/pub/sourceforge/p/project/ph/phprpms/RHEL4 PHP RPMs/4.3.9-3.2/php-mcrypt-4.3.9-3.2.1.i386.rpm<br />
<a style="font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #333333; text-decoration: underline; padding: 0px; margin: 0px;" href="http://rpm.pbone.net/index.php3/stat/4/idpl/12753489/com/php-mcrypt-4.3.9-3.2.1.i386.rpm.html" target="_blank">http://rpm.pbone.net/index.php3/stat/4/idpl/12753489/com/php-mcrypt-4.3.9-3.2.1.i386.rpm.html</a></p>
<p>が、見つかったのでこれを使ってみる。</p>
<blockquote><p># wget ftp://ftp.pbone.net/mirror/ftp.sourceforge.net/pub/sourceforge/p/project/ph/phprpms/RHEL4%20PHP%20RPMs/4.3.9-3.2/php-mcrypt-4.3.9-3.2.1.i386.rpm</p>
<p>rpm -ivh php-mcrypt-4.3.9-3.2.1.i386.rpm</p></blockquote>
<p>成功した。</p>
<p>Apacheの設定。<br />
/etc/httpd/conf.d/phpmyadmin.conf が作成されるので適時修正。<br />
Apache再起動。</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2009/02/17/phpmyadmin%e3%81%ae%e5%b0%8e%e5%85%a5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2009/02/17/phpmyadmin%e3%81%ae%e5%b0%8e%e5%85%a5/" />
	</item>
		<item>
		<title>MySQL(Tritonn)を複数インストール</title>
		<link>http://perl.no-tubo.net/2009/02/17/mysqltritonn%e3%82%92%e8%a4%87%e6%95%b0%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab/</link>
		<comments>http://perl.no-tubo.net/2009/02/17/mysqltritonn%e3%82%92%e8%a4%87%e6%95%b0%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 07:50:53 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[サーバ管理]]></category>
		<category><![CDATA[Ttitonn]]></category>

		<guid isPermaLink="false">http://pet.no-tubo.net/?p=100</guid>
		<description><![CDATA[MySQL4.12が稼働しているサーバにMySQL5.0.67(Ttitonn)をインストールする（MySQL4.12はYUMでインストール済）
my.cnf (MySQL4.12)
[mysqld]
datadir=/ [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL4.12が稼働しているサーバにMySQL5.0.67(Ttitonn)をインストールする<br style="font-size: 13px; font-weight: normal; font-style: normal; font-family: Verdana, 'ヒラギノ角ゴ Pro W3', 'ＭＳ ゴシック', Osaka‐等幅; text-align: left; color: #111111; padding: 0px; margin: 0px;" />（MySQL4.12はYUMでインストール済）</p>
<p>my.cnf (MySQL4.12)</p>
<pre>[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid</pre>
<p>１）mecabのインストール</p>
<p><a href="?p=84">mecabのインストール</a></p>
<p>２）sennaのインストール</p>
<p><a href="?p=81">senna 1.1.4のインストール</a></p>
<p>３）インストールするのはTritonn（MySQL5.0.67）<br />
/usr/local/mysql5にインストールする<br />
※mecab sennaはインストール済み</p>
<blockquote><p>wget http://iij.dl.sourceforge.jp/tritonn/36449/tritonn-1.0.12-mysql-5.0.67.tar.gz<br />
tar xzf tritonn-1.0.12-mysql-5.0.67.tar.gz<br />
cd tritonn-1.0.12-mysql-5.0.67<br />
su&#8211;<br />
./configure &#8211;prefix=/usr/local/mysql5 &#8211;localstatedir=/usr/local/mysql5/data &#8211;with-unix-socket-path=/usr/local/mysql5/data/mysql5.sock &#8211;with-tcp-port=3307 &#8211;with-charset=utf8 &#8211;with-extra-charsets=all &#8211;with-mysqld-user=mysql &#8211;with-senna &#8211;with-mecab<br />
make<br />
mkdir /usr/local/mysql5<br />
make install<br />
cd /usr/local/mysql5<br />
mkdir /usr/local/mysql5/data<br />
chown -R mysql:mysql /usr/local/mysql5<br />
su mysql<br />
./bin/mysql_install_db &#8211;datadir=/usr/local/mysql5/data</p></blockquote>
<p>複数インストール<span style="text-decoration: underline;"><strong>しない</strong></span>場合のconfigureオプションはこんな感じ</p>
<blockquote><p>CC=&#8217;gcc&#8217;  CFLAGS=&#8217;-g&#8217;  CXX=&#8217;gcc&#8217;  CXXFLAGS=&#8217;-g&#8217;  LDFLAGS=&#8221;  ASFLAGS=&#8221; \<br />
./configure \<br />
&#8216;&#8211;prefix=/usr/local/mysql&#8217; \<br />
&#8216;&#8211;localstatedir=/usr/local/mysql/data&#8217; \<br />
&#8216;&#8211;libexecdir=/usr/local/mysql/bin&#8217; \<br />
&#8216;&#8211;with-comment=MySQL Community Server (GPL)&#8217; \<br />
&#8216;&#8211;with-server-suffix=&#8217; \<br />
&#8216;&#8211;enable-thread-safe-client&#8217; \<br />
&#8216;&#8211;enable-local-infile&#8217; \<br />
&#8216;&#8211;enable-assembler&#8217; \<br />
&#8216;&#8211;with-pic&#8217; \<br />
&#8216;&#8211;with-fast-mutexes&#8217; \<br />
&#8216;&#8211;with-client-ldflags=-static&#8217; \<br />
&#8216;&#8211;with-mysqld-ldflags=-static&#8217; \<br />
&#8216;&#8211;with-zlib-dir=bundled&#8217; \<br />
&#8216;&#8211;with-big-tables&#8217; \<br />
&#8216;&#8211;with-yassl&#8217; \<br />
&#8216;&#8211;with-readline&#8217; \<br />
&#8216;&#8211;with-archive-storage-engine&#8217; \<br />
&#8216;&#8211;with-blackhole-storage-engine&#8217; \<br />
&#8216;&#8211;with-ndbcluster&#8217; \<br />
&#8216;&#8211;with-csv-storage-engine&#8217; \<br />
&#8216;&#8211;with-example-storage-engine&#8217; \<br />
&#8216;&#8211;with-federated-storage-engine&#8217; \<br />
&#8216;&#8211;with-innodb&#8217; \<br />
&#8216;&#8211;with-charset=utf8&#8242; \<br />
&#8216;&#8211;with-extra-charsets=all&#8217; \<br />
&#8216;&#8211;with-senna&#8217; &#8216;&#8211;with-mecab&#8217;</p></blockquote>
<p>configure時に以下のエラーが出た時の対処</p>
<blockquote><p>checking for termcap functions library&#8230; configure: error: No curses/termcap library found</p></blockquote>
<p>curses/termcapのライブラリが無いらしい</p>
<blockquote><p>yum install ncurses-devel</p></blockquote>
<p>４）データベースの初期化</p>
<blockquote><p>/usr/local/mysql/bin/mysql_install_db &#8211;user=mysql</p></blockquote>
<p>５）初期ユーザー作成<br />
MySQL起動後に初期ユーザーrootでログイン。<br />
このrootはローカルから接続出来るユーザー。</p>
<p>初期ユーザーを全て削除し、新規ユーザーを作成する。</p>
<blockquote><p>./bin/mysqld_safe &#8211;defaults-file=/etc/my5.cnf &#8211;pid-file=/var/run/mysqld/mysqld5.pid &amp;<br />
/usr/local/mysql5/bin/mysql &#8211;user=root</p></blockquote>
<p>MySQLに接続後、既存ユーザー削除</p>
<blockquote><p>/usr/local/mysql5/bin/mysql &#8211;user=root<br />
mysql&gt; TRUNCATE TABLE mysql.user;</p>
<p>mysql&gt; FLUSH PRIVILEGES;</p></blockquote>
<p>管理ユーザー作成( 管理ユーザー：root パスワード：password)</p>
<blockquote><p>mysql&gt; GRANT ALL PRIVILEGES ON *.* TO &#8216;root&#8217;@'localhost&#8217; IDENTIFIED BY &#8216;password&#8217; WITH GRANT OPTION;</p></blockquote>
<p>補足：シンボリックリンクを貼って「mysql5」でアクセスする</p>
<blockquote><p>su &#8211;<br />
ln -s /usr/local/mysql5/bin/mysql /usr/bin/mysql5</p></blockquote>
<p>$ mysql5 &#8211;user=***** &#8211;password=************<br />
でアクセス可能。</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2009/02/17/mysqltritonn%e3%82%92%e8%a4%87%e6%95%b0%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2009/02/17/mysqltritonn%e3%82%92%e8%a4%87%e6%95%b0%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab/" />
	</item>
	</channel>
</rss>

