<?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>Prodromus &#187; MySQL</title>
	<atom:link href="http://www.prodromus.com/category/mysql/feed" rel="self" type="application/rss+xml" />
	<link>http://www.prodromus.com</link>
	<description>A forerunner to the future...</description>
	<lastBuildDate>Thu, 19 Jan 2012 22:32:37 +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>What database does Facebook use?</title>
		<link>http://www.prodromus.com/2011/01/27/what-database-does-facebook-use</link>
		<comments>http://www.prodromus.com/2011/01/27/what-database-does-facebook-use#comments</comments>
		<pubDate>Thu, 27 Jan 2011 22:19:41 +0000</pubDate>
		<dc:creator>Prodromus</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[caching system]]></category>
		<category><![CDATA[database engine]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Innodb]]></category>
		<category><![CDATA[large scale web applications]]></category>
		<category><![CDATA[Memcached]]></category>
		<category><![CDATA[Microsoft SQL Server]]></category>
		<category><![CDATA[mysql servers]]></category>
		<category><![CDATA[NFS]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[What database does Facebook use?]]></category>

		<guid isPermaLink="false">http://www.prodromus.com/?p=417</guid>
		<description><![CDATA[What database does Facebook use is one of the most common questions asked when folks start taking about what database is the most scalable for large scale web applications.   In fact, it is usually a person who is an open source proponent, and knows very well that Facebook uses MySQL as their core database [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignright" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://commons.wikipedia.org/wiki/File:Mysqlwb-homepage.png"><img title="The home screen of the FOSS edition of MySQL W..." src="http://www.prodromus.com/wp-content/uploads/2011/01/300px-Mysqlwb-homepage2.png" alt="The home screen of the FOSS edition of MySQL W..." width="300" height="211" /></a></dt>
</dl>
</div>
</div>
<p>What database does <a class="zem_slink" title="Facebook" rel="homepage" href="http://facebook.com">Facebook</a> use is one of the most common questions asked when folks start taking about what database is the most scalable for large scale web applications.   In fact, it is usually a person who is an open source proponent, and knows very well that Facebook uses <a class="zem_slink" title="MySQL" rel="homepage" href="http://www.mysql.com">MySQL</a> as their core database engine.  Because of this fact, this is often the single biggest reason that developers use to push to get MySQL used in their company.  I would imagine that is why it is a very popular Google query.</p>
<p>While Facebook uses MySQL, they do not use it as-is out of the box.  In fact, their team has submitted numerous high-performance enhancements to the MySQL core and <a class="zem_slink" title="InnoDB" rel="homepage" href="http://www.innodb.com/">Innodb</a> plug-in.  Their main focus has been on adding performance counters to Innodb.  Other changes focused on the IO sub-system, including the following new features :</p>
<ul>
<li>innodb_io_capacity &#8211; sets the IO capacity of the server to determine rate limits for background IO</li>
<li>innodb_read_io_threads, innodb_write_io_threads &#8211; set the number of background IO threads</li>
<li>innodb_max_merged_io &#8211; sets the maximum number of adjacent IO requests that may be merged into a large IO request</li>
</ul>
<p>Facebook uses MySQL as a key-value store in which data is randomly distributed across a large set of logical instances. These logical instances are spread out across physical nodes and load balancing is done at the physical node level.  Facebook has developed a partitioning scheme in which a global ID is assigned to all user data. They also have a custom archiving scheme that is based on how frequent and recent data is on a per-user basis. Most data is distributed randomly.  Amazingly, it has been rumored that Facebook has 1800 MySQL servers, but only 3 full-time DBAs.</p>
<p>Facebook primarily uses MySQL for structured data storage such as wall posts, user information, etc. This data is replicated between their various data centers. For blob storage (photos, video, etc.), Facebook makes use of a custom solution that involves a CDN externally and NFS internally.</p>
<p>It is also important to note that Facebook makes heavy use of Memcache,  a memory caching system that is used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce reading time. Memcache is Facebook’s primary form of caching and greatly reduces the database load. Having a caching system allows Facebook to be as fast as it is at recalling your data. If it doesn’t have to go to the database it will just fetch your data from the cache based on your user ID.</p>
<p>So, while &#8220;What database does Facebook use?&#8221; seems like a simple question, you can see that they have added a variety of other systems to make it truly web scalable.  But, still feel free to use the argument, &#8220;MySQL is as good or better than Oracle or MS SQL Server, heck, even Facebook uses it, and they have 500 Million users!&#8221;.</p>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://www.allfacebook.com/facebook-showcasing-its-open-source-database-2010-11">Facebook Showcasing Its Open Source Database</a> (allfacebook.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.z-car.com/blog/2010/12/10/google-chromes-new-false-start-feature">Google Chrome&#8217;s new False Start &#8220;Feature&#8221;</a> (z-car.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.readwriteweb.com/hack/2010/11/facebook-mysql-scale.php">Video: How Facebook Makes MySQL Scale</a> (readwriteweb.com)</li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=81737e68-599c-4886-b9d3-1656464a5293" alt="" /></div>
]]></content:encoded>
			<wfw:commentRss>http://www.prodromus.com/2011/01/27/what-database-does-facebook-use/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; ORDER BY does not sort data properly&#8230;</title>
		<link>http://www.prodromus.com/2010/12/28/mysql-order-by-does-not-sort-data-properly</link>
		<comments>http://www.prodromus.com/2010/12/28/mysql-order-by-does-not-sort-data-properly#comments</comments>
		<pubDate>Tue, 28 Dec 2010 22:24:16 +0000</pubDate>
		<dc:creator>Prodromus</dc:creator>
				<category><![CDATA[Errors]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Enigma]]></category>
		<category><![CDATA[enum]]></category>
		<category><![CDATA[ORDER]]></category>
		<category><![CDATA[order by]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[Select]]></category>
		<category><![CDATA[simple queries]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[sort broken]]></category>
		<category><![CDATA[table structure]]></category>
		<category><![CDATA[undiscovered]]></category>

		<guid isPermaLink="false">http://www.prodromus.com/?p=408</guid>
		<description><![CDATA[Imagine a developer working late at night trying to complete some simple queries for a report due the next day.  No matter what she does, the resulting query will just not sort properly. Is this some undiscovered MySQL bug?  No wonder this software is free, MySQL is broke and can&#8217;t even perform a basic sort. [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine a developer working late at night trying to complete some simple queries for a report due the next day.  No matter what she does, the resulting query will just not sort properly. Is this some undiscovered MySQL bug?  No wonder this software is free, MySQL is broke and can&#8217;t even perform a basic sort.  It looks simple, sort the data in a table:</p>
<p>mysql&gt; SELECT id, technology from Enigma;<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| Id | technology |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| 1 | PHP |<br />
| 2 | LINUX |<br />
| 3 | MySQL |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+</p>
<p>To sort the records based on the technology, do an ORDER BY on column Technology:</p>
<p>mysql&gt; SELECT id, technology from Enigma ORDER BY Technology;<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| Id | technology |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| 1 | PHP |<br />
| 2 | LINUX |<br />
| 3 | MySQL |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+</p>
<p>It seems that the server does not understand what I have asked, or I have not mastered the entire alphabet &#8230;<br />
Let&#8217;s add the clause CSA (just in case!)</p>
<p>mysql&gt; SELECT id, technology from Enigma ORDER BY ASC Technology;<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| Id | technology |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| 1 | PHP |<br />
| 2 | LINUX |<br />
| 3 | MySQL |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+</p>
<p>That does not seem to be any better!  MySQL does not sort the data as I wish, am I going crazy? Should I change my RDBMS?<br />
Don&#8217;t worry, a careful look at the table structure allows us to see things clearly.</p>
<p>mysql&gt; SHOW CREATE TABLE enigma;</p>
<p>Table: enigma<br />
Create Table: CREATE TABLE `Enigma` (<br />
`Id` int (11) DEFAULT NULL,<br />
`Technology` enum (&#8216;PHP&#8217;, &#8216;Linux&#8217;, &#8216;MySQL&#8217;) DEFAULT NULL<br />
) ENGINE = MyISAM DEFAULT CHARSET = latin1</p>
<p>The column technology is of a type ENUM.  The Enum field is stored as an integer, and that is the index that MySQL uses for sorting.  In other words, 1 is PHP, 3 is MySQL, and 2 is Linux, so sorting does works properly, just not as expected when the Enum data field is storing character data.  So how do you get the desired result?  Simply force MySQL to use the value string and not index when sorting.   This can be done by using either the Concat() or Cast() functions, as follows:</p>
<p>function concat ()<br />
mysql&gt; SELECT id, technology from Enigma ORDER BY concat (technology);<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| Id | technology |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| 2 | LINUX |<br />
| 3 | MySQL |<br />
| 1 | PHP |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
function cast ()<br />
mysql&gt; SELECT id, technology from Enigma ORDER BY cast (technology as char);<br />
<span style="font-size: 11.6667px;">+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;-+<br />
| id | Technology |<br />
+&#8212;&#8211; -+&#8212;&#8212;&#8212;&#8212;-+<br />
| 2 | LINUX |<br />
| 3 | MySQL |<br />
| 1 | PHP |<br />
+&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211; &#8211; +</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.prodromus.com/2010/12/28/mysql-order-by-does-not-sort-data-properly/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; A simple script to truncate all MySQL tables in a Database</title>
		<link>http://www.prodromus.com/2010/12/22/mysql-a-simple-script-to-truncate-all-mysql-tables-in-a-database</link>
		<comments>http://www.prodromus.com/2010/12/22/mysql-a-simple-script-to-truncate-all-mysql-tables-in-a-database#comments</comments>
		<pubDate>Wed, 22 Dec 2010 20:50:32 +0000</pubDate>
		<dc:creator>Prodromus</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Dirty]]></category>
		<category><![CDATA[DROP]]></category>
		<category><![CDATA[Dump]]></category>
		<category><![CDATA[dumpfile]]></category>
		<category><![CDATA[mysql stored procedure]]></category>
		<category><![CDATA[mysql tables]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[Percona]]></category>
		<category><![CDATA[procedure]]></category>
		<category><![CDATA[recovery]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[Stored]]></category>
		<category><![CDATA[Stored procedure]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[table statements]]></category>
		<category><![CDATA[TRUNCATE]]></category>

		<guid isPermaLink="false">http://www.prodromus.com/?p=359</guid>
		<description><![CDATA[Want a quick and dirty way to Truncate all the tables in a MySQL DB?  You can use the following one line script. mysqldump -ppassword YourDBName &#8211;no-data dumpfile &#124; mysql dumpfile What this does is uses mysqldump to output all the tables in the database &#8220;YourDBName&#8221; into a dump file.  This dump file contains drop [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignright" style="width: 210px;">
<dt class="wp-caption-dt"><a href="http://commons.wikipedia.org/wiki/File:Mysql-hires.gif"><img title="The official logo of the database query MySQL" src="http://www.prodromus.com/wp-content/uploads/2010/12/Mysql-hires.gif" alt="The official logo of the database query MySQL" width="200" height="103" /></a></dt>
</dl>
</div>
</div>
<p>Want a quick and dirty way to Truncate all the tables in a MySQL DB?  You can use the following one line script.</p>
<p>mysqldump -ppassword YourDBName &#8211;no-data dumpfile | mysql dumpfile</p>
<p>What this does is uses mysqldump to output all the tables in the database &#8220;YourDBName&#8221; into a dump file.  This dump file contains drop statements, and create table statements for each table in the database.  What this effectively does is drops every table, and recreates it WITHOUT any data inside.  Be very careful, since this is a very powerful script, it has the ability to completely wipe out your database with no hope of recovery unless you have a current backup.</p>
<p>For additional ways to execute specific commands against all tables in a DB, look into using <a rel="nofollow" href="http://www.maatkit.org/doc/mk-find.html">mk-find</a> in <a rel="nofollow" href="http://www.maatkit.org/tools.html">Maatkit</a>, it is an excellent tool for advanced MySQL scripting.</p>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://www.prodromus.com/2010/12/17/exiting-a-mysql-stored-procedure-in-the-middle-of-the-code">Exiting a MySQL Stored Procedure in the middle of the code</a> (prodromus.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.mysqlperformanceblog.com/2010/12/21/mysql-5-5-8-and-percona-server-on-fast-flash-card-virident-tachion/">MySQL 5.5.8 and Percona Server on Fast Flash card (Virident tachIOn)</a> (mysqlperformanceblog.com)</li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=44ce1fc5-a3f7-47c0-8a39-c9db0470b6ad" alt="" /></div>
]]></content:encoded>
			<wfw:commentRss>http://www.prodromus.com/2010/12/22/mysql-a-simple-script-to-truncate-all-mysql-tables-in-a-database/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; Select rows from a table when a field starts with a number</title>
		<link>http://www.prodromus.com/2010/12/22/mysql-select-rows-from-a-table-when-a-field-starts-with-a-number</link>
		<comments>http://www.prodromus.com/2010/12/22/mysql-select-rows-from-a-table-when-a-field-starts-with-a-number#comments</comments>
		<pubDate>Wed, 22 Dec 2010 19:33:46 +0000</pubDate>
		<dc:creator>Prodromus</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Query Optimization]]></category>
		<category><![CDATA[character class]]></category>
		<category><![CDATA[Pattern matching]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[Regular expression]]></category>
		<category><![CDATA[Select]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://www.prodromus.com/?p=353</guid>
		<description><![CDATA[A common request is how to select records from a table when a specific field starts with a number. This request often is used when searching free-form text fields where the fields were used to provide an answer field to a question. The simplest way to attack this is by using a regular expression. For [...]]]></description>
			<content:encoded><![CDATA[<p>A common request is how to select records from a table when a specific field starts with a number.  This request often is used when searching free-form text fields where the fields were used to provide an answer field to a question.</p>
<p>The simplest way to attack this is by using a regular expression.  For example:</p>
<p>SELECT * FROM BadlyDesignedTable WHERE AnswerColumn regexp &#8216;^[0-9]+&#8217;;</p>
<p>or<br />
SELECT * FROM BadlyDesignedTable WHERE AnswerColumn RLIKE &#8216;^[0-9]+&#8217;;</p>
<p><a class="zem_slink" title="Regular expression" rel="wikipedia" href="http://en.wikipedia.org/wiki/Regular_expression">Regex</a> and RLIKE are compatible keywords that both represent regular expression matching.</p>
<p>The regex is described as follows :</p>
<p>^    - Start anchor, used to ensure the <a class="zem_slink" title="Pattern matching" rel="wikipedia" href="http://en.wikipedia.org/wiki/Pattern_matching">pattern matches</a> start of the string.<br />
[    - Start of <a class="zem_slink" title="Character class" rel="wikipedia" href="http://en.wikipedia.org/wiki/Character_class">character class</a>.<br />
0-9  - Any digit<br />
]    - End of character class</p>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://ask.metafilter.com/173434/How-can-I-select-this-in-SQL">How can I select this in SQL?</a> (ask.metafilter.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.mt-soft.com.ar/2010/07/19/test-regular-expressions-in-your-browser/">Test Regular Expressions in Your Browser</a> (mt-soft.com.ar)</li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=12bfbaa8-f424-4e31-82c2-084467a3e4ea" alt="" /></div>
]]></content:encoded>
			<wfw:commentRss>http://www.prodromus.com/2010/12/22/mysql-select-rows-from-a-table-when-a-field-starts-with-a-number/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Exiting a MySQL Stored Procedure in the middle of the code</title>
		<link>http://www.prodromus.com/2010/12/17/exiting-a-mysql-stored-procedure-in-the-middle-of-the-code</link>
		<comments>http://www.prodromus.com/2010/12/17/exiting-a-mysql-stored-procedure-in-the-middle-of-the-code#comments</comments>
		<pubDate>Fri, 17 Dec 2010 18:50:23 +0000</pubDate>
		<dc:creator>Prodromus</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[EXIT]]></category>
		<category><![CDATA[Exit a Stored Procedure]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[How to Exit a Mysql Stored Procedure]]></category>
		<category><![CDATA[LEAVE]]></category>
		<category><![CDATA[mysql stored procedure]]></category>
		<category><![CDATA[procedure]]></category>
		<category><![CDATA[Statement]]></category>
		<category><![CDATA[Stored]]></category>
		<category><![CDATA[Stored procedure]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://www.prodromus.com/?p=350</guid>
		<description><![CDATA[While exiting a MySQL function is fairly straight-forward, simply use the RETURN keyword, exiting a Stored Procedure is not quite as obvious.  There is no EXIT keyword, however you can use the LEAVE keyword and specify a label that is associated with the BEGIN of the Stored Procedure.  In this way, you are defining the [...]]]></description>
			<content:encoded><![CDATA[<p>While exiting a MySQL function is fairly straight-forward, simply use the RETURN keyword, exiting a Stored Procedure is not quite as obvious.  There is no EXIT keyword, however you can use the LEAVE keyword and specify a label that is associated with the BEGIN of the Stored Procedure.  In this way, you are defining the Stored Procedure with a Label, which the LEAVE statement can then act upon.</p>
<p>As an example, look at the following Stored Procedure :</p>
<p>CREATE PROCEDURE TestProc(Value INT)</p>
<p>ThisSP:BEGIN</p>
<p>IF  Value is null or Value=0 then<br />
Select &#8216;Invalid Value&#8217;;<br />
LEAVE ThisSP;<br />
END IF;</p>
<p>Select * from Table twhere t.Value=Value;</p>
<p><span style="font-size: 11.6667px;">END;</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.prodromus.com/2010/12/17/exiting-a-mysql-stored-procedure-in-the-middle-of-the-code/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; Best way to remove all data from a table</title>
		<link>http://www.prodromus.com/2010/11/22/mysql-best-way-to-remove-all-data-from-a-table</link>
		<comments>http://www.prodromus.com/2010/11/22/mysql-best-way-to-remove-all-data-from-a-table#comments</comments>
		<pubDate>Mon, 22 Nov 2010 22:24:48 +0000</pubDate>
		<dc:creator>Prodromus</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[auto increment]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[DELETE]]></category>
		<category><![CDATA[DROP]]></category>
		<category><![CDATA[dumpfile]]></category>
		<category><![CDATA[LEAVE]]></category>
		<category><![CDATA[mysql table]]></category>
		<category><![CDATA[mysql tables]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[nuclear option]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[table structure]]></category>
		<category><![CDATA[TRUNCATE]]></category>
		<category><![CDATA[truncate table]]></category>

		<guid isPermaLink="false">http://www.prodromus.com/?p=371</guid>
		<description><![CDATA[There are multiple ways in which to remove all data from a MySQL Table. The first is to use the DROP TABLE command, which will remove the entire table with data.  This basically removes the entire table, you will not be able to recover the structure or data. The second is DELETE * FROM Table [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignright" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://en.wikipedia.org/wiki/File:MySQL.svg"><img title="MySQL's logo. Converted from EPS with Scribus ..." src="http://www.prodromus.com/wp-content/uploads/2010/12/300px-MySQL.svg_.png" alt="MySQL's logo. Converted from EPS with Scribus ..." width="300" height="155" /></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;"><a href="http://en.wikipedia.org/wiki/File:MySQL.svg"></a></dd>
</dl>
</div>
</div>
<p>There are multiple ways in which to remove all data from a MySQL Table.</p>
<p>The first is to use the DROP TABLE command, which will remove the entire table with data.  This basically removes the entire table, you will not be able to recover the structure or data.</p>
<p>The second is DELETE * FROM Table which will remove the data,  leaving the auto-increment values alone, as well as the rest of the table structure.  This method is very slow on large tables using Innodb.  This is because each record has to be written to the log.  In general, you should never use this method to remove all data from a table.</p>
<p>The third method is to issue a TRUNCATE TABLE command which will quickly remove all the data from the table, reset the auto-increment values (but leave them as auto-increment columns, so they will just start at 1 and go up from there again).</p>
<p>Lastly, you can use the nuclear option, which is as follows :</p>
<p>mysqldump -ppassword YourDBName YourTblName –no-data dumpfile | mysql dumpfile</p>
<p>This will drop the table, and then recreate it all from scratch.</p>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://www.prodromus.com/2010/12/22/mysql-a-simple-script-to-truncate-all-mysql-tables-in-a-database">MySQL &#8211; A simple script to truncate all MySQL tables in a Database</a> (prodromus.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.mysqlperformanceblog.com/2010/10/26/sharing-an-auto_increment-value-across-multiple-mysql-tables-revisited/">Sharing an auto_increment value across multiple MySQL tables (revisited)</a> (mysqlperformanceblog.com)</li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=96b0789a-58b1-4f29-99df-1098176e566c" alt="" /></div>
]]></content:encoded>
			<wfw:commentRss>http://www.prodromus.com/2010/11/22/mysql-best-way-to-remove-all-data-from-a-table/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; Help, I lost the Root password!  Error number 1045</title>
		<link>http://www.prodromus.com/2010/09/07/mysql-help-i-lost-the-root-password-error-number-1045</link>
		<comments>http://www.prodromus.com/2010/09/07/mysql-help-i-lost-the-root-password-error-number-1045#comments</comments>
		<pubDate>Tue, 07 Sep 2010 19:11:13 +0000</pubDate>
		<dc:creator>Prodromus</dc:creator>
				<category><![CDATA[Errors]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[FLUSH]]></category>
		<category><![CDATA[mysql error number 1045]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[PRIVILEGES]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[root password]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.prodromus.com/?p=347</guid>
		<description><![CDATA[Have you ever seen the dreaded MySQL Error number 1045 Access denied for user &#8216;root&#8217;@'localhost&#8217; (using password: YES)? Don&#8217;t worry, this is an easy to recover from situation. Just follow these basic steps to reset the root user password. Stop the MySQL server process. Start the MySQL server process with the &#8211;skip-grant-tables option. This option [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever seen the dreaded MySQL Error number 1045 Access denied for user &#8216;root&#8217;@'localhost&#8217; (using password: YES)?</p>
<p>Don&#8217;t worry, this is an easy to recover from situation.  Just follow these basic steps to reset the root user password.</p>
<p>Stop the MySQL server process.</p>
<p>Start the MySQL server process with the &#8211;skip-grant-tables option.  This option causes the server to start without using the privilege system at all, which gives <strong>anyone </strong>with access to the server unrestricted access to all databases. BEWARE!  Anyone can access your server, so make sure off the Internet, and that you perform the following steps as quickly as possible.</p>
<p>Start the MySQL console client with the -u root option.  Mysql -u root</p>
<p>SELECT * FROM mysql.user;</p>
<p>UPDATE mysql.user SET Password=PASSWORD(&#8216;[password]&#8216;) WHERE User=&#8217;[username]&#8216;;  Replace [username] with root to change root.  You can also change any other user as well.</p>
<p>Stop the MySQL process</p>
<p>Start the MySQL Process normally (i.e. without the &#8211;skip-grant-tables option).</p>
<p>Some folks have reported that issuing a Flush Privileges command will prevent your having to perform the final Stop/Start of the MySQL server.  However, this has not always worked for me, and I think to be safe, it is wise to recycle the server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.prodromus.com/2010/09/07/mysql-help-i-lost-the-root-password-error-number-1045/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL &#8211; Innodb Slow Shutdown &#8211; Dirty Buffer Pages</title>
		<link>http://www.prodromus.com/2010/09/03/mysql-innodb-slow-shutdown-dirty-buffer-pages</link>
		<comments>http://www.prodromus.com/2010/09/03/mysql-innodb-slow-shutdown-dirty-buffer-pages#comments</comments>
		<pubDate>Fri, 03 Sep 2010 14:45:39 +0000</pubDate>
		<dc:creator>Prodromus</dc:creator>
				<category><![CDATA[Innodb]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[buffer]]></category>
		<category><![CDATA[buffer pool]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Dirty]]></category>
		<category><![CDATA[dirty pages]]></category>
		<category><![CDATA[downtime]]></category>
		<category><![CDATA[long time]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[Shutdown]]></category>
		<category><![CDATA[shutdowns]]></category>
		<category><![CDATA[slow shutdown]]></category>
		<category><![CDATA[system shutdown]]></category>

		<guid isPermaLink="false">http://www.prodromus.com/?p=281</guid>
		<description><![CDATA[If you have a MySQL server that reserves a large amount of memory for the Innodb buffer pool, you may have seen that it can often take a very long time to shutdown.  During the shutdown process, the server will not be able to serve any requests.  From my experience, I have seen that it [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a MySQL server that reserves a large amount of memory for the Innodb buffer pool, you may have seen that it can often take a very long time to shutdown.  During the shutdown process, the server will not be able to serve any requests.  From my experience, I have seen that it can take 1-5 minutes per GB of buffer to perform a shutdown.  So, for example, if you have a server with 50G of memory allocated to the Innodb Buffer Pool, and 50% of the buffer is dirty (unwritten to disk), it can take anywhere from 25-125 minutes to shutdown.  Multiple hour shutdowns on large, busy Innodb MySQL servers is not unheard of.</p>
<p>Luckily, there is a fairly easy way to speed up shutdown while still allowing the server to stay up and handle requests.  The secret is to lower the maximum percentage of dirty pages allowed.  This is controlled by the global variable innodb_max_dirty_pages_pct.  On my servers I usually have this set at 75%.  This variable can be changed at run-time, which allows us to modify this variable to speed up system shutdown.</p>
<p>First, enter the command :</p>
<p>set global  innodb_max_dirty_pages_pct=0;</p>
<p>You can then enter the following to verify the new value:</p>
<p>show  global variables where variable_name rlike &#8216;dirty&#8217;;</p>
<p>To monitor the number of dirty pages that have not been written to disk, enter the following:</p>
<p>show  global status where variable_name rlike &#8216;dirty&#8217;;</p>
<p>You will see this number begin to drop, although it is unlikely to ever reach 0, once it drops to a low level and reaches a plateau, you can then shutdown the server.  You will find that the server will shutdown very quickly, allowing you to minimize downtime.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.prodromus.com/2010/09/03/mysql-innodb-slow-shutdown-dirty-buffer-pages/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Collate and Case Sensitivity &#8211; Flexible Compare</title>
		<link>http://www.prodromus.com/2010/08/31/mysql-collate-and-case-sensitivity-flexible-compare</link>
		<comments>http://www.prodromus.com/2010/08/31/mysql-collate-and-case-sensitivity-flexible-compare#comments</comments>
		<pubDate>Tue, 31 Aug 2010 17:10:50 +0000</pubDate>
		<dc:creator>Prodromus</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[case sensitivity]]></category>
		<category><![CDATA[case-sensitive search]]></category>
		<category><![CDATA[COLLATE]]></category>
		<category><![CDATA[collation]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[match]]></category>
		<category><![CDATA[sensitive search]]></category>
		<category><![CDATA[string comparisons]]></category>
		<category><![CDATA[string search]]></category>

		<guid isPermaLink="false">http://www.prodromus.com/?p=340</guid>
		<description><![CDATA[In a typical MySQL installation, the default character set and collation are latin1 and latin1_swedish_ci.  This means that all string comparisons will be performed in a case insensitive manner.  So, &#8216;Search String&#8217;='search string&#8217;.  This is great for most WHERE expressions, however there are occasions where performing a case-sensitive search is required.  Luckily MySQL provides the collate clause which allows you to [...]]]></description>
			<content:encoded><![CDATA[<p><!--e9e379b0972f40d19a4f98f80fa4ffb2-->In a typical MySQL installation, the default character set and collation are latin1 and latin1_swedish_ci.  This means that all string comparisons will be performed in a case insensitive manner.  So, &#8216;Search String&#8217;='search string&#8217;.  This is great for most WHERE expressions, however there are occasions where performing a case-sensitive search is required.  Luckily MySQL provides the collate clause which allows you to override whatever the default collation is for a comparison.   As an example :</p>
<p>select * from mytable where first_name collate latin1_general_cs=&#8217;damon&#8217;</p>
<p>This will only return rows will the first_name matches damon exactly.  Damon will not match.</p>
<p>You can also use latin1_bin which performs an exact binary match.</p>
<p>If you are unsure of a field or strings collation, you can use the COLLATION(str) function to return the collation of the string argument.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.prodromus.com/2010/08/31/mysql-collate-and-case-sensitivity-flexible-compare/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top My.CNF Optimizations for Innodb</title>
		<link>http://www.prodromus.com/2010/08/20/top-my-cnf-optimizations-for-innodb</link>
		<comments>http://www.prodromus.com/2010/08/20/top-my-cnf-optimizations-for-innodb#comments</comments>
		<pubDate>Fri, 20 Aug 2010 16:07:18 +0000</pubDate>
		<dc:creator>Prodromus</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[Innodb]]></category>
		<category><![CDATA[INSERT]]></category>
		<category><![CDATA[Logging]]></category>
		<category><![CDATA[MyISAM]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[optimizations]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[performance improvement]]></category>
		<category><![CDATA[profiler]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[query performance]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[UPDATE]]></category>

		<guid isPermaLink="false">http://www.prodromus.com/?p=327</guid>
		<description><![CDATA[These are the four parameters which will have the most affect on the performance of MySQL 5.1x and Innodb.   If you are suffering from poor performance, try changing the following settings.  Remember, each individual situation will vary, and in many cases, the actual design of your queries will have more to do with your [...]]]></description>
			<content:encoded><![CDATA[<p>These are the four parameters which will have the most affect on the performance of MySQL 5.1x and Innodb.   If you are suffering from poor performance, try changing the following settings.  Remember, each individual situation will vary, and in many cases, the actual design of your queries will have more to do with your overall performance than any system tuning tricks.  The best tool I have found to capture, review, and analyse query performance for MySQL is <a title="Jet Profiler for MySQL" href="http://www.jetprofiler.com/" target="_blank">Jet Profiler for MySQL</a>.  If you need help optimizing your queries, let us know.</p>
<div id="_mcePaste">
<p><span style="font-size: 13.3333px;">innodb_buffer_pool_size =8G<br />
</span><span style="font-size: 13.3333px;">Set this to ~80% of free server memory.  If you have a dedicated MySQL server with 10G, set to 8G</span></p>
</div>
<div id="_mcePaste"><span style="font-size: 13.3333px;">innodb_flush_log_at_trx_commit =0 </span></div>
<div><span style="font-size: 13.3333px;">Setting this to 0 will have a huge performance improvement, however your data is at somewhat more if you have a hardware failure</span></div>
<div><span style="font-size: 13.3333px;"><br />
</span></div>
<div id="_mcePaste">sync_binlog =0<br />
<span style="font-size: 13.3333px;">Setting this to 0 will have a huge performance improvement, however your data is at somewhat more if you have a hardware failure</span></div>
<div><span style="font-size: 13.3333px;"><br />
</span></div>
<div id="_mcePaste">innodb_flush_method=O_DIRECT<br />
On many systems, this will provide a performance improvement.  However, this can actually have a negative affect, so make sure you test appropriately.</div>
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://www.prodromus.com/2010/06/02/mysql-disabling-binary-logging-for-insert-and-update">MySQL &#8211; Disabling Binary Logging for INSERT and UPDATE</a> (prodromus.com)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.prodromus.com/2010/08/20/top-my-cnf-optimizations-for-innodb/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

