<?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>Albertech.net &#187; MySQL</title>
	<atom:link href="http://albertech.net/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://albertech.net</link>
	<description>Tips, Tricks, and Reviews in Linux, Apache, MySQL, PHP</description>
	<lastBuildDate>Wed, 28 Jul 2010 16:09:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL Tutorial: Fetch last 10 rows without reversing order</title>
		<link>http://albertech.net/2010/01/mysql-tutorial-fetch-last-10-rows-without-reversing-order/</link>
		<comments>http://albertech.net/2010/01/mysql-tutorial-fetch-last-10-rows-without-reversing-order/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 21:57:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[order by]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://albertech.net/?p=330</guid>
		<description><![CDATA[Here's the quickest way to sort data in MySQL after retrieving the last 10 entries with the LIMIT and ORDER BY DESC commands. If you simply do a ORDER BY DESC LIMIT 10, this will return the last 10 results in reverse order (newest first). Adding an inline SELECT command will sort the results after retrieving the last 10 items. (oldest first)

<B>SQL Command</B>

$sql = &#34;SELECT * FROM &#40;SELECT * FROM [TABLE] WHERE ORDER BY modified_date DESC LIMIT 10&#41; AS tbl ORDER BY tbl.modified_date&#34;



This will retrieve the last 10 rows while sorting by date chronologically. I used this SQL command for ... ]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Falbertech.net%252F2010%252F01%252Fmysql-tutorial-fetch-last-10-rows-without-reversing-order%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22MySQL%20Tutorial%3A%20Fetch%20last%2010%20rows%20without%20reversing%20order%22%20%7D);"></div>
<p>Here&#8217;s the quickest way to sort data in MySQL after retrieving the last 10 entries with the LIMIT and ORDER BY DESC commands. If you simply do a ORDER BY DESC LIMIT 10, this will return the last 10 results in reverse order (newest first). Adding an inline SELECT command will sort the results after retrieving the last 10 items. (oldest first)</p>
<p><B>SQL Command</B></p>
<p>$sql = &quot;SELECT * FROM &#40;SELECT * FROM [TABLE] WHERE ORDER BY modified_date DESC LIMIT 10&#41; AS tbl ORDER BY tbl.modified_date&quot;</p>
<p>This will retrieve the last 10 rows while sorting by date chronologically. I used this SQL command for the graphing API I was using (<a href="http://naku.dohcrew.com/libchart">LibChart</a>). This allowed my graph to display the most current data on the right side as opposed to the left.</p>

]]></content:encoded>
			<wfw:commentRss>http://albertech.net/2010/01/mysql-tutorial-fetch-last-10-rows-without-reversing-order/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL: Avoiding the Mysql:Too many connections error</title>
		<link>http://albertech.net/2009/07/mysql-avoiding-the-mysqltoo-many-connections-error/</link>
		<comments>http://albertech.net/2009/07/mysql-avoiding-the-mysqltoo-many-connections-error/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 19:37:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[too many connections]]></category>
		<category><![CDATA[wait_timeout]]></category>

		<guid isPermaLink="false">http://albertech.net/?p=208</guid>
		<description><![CDATA[ If your site experiences the infamous "Mysql : Too many connections" error, you will need to tune your MySQL server to handle the load of a heavily used website. 

There are some configuration variables that you can adjust to make your site handle more connections.
The wait_timeout default in MySQL is 28840 seconds (8 hours), which can seriously limit the number of open connections you have on your page. I adjusted mine to 60 seconds. This frees up the thread after idle timeout, which allows for more connections to connect. The 8 hour timeframe is fine if you only have a few connections to the server. For popular websites, its best to make this value as low as possible. Set this variable to the maximum time your page typically runs. For instance, if you have a page that needs to retrieve some data processed from another server (60-80 seconds) and you only use one mysql_connect, you may lose the mysql connection for processing the remaining parts of the page if your wait_timeout is too low. If the processing takes much longer, a workaround is to use multiple mysql_connects to prevent an idle connection from disconnecting.
]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Falbertech.net%252F2009%252F07%252Fmysql-avoiding-the-mysqltoo-many-connections-error%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22MySQL%3A%20Avoiding%20the%20Mysql%3AToo%20many%20connections%20error%22%20%7D);"></div>
<p> <strong>If your site experiences the infamous &#8220;Mysql : Too many connections&#8221; error, you will need to tune your MySQL server to handle the load of a heavily used website.</strong> </p>
<p> There are some configuration variables that you can adjust to make your site handle more connections.</p>
<ul>
<li>An easy way to identify which variables need to be changed can be done through phpMyAdmin. Login to your phpMyAdmin control panel and search for the &#8220;<strong>Show MySQL runtime information</strong>&#8221; module. Scroll down the page and look for entries that are in <span style="color: #ff0000;">red. <span style="color: #000000;">These are suggested areas in your MySQL configuration that need to be looked at.
<p></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;">The<strong> wait_timeout </strong>default in MySQL is <strong>28840 seconds</strong> (8 hours), which can seriously limit the number of open connections you have on your page. I adjusted mine to<strong> 60 seconds</strong>. This frees up the thread after idle timeout, which allows for more connections to connect. The 8 hour timeframe is fine if you only have a few connections to the server. For popular websites, its best to make this value as low as possible. Set this variable to the maximum time your page typically runs. For instance, if you have a page that needs to retrieve some data processed from another server (60-80 seconds) and you only use one mysql_connect, you may lose the mysql connection for processing the remaining parts of the page if your wait_timeout is too low. If the processing takes much longer, a workaround is to use multiple mysql_connects to prevent an idle connection from disconnecting.
<p></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;"><strong>DNS issues</strong>. If your DNS suddenly stops working, this will consume all your MySQL connections. MySQL tries to resolve the IP address for every connection it gets, so this will start creating many more threads than released if it DNS is down. In Linux, edit the <strong>/etc/hosts</strong> file and manually add in your web server IPs/names to this (if you have static IPs) This will speed up performance by resolving IPs locally as opposed to through DNS. You can identify DNS issues or connection attempts through &#8220;<strong>Failed attempts</strong>&#8221; section in phpMyAdmin runtime page. A significant number of failed attempts can mean either someone is trying to break into your MySQL box or your DNS isn&#8217;t working right.
<p></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;">Increase the <strong>key_buffer</strong> value (for MyISAM tables) This helps handle indexes for temporary tables. If you have lots of key misses, its important to increase the size of the key_buffer. You can do this by comparing the key_reads vs. key_read_requests value.
<p></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;">Increase the <strong>innodb_buffer_pool_size</strong> (for innodb tables)
<p></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;">Increase the <strong>table_cache</strong> value. If you look at your phpMyAdmin runtime &#8220;Opened_tables&#8221; field and see a large number (over 1,000) you will need to increase your table_cache. This will keep tables in memory to speed up peformance. Default is only 64. I&#8217;ve upped mine to over 2,000 since I have many databases and tables running on my server.
<p></span></span></li>
<li><span style="color: #ff0000;"><span style="color: #000000;">For more information, check out these resources:<br />
<a href="http://www.ibm.com/developerworks/linux/library/l-tune-lamp-3.html">http://www.ibm.com/developerworks/linux/library/l-tune-lamp-3.html</a> <br />
</span></span><span style="color: #ff0000;"><span style="color: #000000;"><a href="http://dev.mysql.com/tech-resources/presentations/presentation-oscon2000-20000719/index.html">http://dev.mysql.com/tech-resources/presentations/presentation-oscon2000-20000719/index.html</a></span></span></li>
</ul>
<p><strong> </strong></p>

]]></content:encoded>
			<wfw:commentRss>http://albertech.net/2009/07/mysql-avoiding-the-mysqltoo-many-connections-error/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Quick tuning MySQL performance</title>
		<link>http://albertech.net/2009/06/quick-tuning-mysql-performance/</link>
		<comments>http://albertech.net/2009/06/quick-tuning-mysql-performance/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 01:32:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[throttle]]></category>
		<category><![CDATA[tuning]]></category>

		<guid isPermaLink="false">http://albertech.net/?p=186</guid>
		<description><![CDATA[I've been working on tuning my Apache/MySQL/PHP configuration lately to see how to improve the performance. Lately, I've been noticing some crawlers that have been ignoring my robots.txt file and hitting my server really hard with several page requests every second. So, I decided to run some tests to see where I could speed up my website in the code. ]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Falbertech.net%252F2009%252F06%252Fquick-tuning-mysql-performance%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Quick%20tuning%20MySQL%20performance%22%20%7D);"></div>
