<?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/"
	>

<channel>
	<title>answersy.com Blog &#187; MySql</title>
	<atom:link href="http://answersy.com/zchen/index.php/category/it-related/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://answersy.com/zchen</link>
	<description>Got questions? Got answers!</description>
	<lastBuildDate>Thu, 20 Oct 2011 04:28:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to install 64-bit sqlplus and perl DBD::Oracle package on Mac OS X?</title>
		<link>http://answersy.com/zchen/2011/10/20/how-to-install-64-bit-sqlplus-and-perl-dbdoracle-package-on-mac-os-x/</link>
		<comments>http://answersy.com/zchen/2011/10/20/how-to-install-64-bit-sqlplus-and-perl-dbdoracle-package-on-mac-os-x/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 03:18:58 +0000</pubDate>
		<dc:creator>zchen</dc:creator>
				<category><![CDATA[IT Related]]></category>
		<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[MySql]]></category>

		<guid isPermaLink="false">http://answersy.com/zchen/?p=393</guid>
		<description><![CDATA[The Mac OS X version is 10.6.8. The Perl is installed at /usr/bin/perl, version (perl -version) is "v5.10.0 built for darwin-thread-multi-2level." There are two good articles on the web that discuss this issue, but none of them is perfect for me. So I tried to add my stuff here. The first is about installing sqlplus: [...]]]></description>
			<content:encoded><![CDATA[<p>The Mac OS X version is <strong>10.6.8</strong>.<br />
The Perl is installed at /usr/bin/perl, version (perl -version) is "<strong>v5.10.0 built for darwin-thread-multi-2level</strong>."</p>
<p>There are two good articles on the web that discuss this issue, but none of them is perfect for me. So I tried to add my stuff here.<br />
The first is about installing sqlplus: <a href="http://www.danilovizzarro.it/2008/07/how-to-install-sqlplus-and-the-oracle-client-v102-on-a-mac-os-x-leopard-1054/">http://www.danilovizzarro.it/2008/07/how-to-install-sqlplus-and-the-oracle-client-v102-on-a-mac-os-x-leopard-1054/</a><br />
The second is about installing DBD::Oracle: <a href="http://blacka.com/david/2008/11/12/how-to-install-dbdoracle-on-mac-os-x/">http://blacka.com/david/2008/11/12/how-to-install-dbdoracle-on-mac-os-x/</a></p>
<p><strong>To install sqlplus</strong>, you need download instantclient form <a href="http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html">oracle site</a>, the following (64-bit) packages:</p>
<li>Basic: <em>instantclient-basic-10.2.0.4.0-macosx-x64.zip</em></li>
<li>Sqlplus: <em>instantclient-sqlplus-10.2.0.4.0-macosx-x64.zip</em></li>
<p>To install DBD::Oracle, you need one more package:</p>
<li>SDK: <em>instantclient-sdk-10.2.0.4.0-macosx-x64.zip</em></li>
<p>Once you download and unzip them, all the files will go to a directory called <strong>instantclient_10_2</strong>. Move this folder to something like /opt/oracle</p>
<p><code><br />
$ sudo mv instantclient_10_2 /opt/oracle<br />
</code></p>
<p>You should set unix environment variable like the following:<br />
<code><br />
DYLD_LIBRARY_PATH="/opt/oracle/instantclient_10_2"<br />
export DYLD_LIBRARY_PATH<br />
TNS_ADMIN="/opt/oracle/tns"<br />
export TNS_ADMIN<br />
ORACLE_HOME="/opt/oracle/instantclient_10_2"<br />
export ORACLE_HOME<br />
</code></p>
<p>To connect to the an Oracle via sqlplus you can run the following command:<br />
<code><br />
# sqlplus DB_USER/DB_PASS@//DB_HOST:DB_PORT/DB_SID<br />
</code></p>
<p>To install <strong>DBD::Oracle</strong>, you will need to download perl <a href="http://search.cpan.org/dist/DBD-Oracle/">DBD package</a> from CPAN, I chose version 1.32.</p>
<p>After you download the package, unzip it to ~/Download/DBD-Oracle-1.32, make sure you have set ORACLE_HOME and DYLD_LIBRARY_PATH correctly.<br />
You need to set some soft link in $ORACLE_HOME (<span style="color: #ff0000;">This is the key step most readme files failed to mention.</span>)</p>
<p><code><br />
$ cd /opt/oracle/instantclient_10_2/<br />
$ sudo ln -s /opt/oracle/instantclient_10_2/ lib<br />
$ sudo ln -s libclntsh.dylib.10.1 libclntsh.dylib<br />
$ ls -l </code></p>
<p><code>lrwxr-xr-x   1 root  admin        31 Oct 19 16:36 lib -&gt; /opt/oracle/instantclient_10_2/<br />
lrwxr-xr-x   1 root  admin        20 Oct 19 16:32 libclntsh.dylib -&gt; libclntsh.dylib.10.1<br />
</code></p>
<p>Now you can compile the DBD::Oracle Package now:<br />
<code><br />
$ cd ~/Download/DBD-Oracle-1.32<br />
$ perl Makefile.PL<br />
$ make<br />
$ sudo make install<br />
</code></p>
<p>In perl script you connect to oracle server using the following code:<br />
<code><br />
#! /usr/bin/perl -w</p>
<p>use warnings;<br />
use strict;<br />
use Data::Dumper;<br />
use DBI;</p>
<p>my $sid = "host=host.xyz.com;sid=DBSID;port=1521"<br />
my $dbh = DBI->connect("dbi:Oracle:$sid", $user, $pass) or die "ERROR: failed to connect db: $@\n";<br />
</code></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fanswersy.com%2Fzchen%2F2011%2F10%2F20%2Fhow-to-install-64-bit-sqlplus-and-perl-dbdoracle-package-on-mac-os-x%2F';
  addthis_title  = 'How+to+install+64-bit+sqlplus+and+perl+DBD%3A%3AOracle+package+on+Mac+OS+X%3F';
  addthis_pub    = 'zchen050815';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://answersy.com/zchen/2011/10/20/how-to-install-64-bit-sqlplus-and-perl-dbdoracle-package-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to install Perl DBD, DBI::mysql Modules under Mac OS X?</title>
		<link>http://answersy.com/zchen/2011/10/12/how-to-install-perl-dbd-dbimysql-modules-under-mac-os-x/</link>
		<comments>http://answersy.com/zchen/2011/10/12/how-to-install-perl-dbd-dbimysql-modules-under-mac-os-x/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 04:04:26 +0000</pubDate>
		<dc:creator>zchen</dc:creator>
				<category><![CDATA[IT Related]]></category>
		<category><![CDATA[MySql]]></category>

		<guid isPermaLink="false">http://answersy.com/zchen/?p=385</guid>
		<description><![CDATA[Please refer to http://www.quicomm.com/apm_dbddbi.htm And you are likely see the following error: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle You need to set the following in your .profile or .bash_profile export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH see also http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/ addthis_url = 'http%3A%2F%2Fanswersy.com%2Fzchen%2F2011%2F10%2F12%2Fhow-to-install-perl-dbd-dbimysql-modules-under-mac-os-x%2F'; addthis_title = 'How+to+install+Perl+DBD%2C+DBI%3A%3Amysql+Modules+under+Mac+OS+X%3F'; addthis_pub = 'zchen050815';]]></description>
			<content:encoded><![CDATA[<p>Please refer to <a href="http://www.quicomm.com/apm_dbddbi.htm">http://www.quicomm.com/apm_dbddbi.htm</a></p>
<p>And you are likely see the following error: </p>
<blockquote><p>dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib<br />
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle<br />
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle</p></blockquote>
<p>You need to set the following in your .profile or .bash_profile </p>
<blockquote><p>export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
</p></blockquote>
<p>see also <a href="http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/">http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/</a></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fanswersy.com%2Fzchen%2F2011%2F10%2F12%2Fhow-to-install-perl-dbd-dbimysql-modules-under-mac-os-x%2F';
  addthis_title  = 'How+to+install+Perl+DBD%2C+DBI%3A%3Amysql+Modules+under+Mac+OS+X%3F';
  addthis_pub    = 'zchen050815';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://answersy.com/zchen/2011/10/12/how-to-install-perl-dbd-dbimysql-modules-under-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How do Mysql Handle Bit-wise  Operations?</title>
		<link>http://answersy.com/zchen/2007/10/24/how-do-mysql-handle-bit-wise-operations/</link>
		<comments>http://answersy.com/zchen/2007/10/24/how-do-mysql-handle-bit-wise-operations/#comments</comments>
		<pubDate>Wed, 24 Oct 2007 05:04:31 +0000</pubDate>
		<dc:creator>zchen</dc:creator>
				<category><![CDATA[IT Related]]></category>
		<category><![CDATA[MySql]]></category>

		<guid isPermaLink="false">http://answersy.com/zchen/2007/10/24/how-do-mysql-handle-bit-wise-operations/</guid>
		<description><![CDATA[See http://dev.mysql.com/doc/refman/4.1/en/bit-functions.html http://dev.mysql.com/doc/refman/5.0/en/bit-functions.html And the users' comments are very helpful! SELECT SUM&#40;IF&#40;rubrik &#38; 1, 1, 0&#41;&#41; actus, SUM&#40;IF&#40;rubrik &#38; 2, 1, 0&#41;&#41; shopping, SUM&#40;IF&#40;rubrik &#38; 4, 1, 0&#41;&#41; utils, SUM&#40;IF&#40;rubrik &#38; 8, 1, 0&#41;&#41; communication, SUM&#40;IF&#40;rubrik &#38; 16, 1, 0&#41;&#41; services, COUNT&#40;user_id&#41; AS total, FROM preferences p addthis_url = 'http%3A%2F%2Fanswersy.com%2Fzchen%2F2007%2F10%2F24%2Fhow-do-mysql-handle-bit-wise-operations%2F'; addthis_title = 'How+do+Mysql+Handle+Bit-wise++Operations%3F'; addthis_pub = [...]]]></description>
			<content:encoded><![CDATA[<p>See <a title="MySql 4.1" href="http://dev.mysql.com/doc/refman/4.1/en/bit-functions.html">http://dev.mysql.com/doc/refman/4.1/en/bit-functions.html</a></p>
<p><a title="MySql 5.0" href="http://dev.mysql.com/doc/refman/5.0/en/bit-functions.html">http://dev.mysql.com/doc/refman/5.0/en/bit-functions.html</a></p>
<p>And the users' comments are very helpful!</p>
<pre class="sql"><span style="color: #993333; font-weight: bold;">SELECT</span>
SUM<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>rubrik &amp; <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> actus,
SUM<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>rubrik &amp; <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> shopping,
SUM<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>rubrik &amp; <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> utils,
SUM<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>rubrik &amp; <span style="color: #cc66cc;">8</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> communication,
SUM<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>rubrik &amp; <span style="color: #cc66cc;">16</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> services,
COUNT<span style="color: #66cc66;">&#40;</span>user_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> total,
<span style="color: #993333; font-weight: bold;">FROM</span> preferences p</pre>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fanswersy.com%2Fzchen%2F2007%2F10%2F24%2Fhow-do-mysql-handle-bit-wise-operations%2F';
  addthis_title  = 'How+do+Mysql+Handle+Bit-wise++Operations%3F';
  addthis_pub    = 'zchen050815';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://answersy.com/zchen/2007/10/24/how-do-mysql-handle-bit-wise-operations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Aggregate Texts with GROUP_CONCAT in MySql?</title>
		<link>http://answersy.com/zchen/2007/10/05/how-to-aggregate-texts-with-group_concat-in-mysql/</link>
		<comments>http://answersy.com/zchen/2007/10/05/how-to-aggregate-texts-with-group_concat-in-mysql/#comments</comments>
		<pubDate>Fri, 05 Oct 2007 03:33:35 +0000</pubDate>
		<dc:creator>zchen</dc:creator>
				<category><![CDATA[IT Related]]></category>
		<category><![CDATA[MySql]]></category>

		<guid isPermaLink="false">http://answersy.com/zchen/2007/10/05/how-to-aggregate-texts-with-group_concat-in-mysql/</guid>
		<description><![CDATA[The official syntax can be found at http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat It is really cool! For example I have a table Tbl_Cmp_Grp_Srt_Txt with four columns Cmp, Grp, Srt, Txt Cmp has two different values "C1" and "C2", we want to group by Grp, sort by Srt and concat all the Txt's together and put the different groups side-by-side. [...]]]></description>
			<content:encoded><![CDATA[<p>The official syntax can be found at <a target="_blank" href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat">http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat</a></p>
<p>It is really cool!</p>
<p>For example I have a table Tbl_Cmp_Grp_Srt_Txt with four columns Cmp, Grp, Srt, Txt<br />
Cmp has two different values "C1" and "C2", we want to group by Grp, sort by Srt and concat all the Txt's together and put the different groups side-by-side. Here is how I did it.</p>
<pre class="sql"><span style="color: #993333; font-weight: bold;">SELECT</span> t1.Cmp, t1.Grp, t1.Txts, t2.Cmp, t2.Grp, t2.Txts
<span style="color: #993333; font-weight: bold;">FROM</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> Cmp, Grp, GROUP_CONCAT<span style="color: #66cc66;">&#40;</span>Txt <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> Srt separator <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\t</span>'</span><span style="color: #66cc66;">&#41;</span> Txts
<span style="color: #993333; font-weight: bold;">FROM</span> Tbl_Cmp_Grp_Srt_Txt
<span style="color: #993333; font-weight: bold;">WHERE</span> Cmp = <span style="color: #ff0000;">'C1'</span> <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> Grp<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> t1,
<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> Cmp, Grp, GROUP_CONCAT<span style="color: #66cc66;">&#40;</span>Txt <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> Srt separator <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\t</span>'</span><span style="color: #66cc66;">&#41;</span> Txts
<span style="color: #993333; font-weight: bold;">FROM</span> Tbl_Cmp_Grp_Srt_Txt
<span style="color: #993333; font-weight: bold;">WHERE</span> Cmp = <span style="color: #ff0000;">'C2'</span> <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> Grp<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> t1,
<span style="color: #993333; font-weight: bold;">WHERE</span> t1.Grp = t2.Grp
<span style="color: #993333; font-weight: bold;">AND</span> t1.Txts &lt;&gt; t2.Txts</pre>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fanswersy.com%2Fzchen%2F2007%2F10%2F05%2Fhow-to-aggregate-texts-with-group_concat-in-mysql%2F';
  addthis_title  = 'How+to+Aggregate+Texts+with+GROUP_CONCAT+in+MySql%3F';
  addthis_pub    = 'zchen050815';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://answersy.com/zchen/2007/10/05/how-to-aggregate-texts-with-group_concat-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Get URL Host with MySql?</title>
		<link>http://answersy.com/zchen/2007/09/30/how-to-get-url-host-with-mysql/</link>
		<comments>http://answersy.com/zchen/2007/09/30/how-to-get-url-host-with-mysql/#comments</comments>
		<pubDate>Sun, 30 Sep 2007 04:20:21 +0000</pubDate>
		<dc:creator>zchen</dc:creator>
				<category><![CDATA[IT Related]]></category>
		<category><![CDATA[MySql]]></category>

		<guid isPermaLink="false">http://answersy.com/zchen/2007/09/30/how-to-get-url-host-with-mysql/</guid>
		<description><![CDATA[REPLACE(url, str2, str1), replace all the "https://" with "http://" SUBSTRING_INDEX(xxx, '/', 3), get everything before the 3rd '/' REPLACE(yyyy, str1, ''), remove 'http://' DROP FUNCTION IF EXISTS getHostFromUrl; CREATE FUNCTION getHostFromUrl &#40;url text&#40;1024&#41;&#41; RETURNS CHAR&#40;255&#41; BEGIN DECLARE str1 varchar&#40;10&#41;; DECLARE str2 varchar&#40;10&#41;; SET str1='http://'; SET str2='https://'; RETURN REPLACE&#40;SUBSTRING_INDEX&#40;REPLACE&#40;url, str2, str1&#41;, '/', 3&#41;, str1, ''&#41;; END; [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li>REPLACE(url, str2, str1),  replace all the "https://" with "http://"</li>
<li>SUBSTRING_INDEX(xxx, '/', 3), get everything before the 3rd '/'</li>
<li>REPLACE(yyyy, str1, ''), remove 'http://'</li>
</ul>
<pre class="sql"><span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> getHostFromUrl;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> getHostFromUrl <span style="color: #66cc66;">&#40;</span>url text<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> RETURNS CHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
BEGIN
DECLARE str1 varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;
DECLARE str2 varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">SET</span> str1=<span style="color: #ff0000;">'http://'</span>;
<span style="color: #993333; font-weight: bold;">SET</span> str2=<span style="color: #ff0000;">'https://'</span>;
<span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>SUBSTRING_INDEX<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">REPLACE</span><span style="color: #66cc66;">&#40;</span>url, str2, str1<span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">'/'</span>, <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>, str1, <span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>;
END;</pre>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fanswersy.com%2Fzchen%2F2007%2F09%2F30%2Fhow-to-get-url-host-with-mysql%2F';
  addthis_title  = 'How+to+Get+URL+Host+with+MySql%3F';
  addthis_pub    = 'zchen050815';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://answersy.com/zchen/2007/09/30/how-to-get-url-host-with-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Get MD5 in Mysql?</title>
		<link>http://answersy.com/zchen/2007/09/29/how-to-get-md5-in-mysql/</link>
		<comments>http://answersy.com/zchen/2007/09/29/how-to-get-md5-in-mysql/#comments</comments>
		<pubDate>Sat, 29 Sep 2007 17:25:59 +0000</pubDate>
		<dc:creator>zchen</dc:creator>
				<category><![CDATA[IT Related]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[Random Thoughts]]></category>

		<guid isPermaLink="false">http://answersy.com/zchen/2007/09/29/how-to-get-md5-in-mysql/</guid>
		<description><![CDATA[See official Mysql Reference http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html#function_md5 mysql> SELECT MD5('testing'); addthis_url = 'http%3A%2F%2Fanswersy.com%2Fzchen%2F2007%2F09%2F29%2Fhow-to-get-md5-in-mysql%2F'; addthis_title = 'How+to+Get+MD5+in+Mysql%3F'; addthis_pub = 'zchen050815';]]></description>
			<content:encoded><![CDATA[<p>See official Mysql Reference <a href="http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html#function_md5">http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html#function_md5</a></p>
<p>mysql> <font color="brown">SELECT MD5('testing');</font></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fanswersy.com%2Fzchen%2F2007%2F09%2F29%2Fhow-to-get-md5-in-mysql%2F';
  addthis_title  = 'How+to+Get+MD5+in+Mysql%3F';
  addthis_pub    = 'zchen050815';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://answersy.com/zchen/2007/09/29/how-to-get-md5-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Install MySql 5.0+ on a Linux Box?</title>
		<link>http://answersy.com/zchen/2007/09/28/how-to-install-mysql-50-on-a-linux-box/</link>
		<comments>http://answersy.com/zchen/2007/09/28/how-to-install-mysql-50-on-a-linux-box/#comments</comments>
		<pubDate>Fri, 28 Sep 2007 04:47:19 +0000</pubDate>
		<dc:creator>zchen</dc:creator>
				<category><![CDATA[IT Related]]></category>
		<category><![CDATA[Linux/Unix]]></category>
		<category><![CDATA[MySql]]></category>

		<guid isPermaLink="false">http://answersy.com/zchen/2007/09/28/how-to-install-mysql-50-on-a-linux-box/</guid>
		<description><![CDATA[Step 1: Download the package You can find the official download Link at http://dev.mysql.com/downloads/ For MySql 5.0: http://dev.mysql.com/downloads/mysql/5.0.html#downloads Step 2: Install the Binary shell> /usr/sbin/groupadd mysql shell> /usr/sbin/useradd -g mysql mysql shell> cd /usr/local shell> gunzip < /PATH/TO/MYSQL-VERSION-OS.tar.gz &#124; tar xvf - shell> ln -s FULL-PATH-TO-MYSQL-VERSION-OS mysql shell> cd mysql shell> scripts/mysql_install_db --user=mysql shell> chown [...]]]></description>
			<content:encoded><![CDATA[<p style="font-weight: bold">Step 1: Download the package</p>
<ul>
<li>You can find the<strong> official download Link at</strong> <a target="_top" href="http://dev.mysql.com/downloads/">http://dev.mysql.com/downloads/</a></li>
<li>For <strong>MySql 5.0:</strong> <a target="_top" href="http://dev.mysql.com/downloads/mysql/5.0.html#downloads">http://dev.mysql.com/downloads/mysql/5.0.html#downloads</a></li>
</ul>
<p><span style="font-weight: bold">Step 2: Install the Binary</span><strong><span style="font-weight: normal" /></strong><br />
shell> <font style="color: brown">/usr/sbin/groupadd mysql</font><br />
shell> <font style="color: brown">/usr/sbin/useradd -g mysql mysql</font><br />
shell> <font style="color: brown">cd /usr/local</font><br />
shell> <font style="color: brown">gunzip < /PATH/TO/MYSQL-VERSION-OS.tar.gz | tar xvf -</font><br />
shell> <font style="color: brown">ln -s FULL-PATH-TO-MYSQL-VERSION-OS mysql</font><br />
shell> <font style="color: brown">cd mysql</font><br />
shell> <font style="color: brown">scripts/mysql_install_db --user=mysql</font><br />
shell> <font style="color: brown">chown -R root .</font><br />
shell> <font style="color: brown">chown -R mysql data</font><br />
shell> <font style="color: brown">chgrp -R mysql .</font><br />
shell> <font style="color: brown">bin/mysqld_safe --user=mysql & </font> # start mysql daemon</p>
<p><strong> Step 3: Post-installation</strong><br />
shell> <font style="color: brown">su mysql</font><br />
shell> <font style="color: brown">mysql/scripts/mysql_install_db</font></p>
<p>shell> <font style="color: brown">mysql -u root -p</font><br />
mysql> <font style="color: brown">use mysql</font><br />
mysql> <font style="color: brown">GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;</font><br />
mysql> <font style="color: brown">set PASSWORD FOR 'user'@'localhost'  = PASSWORD('password');</font><br />
mysql> <font style="color: brown">FLUSH PRIVILEGES;</font><br />
mysql> <font style="color: brown">select * from mysql.user;</font></p>
<p>mysql> <font style="color: brown">create database db_name;</font><br />
mysql> <font style="color: brown">SHOW DATABASES;</font><br />
mysql> <font style="color: brown">use db_name;</font><br />
mysql> <font style="color: brown">SHOWTABLES;</font></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fanswersy.com%2Fzchen%2F2007%2F09%2F28%2Fhow-to-install-mysql-50-on-a-linux-box%2F';
  addthis_title  = 'How+to+Install+MySql+5.0%2B+on+a+Linux+Box%3F';
  addthis_pub    = 'zchen050815';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://answersy.com/zchen/2007/09/28/how-to-install-mysql-50-on-a-linux-box/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How can IF and CASE in MySql Help?</title>
		<link>http://answersy.com/zchen/2007/09/21/how-can-if-and-case-in-mysql-help/</link>
		<comments>http://answersy.com/zchen/2007/09/21/how-can-if-and-case-in-mysql-help/#comments</comments>
		<pubDate>Fri, 21 Sep 2007 16:30:45 +0000</pubDate>
		<dc:creator>zchen</dc:creator>
				<category><![CDATA[IT Related]]></category>
		<category><![CDATA[MySql]]></category>

		<guid isPermaLink="false">http://answersy.com/zchen/2007/09/21/how-can-if-and-case-in-mysql-help/</guid>
		<description><![CDATA[You have a table, say Tbl_Facts (Id INT, Grade INT) What you want to do is to put number of rows for different values of Grade side by side. You can use IF function to do so if you know all the possible values of Grade SELECT SUM&#40;IF&#40;Grade = 1, 1, 0&#41;&#41; AS CntGrade1, SUM&#40;IF&#40;Grade [...]]]></description>
			<content:encoded><![CDATA[<p>You have a table, say <strong>Tbl_Facts (Id INT, Grade INT)</strong></p>
<p>What you want to do is to put number of rows for different values of Grade side by side.</p>
<p>You can use IF function to do so if you know all the possible values of Grade</p>
<pre class="sql"><span style="color: #993333; font-weight: bold;">SELECT</span>
SUM<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>Grade  = <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> CntGrade1,
SUM<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>Grade  = <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> CntGrade2,
SUM<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>Grade  = <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> CntGrade3,
SUM<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">IF</span><span style="color: #66cc66;">&#40;</span>Grade  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> CntOthers
<span style="color: #993333; font-weight: bold;">FROM</span> Tbl_Facts</pre>
<p>If you have a formula to calculate a score of your facts, say when Grade is 1, you get 10 points; when Grade is 2, you get 5, when Grade is 3 you get 0, otherwise you get -5. What is the total score of the rows in your table?</p>
<pre class="sql"><span style="color: #993333; font-weight: bold;">SELECT</span>
SUM<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>CASE Grade   WHEN <span style="color: #cc66cc;">1</span> THEN <span style="color: #cc66cc;">10</span> WHEN <span style="color: #cc66cc;">2</span> THEN <span style="color: #cc66cc;">5</span> WHEN <span style="color: #cc66cc;">3</span> THEN <span style="color: #cc66cc;">0</span> ELSE <span style="color: #cc66cc;">-5</span> END<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> Score,
<span style="color: #993333; font-weight: bold;">FROM</span> Tbl_Facts</pre>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fanswersy.com%2Fzchen%2F2007%2F09%2F21%2Fhow-can-if-and-case-in-mysql-help%2F';
  addthis_title  = 'How+can+IF+and+CASE+in+MySql+Help%3F';
  addthis_pub    = 'zchen050815';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://answersy.com/zchen/2007/09/21/how-can-if-and-case-in-mysql-help/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get MySql Rownum?</title>
		<link>http://answersy.com/zchen/2007/09/21/how-to-get-mysql-rownum/</link>
		<comments>http://answersy.com/zchen/2007/09/21/how-to-get-mysql-rownum/#comments</comments>
		<pubDate>Fri, 21 Sep 2007 03:01:50 +0000</pubDate>
		<dc:creator>zchen</dc:creator>
				<category><![CDATA[IT Related]]></category>
		<category><![CDATA[MySql]]></category>

		<guid isPermaLink="false">http://answersy.com/zchen/2007/09/21/how-to-get-mysql-rownum/</guid>
		<description><![CDATA[Although this is not very elegant, it works. SELECT @no:=@no+1 rownum, t.* FROM &#40;SELECT @no:=0&#41; r, table_name t addthis_url = 'http%3A%2F%2Fanswersy.com%2Fzchen%2F2007%2F09%2F21%2Fhow-to-get-mysql-rownum%2F'; addthis_title = 'How+to+get+MySql+Rownum%3F'; addthis_pub = 'zchen050815';]]></description>
			<content:encoded><![CDATA[<p>Although this is not very elegant, it works.</p>
<pre class="sql"><span style="color: #993333; font-weight: bold;">SELECT</span> @no:=@no<span style="color: #cc66cc;">+1</span> rownum, t.*
<span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> @no:=<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> r, table_name t</pre>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fanswersy.com%2Fzchen%2F2007%2F09%2F21%2Fhow-to-get-mysql-rownum%2F';
  addthis_title  = 'How+to+get+MySql+Rownum%3F';
  addthis_pub    = 'zchen050815';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://answersy.com/zchen/2007/09/21/how-to-get-mysql-rownum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.561 seconds -->

