<?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>kwatog &#38; co.&#187; MySQL</title>
	<atom:link href="http://kwatog.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://kwatog.com</link>
	<description>tech notes and general nonsense</description>
	<lastBuildDate>Tue, 31 Jan 2012 06:27:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MySQL Dump and Reload</title>
		<link>http://kwatog.com/blog/mysql/mysql-dump-reload/</link>
		<comments>http://kwatog.com/blog/mysql/mysql-dump-reload/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 16:21:26 +0000</pubDate>
		<dc:creator>kwatog</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[load]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=133</guid>
		<description><![CDATA[This one has been on my draft for more than a year already so I better fix it up and share. Besides, I find myself more and more googling my site to find my posts instead of searching via the WP admin. Without further ado, here it is.. MySQL Dump This command saves/backup your database [...]]]></description>
			<content:encoded><![CDATA[<p>This one has been on my draft for more than a year already so I better fix it up and share. Besides, I find myself more and more googling my site to find my posts instead of searching via the WP admin. Without further ado, here it is..<br />
<span id="more-133"></span><br />
<strong>MySQL Dump</strong><br />
This command saves/backup your database into a file. The simplest use of this is to backup the whole database.<br />
<code><br />
mysqldump -u&lt;db_user_id&gt; -p &lt;db_name&gt; &gt; &lt;path/filename.sql&gt;<br />
</code><br />
Of course, there&#8217;s a whole set of options that comes with it but I&#8217;ll not cover that for now.<br />
<code><br />
mysqldump -uroot -p wp_dbase &gt; /usr/kwatog/wpdb_20100813.sql<br />
</code><br />
Take note that you&#8217;ll be asked for password when you launch this command.</p>
<p><strong>Reload MySQL Backup to DB</strong><br />
In case you want to reload your backup, here&#8217;s the syntax for it.<br />
<code><br />
mysql -u&lt;dbuserid&gt; -p &lt;dbase_name&gt; &lt;  &lt;path/filename&gt;<br />
</code></p>
<p>Sample<br />
<code><br />
mysql -uroot -p wp_dbase &lt; /usr/kwatog/wpdb_20100813.sql<br />
</code></p>
<p>Again, it&#8217;s so easy, no? </p>
<h4>Incoming search terms:</h4><ul><li>mysql dump reload</li><li>mysqldump reload</li><li>mysql reload</li><li>dump reload mysql</li><li>mysql dump and reload</li><li>nginx mysqldump 502 bad gateway</li><li>reload mysql</li><li>reload mysql dump</li><li>reload mysqldump</li><li>mysqldump and</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/mysql/mysql-dump-reload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Date Functions in MySQL</title>
		<link>http://kwatog.com/blog/date-function-in-mysql/</link>
		<comments>http://kwatog.com/blog/date-function-in-mysql/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 01:23:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[add_months]]></category>
		<category><![CDATA[date_add]]></category>
		<category><![CDATA[months_between]]></category>
		<category><![CDATA[Oracle]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=382</guid>
		<description><![CDATA[Here&#8217;s few of the usual equivalent Oracle data functions in MySQL. DATE ADD (SYSDATE +/-1) SELECT DATE_ADD(SYSDATE(),INTERVAL 1 DAY); SELECT DATE_ADD(SYSDATE(),INTERVAL -10 DAY); ADD_MONTHS SELECT DATE_ADD(SYSDATE(),INTERVAL 1 MONTH); TRUNC() SELECT DATE(SYSDATE()); TO_DATE() SELECT STR_TO_DATE( '07-08-2010', '%d-%m-%Y' ); TIME DIFFERENCE SELECT TIMESTAMPDIFF( SECOND , '2010-01-07 23:50:59', SYSDATE( ) ) /3600 /24 day, TIMESTAMPDIFF( SECOND , '2010-01-07 [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s few of the usual equivalent Oracle data functions in MySQL.</p>
<p><strong>DATE ADD (SYSDATE +/-1)</strong><br />
<code><br />
SELECT DATE_ADD(SYSDATE(),INTERVAL 1 DAY);<br />
SELECT DATE_ADD(SYSDATE(),INTERVAL -10 DAY);<br />
</code><br />
<span id="more-382"></span><br />
<strong>ADD_MONTHS</strong><br />
<code><br />
SELECT DATE_ADD(SYSDATE(),INTERVAL 1 MONTH);<br />
</code></p>
<p><strong>TRUNC()</strong><br />
<code><br />
SELECT DATE(SYSDATE());<br />
</code></p>
<p><strong>TO_DATE()</strong><br />
<code><br />
SELECT STR_TO_DATE( '07-08-2010', '%d-%m-%Y' );</code></p>
<p><strong>TIME DIFFERENCE</strong><br />
<code><br />
SELECT TIMESTAMPDIFF(<br />
SECOND , '2010-01-07 23:50:59', SYSDATE( ) ) /3600 /24 day,<br />
TIMESTAMPDIFF(<br />
SECOND , '2010-01-07 23:50:59', SYSDATE( ) )  /3600 hours,<br />
TIMESTAMPDIFF(<br />
SECOND , '2010-01-07 23:50:59', SYSDATE( ) )  /60 mins,<br />
TIMESTAMPDIFF(<br />
SECOND , '2010-01-07 23:50:59', SYSDATE( ) )  secs,<br />
</code><br />
In the preceding example, I could have just used HOUR, MINUTE, DAY, MONTH or YEAR interval but in real world, I mostly use SECOND for a more accurate results. That&#8217;s not to say timestampdiff is not accurate. Maybe because I&#8217;m used in how I do it in Oracle. </p>
<p><strong>MONTHS_BETWEEN</strong><br />
<code><br />
SELECT TIMESTAMPDIFF(<br />
MONTH , '2010-01-07', SYSDATE( ) )  no_months<br />
</code></p>
<table>
<tr>
<td><strong>Specifier</strong></td>
<td><strong>Description</strong></td>
</tr>
<tr>
<td><code>%a</code></td>
<td>Abbreviated weekday name                   (<code>Sun</code>..<code>Sat</code>)</td>
</tr>
<tr>
<td><code>%b</code></td>
<td>Abbreviated month name (<code>Jan</code>..<code>Dec</code>)</td>
</tr>
<tr>
<td><code>%c</code></td>
<td>Month, numeric (<code>0</code>..<code>12</code>)</td>
</tr>
<tr>
<td><code>%D</code></td>
<td>Day of the month with English suffix (<code>0th</code>,                   <code>1st</code>, <code>2nd</code>,                   <code>3rd</code>, …)</td>
</tr>
<tr>
<td><code>%d</code></td>
<td>Day of the month, numeric (<code>00</code>..<code>31</code>)</td>
</tr>
<tr>
<td><code>%e</code></td>
<td>Day of the month, numeric (<code>0</code>..<code>31</code>)</td>
</tr>
<tr>
<td><code>%f</code></td>
<td>Microseconds (<code>000000</code>..<code>999999</code>)</td>
</tr>
<tr>
<td><code>%H</code></td>
<td>Hour (<code>00</code>..<code>23</code>)</td>
</tr>
<tr>
<td><code>%h</code></td>
<td>Hour (<code>01</code>..<code>12</code>)</td>
</tr>
<tr>
<td><code>%I</code></td>
<td>Hour (<code>01</code>..<code>12</code>)</td>
</tr>
<tr>
<td><code>%i</code></td>
<td>Minutes, numeric (<code>00</code>..<code>59</code>)</td>
</tr>
<tr>
<td><code>%j</code></td>
<td>Day of year (<code>001</code>..<code>366</code>)</td>
</tr>
<tr>
<td><code>%k</code></td>
<td>Hour (<code>0</code>..<code>23</code>)</td>
</tr>
<tr>
<td><code>%l</code></td>
<td>Hour (<code>1</code>..<code>12</code>)</td>
</tr>
<tr>
<td><code>%M</code></td>
<td>Month name (<code>January</code>..<code>December</code>)</td>
</tr>
<tr>
<td><code>%m</code></td>
<td>Month, numeric (<code>00</code>..<code>12</code>)</td>
</tr>
<tr>
<td><code>%p</code></td>
<td><code>AM</code> or <code>PM</code></td>
</tr>
<tr>
<td><code>%r</code></td>
<td>Time, 12-hour (<code>hh:mm:ss</code> followed by                   <code>AM</code> or <code>PM</code>)</td>
</tr>
<tr>
<td><code>%S</code></td>
<td>Seconds (<code>00</code>..<code>59</code>)</td>
</tr>
<tr>
<td><code>%s</code></td>
<td>Seconds (<code>00</code>..<code>59</code>)</td>
</tr>
<tr>
<td><code>%T</code></td>
<td>Time, 24-hour (<code>hh:mm:ss</code>)</td>
</tr>
<tr>
<td><code>%U</code></td>
<td>Week (<code>00</code>..<code>53</code>), where Sunday is the                   first day of the week</td>
</tr>
<tr>
<td><code>%u</code></td>
<td>Week (<code>00</code>..<code>53</code>), where Monday is the                   first day of the week</td>
</tr>
<tr>
<td><code>%V</code></td>
<td>Week (<code>01</code>..<code>53</code>), where Sunday is the                   first day of the week; used with <code>%X</code></td>
</tr>
<tr>
<td><code>%v</code></td>
<td>Week (<code>01</code>..<code>53</code>), where Monday is the                   first day of the week; used with <code>%x</code></td>
</tr>
<tr>
<td><code>%W</code></td>
<td>Weekday name (<code>Sunday</code>..<code>Saturday</code>)</td>
</tr>
<tr>
<td><code>%w</code></td>
<td>Day of the week                   (<code>0</code>=Sunday..<code>6</code>=Saturday)</td>
</tr>
<tr>
<td><code>%X</code></td>
<td>Year for the week where Sunday is the first day of the week, numeric,                   four digits; used with <code>%V</code></td>
</tr>
<tr>
<td><code>%x</code></td>
<td>Year for the week, where Monday is the first day of the week, numeric,                   four digits; used with <code>%v</code></td>
</tr>
<tr>
<td><code>%Y</code></td>
<td>Year, numeric, four digits</td>
</tr>
<tr>
<td><code>%y</code></td>
<td>Year, numeric (two digits)</td>
</tr>
<tr>
<td><code>%%</code></td>
<td>A literal “<code>%</code>” character</td>
</tr>
<tr>
<td><code>%<em><code>x</code></em></code></td>
<td><em><code>x</code></em>, for any                   “<em><code>x</code></em>” not listed                   above</td>
</tr>
</table>
<p>Reference:</p>
<p>http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html</p>
<h4>Incoming search terms:</h4><ul><li>mysql sysdate</li><li>add_months in mysql</li><li>mysql months_between</li><li>mysql trunc date</li><li>mysql add_months</li><li>add_months mysql</li><li>sysdate in mysql</li><li>mysql trunc date function</li><li>trunc function in mysql;</li><li>mysql truncate date to month</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/date-function-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle NVL Equivalent in MySQL</title>
		<link>http://kwatog.com/blog/mysql/oracle-nvl-equivalent-in-mysql/</link>
		<comments>http://kwatog.com/blog/mysql/oracle-nvl-equivalent-in-mysql/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 01:59:44 +0000</pubDate>
		<dc:creator>kwatog</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[isnull]]></category>
		<category><![CDATA[nvl]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[sybase]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=204</guid>
		<description><![CDATA[Here&#8217;s the MySQL equivalent of Oracle&#8217;s NVL and MSSQL/Sybase&#8217;s ISNULL functions. Syntax IFNULL(expr1,expr2) Usage If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2. Take note that IFNULL() returns a numeric or string value, depending on the context in which it is used. I haven&#8217;t used it for other data types yet but [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the MySQL equivalent of Oracle&#8217;s NVL and MSSQL/Sybase&#8217;s ISNULL functions.</p>
<h3>Syntax</h3>
<p><code><br />
IFNULL(expr1,expr2)<br />
</code></p>
<h3>Usage</h3>
<p>If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2. Take note that IFNULL() returns a numeric or string value, depending on the context in which it is used. I haven&#8217;t used it for other data types yet but I reckon it would have the same results. That is to return the same data type as that of expr1. Another important thing to remember is that expr1 and expr2 should have the same data type</p>
<h4>Incoming search terms:</h4><ul><li>nvl mysql</li><li>mysql nvl equivalent</li><li>nvl in mysql</li><li>mysql nvl</li><li>oracle nvl mysql</li><li>nvl equivalent in mysql</li><li>mysql nvl equivalent function</li><li>mysql аналог nvl</li><li>oracle nvl</li><li>NVL Oracle</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/mysql/oracle-nvl-equivalent-in-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL SEQUENCE Equivalent</title>
		<link>http://kwatog.com/blog/mysql/mysql-sequence-equivalent/</link>
		<comments>http://kwatog.com/blog/mysql/mysql-sequence-equivalent/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 03:37:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[nextval]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[sequence]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=197</guid>
		<description><![CDATA[Most Oracle guys (and I heard PostgreSQL, too) will be missing sequence in MySQL. The nearest equivalent that MySQL has for this feature is the AUTO INCREMENT field. However, auto increment is sometimes not sufficient and time will come that you will be missing it. Case in point is the alpha-numeric auto-generated code. In Oracle, [...]]]></description>
			<content:encoded><![CDATA[<p>Most Oracle guys (and I heard PostgreSQL, too) will be missing sequence in MySQL. The nearest equivalent that MySQL has for this feature is the AUTO INCREMENT field. However, auto increment is sometimes not sufficient and time will come that you will be missing it. </p>
<p>Case in point is the alpha-numeric auto-generated code. In Oracle, it&#8217;s easy to generate AA123, AA124, AA125, etc., etc. All we have to do is concat the alpha part (AA) and with the nextval of sequence. For MySQL, the alpha part and the numeric part have to be saved in separate fields.</p>
<p>However, Maresa of Microshell has created an alternative solution for it. The article discusses a way to emulate the nextval function in mysql.  It a nutshell, they created a table similar to the all_sequences of Oracle. This is where you insert your sequences. Then, create a function named nextval() function which increments and returns value of the sequence.<br />
You can check the procedure <a href="http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/1942">here</a>.</p>
<p>It&#8217;s pretty neat, actually. It&#8217;s an excellent alternative and you can even create similar functions like currval(), prevval(), among others. However, I have some reservations on his approach especially on the issue of concurrency. You see in Oracle, calling the nextval() will increment the value and that&#8217;s already persisted (saved) in the sequence table even without saving your query/dml statement. On this approach, other queries accessing the pseudo-nextval will have to wait until your query finishes. Not a good idea. </p>
<p>So for now, I&#8217;ll will still have to make do with whatever MySQL is providing. If there&#8217;s any consolation, MySQL provides LAST_INSERT_ID()  function in case you want to get the latest id inserted. See details here <a href="http://dev.mysql.com/doc/refman/5.0/en/information-functions.html">here</a>. </p>
<p>So I&#8217;m just hoping that MySQL will implement an equivalent feature in the near future. With the imminent takeover by Oracle, I&#8217;m actually hoping that development of MySQL will push through and take a steam. We all know that the development of this widely used open-source database engine has been hampered ever since Sun bought it. </p>
<p>Sequence is a little feature. But little as it seems, it solves a lot of problems and helps improve code development time.</p>
<h4>Incoming search terms:</h4><ul><li>mysql sequence nextval</li><li>mysql nextval</li><li>nextval in mysql</li><li>postgresql sequence equivalent in mysql</li><li>oracle sequence in mysql</li><li>oracle sequence equivalent in mysql</li><li>sequence alternative in mysql</li><li>mysql sequentions</li><li>mysql sequence procedure</li><li>emulating nextval function to get sequence in mysql</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/mysql/mysql-sequence-equivalent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Administration Commands</title>
		<link>http://kwatog.com/blog/linux/mysql-admi-linux/</link>
		<comments>http://kwatog.com/blog/linux/mysql-admi-linux/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 12:11:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[create user]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=153</guid>
		<description><![CDATA[Backup MySQL Database into a File -bash-3.2$mysqldump -ujhondoe -p mydb_name > mydb_name_backup.sql password: -bash-3.2$ zip mydb_name_backup.zip mydb_name_backup.sql Load MySQL Backup Into Database -bash-3.2$mysql -ujhondoe mydb_name < mydb_name_backup.sql password: Create User in MySQL mysql> CREATE USER 'jhondoe'@'localhost' IDENTIFIED BY 'mypassword'; mysql> GRANT ALL PRIVILEGES ON mydbname.* TO 'jhondoe'@'localhost' WITH GRANT OPTION; mysql> CREATE USER 'jhondoe'@'%' IDENTIFIED [...]]]></description>
			<content:encoded><![CDATA[<h2>Backup MySQL Database into a File</h2>
<p><code><br />
-bash-3.2$mysqldump -ujhondoe -p mydb_name > mydb_name_backup.sql<br />
password: <type your password here><br />
-bash-3.2$ zip mydb_name_backup.zip mydb_name_backup.sql<br />
</code></p>
<h2>Load MySQL Backup Into Database</h2>
<p><code><br />
-bash-3.2$mysql -ujhondoe mydb_name < mydb_name_backup.sql<br />
password: <type your password here><br />
</code></p>
<h2>Create User in MySQL</h2>
<p><code><br />
mysql> CREATE USER 'jhondoe'@'localhost' IDENTIFIED BY 'mypassword';<br />
mysql> GRANT ALL PRIVILEGES ON mydbname.* TO 'jhondoe'@'localhost'   WITH GRANT OPTION;</p>
<p>mysql> CREATE USER 'jhondoe'@'%' IDENTIFIED BY 'mypassword';<br />
mysql> GRANT ALL PRIVILEGES ON mydbname.* TO 'monty'@'%'   WITH GRANT OPTION;<br />
</code></p>
<h4>Incoming search terms:</h4><ul><li>mysql administration commands</li><li>my sql administration command</li><li>mysql admin command</li><li>mysql database admin commands</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/linux/mysql-admi-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rename Tables in MySQL</title>
		<link>http://kwatog.com/blog/mysql/rename-tables-in-mysql/</link>
		<comments>http://kwatog.com/blog/mysql/rename-tables-in-mysql/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 02:20:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[phpMyAdmin]]></category>
		<category><![CDATA[rename]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wordpress mu]]></category>
		<guid isPermaLink="false">http://kwatog.com/?p=121</guid>
		<description><![CDATA[If you want to hand code renaming tables, here&#8217;s the sample. Single Table RENAME TABLE wp_users TO kwg_users; multiple tables RENAME TABLE wp_users TO kwtg_users, wp_usermeta TO kwtg_usermeta, wp_site TO kwtg_wpsite, wp_signups TO kwtg_signups; This is handy when renaming a whole lot of tables as in the case of WordPress mu where each blog has [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to hand code renaming tables, here&#8217;s the sample. </p>
<p><strong>Single Table</strong><br />
<code><br />
RENAME TABLE wp_users  TO kwg_users;<br />
</code></p>
<p><strong>multiple tables</strong><br />
<code><br />
RENAME TABLE wp_users  TO kwtg_users,<br />
                     wp_usermeta TO kwtg_usermeta,<br />
                     wp_site TO kwtg_wpsite,<br />
                     wp_signups TO kwtg_signups;<br />
</code></p>
<p>This is handy when renaming a whole lot of tables as in the case of <strong>WordPress mu</strong> where each blog has its own set of tables. If you decide to rename them for security reasons (like you forgot to change the default table prefix during installation), it will be a pain to change them one by one through <strong>phpMyAdmin</strong>.</p>
<h4>Incoming search terms:</h4><ul><li>mysql rename table recursively</li><li>rename multiple tables mysql</li><li>rename table in mysql</li><li>rinomina wp-posts in my sql</li></ul>]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/mysql/rename-tables-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!--
Hyper cache file: 5c906fef93503e20383cf3b352096089
Cache created: 05-02-2012 01:35:13
HCE Version: 0.9.8
Load AVG: 0(5)
-->