<p>I&#8217;ve been working on tuning my Apache/MySQL/PHP configuration lately to see how to improve the performance. Lately, I&#8217;ve been noticing some crawlers (same IPs all the time) that have been ignoring my robots.txt file and hitting my server really hard with several page requests every second.</p>
<p>So, I decided to run some tests to see where I could speed up my website in the code.</p>
<p>One test was significant. I commented one update statement in my code and that sped up my page 3 times. Page display time went down from 0.15 second to 0.045 second! It seems as though my VMWARE server has slow write access times in comparison to reads, so this is a source of the cause. I decided to use this to my advantage.  So, basically create an array with the blacklisted IPs (but you can&#8217;t block them entirely since I need certain crawlers to index websites/etc. for searches)</p>
<p><code>$is_crawler = 0;<br />
$crawler_array = array("[CRAWLER IP]","[CRAWLER IP2]");<br />
foreach($crawler_array as $crawler_item)<br />
{<br />
if ($crawler_item == $current_ip)<br />
{<br />
$is_crawler = 1;<br />
break;<br />
}<br />
}</code></p>
<p>In using this, only run the update query if the source IP isn&#8217;t a crawler&#8230; so something like this:<br />
<code><br />
if ($is_crawler==0)<br />
{</code><code><br />
// Run MySQL Update command<br />
}  </code></p>
<p>Other ways to speed up your MySQL performance.</p>
<ul>
<li>Only use ORDER BY when necessary. Ordering is costly with large datasets</li>
<li>Joins are costly as well. Design a database table cache that has the union set if performance is a concern</li>
<li>Memcache is a viable option as well for pages that use many tables to generate the page.</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://albertech.net/2009/06/quick-tuning-mysql-performance/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Preventing MySQL injection with PHP</title>
		<link>http://albertech.net/2009/03/preventing-mysql-injection-with-php/</link>
		<comments>http://albertech.net/2009/03/preventing-mysql-injection-with-php/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 22:13:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[prevent injection]]></category>

		<guid isPermaLink="false">http://albertech.net/?p=110</guid>
		<description><![CDATA[<strong>A good practice is to check input strings to make sure users don't put in mySQL commands in your server.</strong> For instance, if a username or password POST variable isn't filtered, there is a potential for an injection like 'OR myusername='. In the past, I've been using my own PHP toolkit to "clean" the input variables. But recently, I began searching to see if there are a built-in solution in PHP for this, especially since I'm converting a script written in Python that had the filter <B>MySQLdb.escape_string</B>. Enter <a href="http://us2.php.net/manual/en/function.mysql-real-escape-string.php">mysql_real_escape_string()</a>]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Falbertech.net%252F2009%252F03%252Fpreventing-mysql-injection-with-php%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Preventing%20MySQL%20injection%20with%20PHP%22%20%7D);"></div>
<p><strong>A good practice is to check input strings to make sure users don&#8217;t put in mySQL commands in your server.</strong> For instance, if a username or password POST variable isn&#8217;t filtered, there is a potential for an injection like &#8216;OR myusername=&#8217;. In the past, I&#8217;ve been using my own PHP toolkit to &#8220;clean&#8221; the input variables. But recently, I began searching to see if there are a built-in solution in PHP for this, especially since I&#8217;m converting a script written in Python that had the filter <B>MySQLdb.escape_string</B>. Enter <a href="http://us2.php.net/manual/en/function.mysql-real-escape-string.php">mysql_real_escape_string()</a></p>
<p>1) Step 1: Filter out the backtick character, ` which is often used in mySQL to denote field names<br />
<code><br />
$variable = str_replace("`","",$variable);<br />
</code></p>
<p>2) Step 2: If its a username or password field which does not have a space, you should use ctype_alnum  This will determine whether there is a character thats not alphanumeric or numeric. So, spaces will not work.<br />
<code><br />
if (ctype_alnum($variable))<br />
{<br />
   //allowed variable<br />
}<br />
</code></p>
<p>3) Step 3: Use the mysql_real_escape_string as long as it exists on your server. If it doesn&#8217;t exist, an error message will display. I suggest upgrading your PHP if possible since this function will take care of different character sets/etc. You can use this function after the mySQL connection has been initialized.<br />
<code><br />
if(function_exists("mysql_real_escape_string"))<br />
{<br />
   $variable = mysql_real_escape_string(htmlspecialchars($variable, ENT_QUOTES));<br />
}<br />
else<br />
{<br />
    echo "mysql_real_escpe_string does not exist on the server. Upgrade PHP to the latest version.";<br />
}<br />
</code></p>

]]></content:encoded>
			<wfw:commentRss>http://albertech.net/2009/03/preventing-mysql-injection-with-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Converting MySQL datetime to any format</title>
		<link>http://albertech.net/2009/03/converting-mysql-datetime-to-any-format/</link>
		<comments>http://albertech.net/2009/03/converting-mysql-datetime-to-any-format/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 05:54:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[format]]></category>

		<guid isPermaLink="false">http://albertech.net/?p=95</guid>
		<description><![CDATA[Converting the datetime format is really simple if you let MySQL do the formatting for you.

<a title="MySQL 5.1 Date and Time Functions" href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format">MySQL 5.1 SELECT DATE_FORMAT manual</a>

For instance, if you wanted to convert the datetime into something that reads
<code>function ConvertNiceDateOnly($date)
{
// Convert mySQL date to nice formatted date
$normaldate = mysql_query("SELECT DATE_FORMAT('$date','%M %e, %Y')");
$normaldate = mysql_fetch_row($normaldate);
$normaldate = $normaldate[0];
return $normaldate;
}
</code>]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Falbertech.net%252F2009%252F03%252Fconverting-mysql-datetime-to-any-format%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Converting%20MySQL%20datetime%20to%20any%20format%22%20%7D);"></div>
<p>Converting the datetime format is really simple if you let MySQL do the formatting for you.</p>
<p><a title="MySQL 5.1 Date and Time Functions" href="http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format">MySQL 5.1 SELECT DATE_FORMAT manual</a></p>
<p>For instance, if you wanted to convert the datetime into something that reads<br />
<code>function ConvertNiceDateOnly($date)<br />
{<br />
// Convert mySQL date to nice formatted date<br />
$normaldate = mysql_query("SELECT DATE_FORMAT('$date','%M %e, %Y')");<br />
$normaldate = mysql_fetch_row($normaldate);<br />
$normaldate = $normaldate[0];<br />
return $normaldate;<br />
}<br />
</code></p>

]]></content:encoded>
			<wfw:commentRss>http://albertech.net/2009/03/converting-mysql-datetime-to-any-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; MySQL datetime to seconds</title>
		<link>http://albertech.net/2009/01/php-mysql-datetime-to-seconds/</link>
		<comments>http://albertech.net/2009/01/php-mysql-datetime-to-seconds/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 02:53:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[datetime to seconds]]></category>

		<guid isPermaLink="false">http://albertech.net/?p=59</guid>
		<description><![CDATA[<strong>$unixseconds = strtotime($mysqldate);</strong>

For instance, you can use this to write a timeout script for login failures. Usually, a system should lock after 3-5 consecutive failed login attempts. I save the timestamp after the 5th consecutive login failure, then run a check on this timestamp if the current time is within the ~5-10 minute lockout window. 5 minutes is 300 seconds, 10 minutes is 600 seconds.]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Falbertech.net%252F2009%252F01%252Fphp-mysql-datetime-to-seconds%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22PHP%20-%20MySQL%20datetime%20to%20seconds%22%20%7D);"></div>
<p><strong>$unixseconds = strtotime($mysqldate);</strong></p>
<p>For instance, you can use this to write a timeout script for login failures. Usually, a system should lock after 3-5 consecutive failed login attempts. I save the timestamp after the 5th consecutive login failure, then run a check on this timestamp if the current time is within the ~5-10 minute lockout window. 5 minutes is 300 seconds, 10 minutes is 600 seconds.</p>

]]></content:encoded>
			<wfw:commentRss>http://albertech.net/2009/01/php-mysql-datetime-to-seconds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; rename a database</title>
		<link>http://albertech.net/2008/12/mysql-rename-a-database/</link>
		<comments>http://albertech.net/2008/12/mysql-rename-a-database/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 19:16:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[rename database]]></category>

		<guid isPermaLink="false">http://albertech.net/?p=51</guid>
		<description><![CDATA[I looked through the documentation on MySQL and it looks like they removed the "rename database" option. Here's a workaround:

<strong>mysqladmin create [Name of new database]
mysqldump --opt [Name of old database] &#124; mysql [Name of new database]</strong>]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Falbertech.net%252F2008%252F12%252Fmysql-rename-a-database%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22MySQL%20-%20rename%20a%20database%22%20%7D);"></div>
<p>I looked through the documentation on MySQL and it looks like they removed the &#8220;rename database&#8221; option. Here&#8217;s a workaround:</p>
<p><strong>mysqladmin create [Name of new database]<br />
mysqldump &#8211;opt [Name of old database] | mysql [Name of new database]</strong></p>

]]></content:encoded>
			<wfw:commentRss>http://albertech.net/2008/12/mysql-rename-a-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reset MySQL auto increment to 1</title>
		<link>http://albertech.net/2008/12/reset-mysql-auto-increment-to-1/</link>
		<comments>http://albertech.net/2008/12/reset-mysql-auto-increment-to-1/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 20:04:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[auto_increment]]></category>
		<category><![CDATA[primary key]]></category>
		<category><![CDATA[reset]]></category>
		<category><![CDATA[truncate]]></category>

		<guid isPermaLink="false">http://albertech.net/?p=47</guid>
		<description><![CDATA[Here's a quick reference to reset the MySQL auto_increment field to 1 and <strong>delete</strong> <strong>ALL rows in a table</strong>. This is useful in case you had to do some testing and wanted to reset the primary key field back to 1 and clear out the table.

<code>truncate table [NAME OF TABLE]</code>

If you don't want to wipe out the table, you can reset the auto_increment by using:

<code>alter table [NAME OF TABLE] auto_increment=1</code>]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Falbertech.net%252F2008%252F12%252Freset-mysql-auto-increment-to-1%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Reset%20MySQL%20auto%20increment%20to%201%22%20%7D);"></div>
<p>Here&#8217;s a quick reference to reset the MySQL auto_increment field to 1 and <strong>delete</strong> <strong>ALL rows in a table</strong>. This is useful in case you had to do some testing and wanted to reset the primary key field back to 1 and clear out the table.</p>
<p><code>truncate table [NAME OF TABLE]</code></p>
<p>If you don&#8217;t want to wipe out the table, you can reset the auto_increment by using:</p>
<p><code>alter table [NAME OF TABLE] auto_increment=1</code></p>

]]></content:encoded>
			<wfw:commentRss>http://albertech.net/2008/12/reset-mysql-auto-increment-to-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
