<?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>Technology: Learn and Share &#187; MySQL backup</title>
	<atom:link href="http://crazytoon.com/category/mysql-backup/feed/" rel="self" type="application/rss+xml" />
	<link>http://crazytoon.com</link>
	<description>Enterprise level solutions, LAMP, Linux, Apache, MySQL, PHP, Perl, Windows, Cache, Optimization</description>
	<lastBuildDate>Fri, 16 Jul 2010 20:24:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Oh dear MySQL slave, where did you put those rows?</title>
		<link>http://crazytoon.com/2008/05/17/mysql-missing-data-on-slave-mysql-replicatio/</link>
		<comments>http://crazytoon.com/2008/05/17/mysql-missing-data-on-slave-mysql-replicatio/#comments</comments>
		<pubDate>Sat, 17 May 2008 10:35:00 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[uh...]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=75</guid>
		<description><![CDATA[I need help from my fellow mysql users.  I know some of the people who read this are alot better then me with mysql so hopefully you can help  
So today we decided that we are going to migrate one of our master database servers to new hardware.  Since we got the hardware this [...]]]></description>
			<content:encoded><![CDATA[<p>I need help from my fellow mysql users.  I know some of the people who read this are alot better then me with mysql so hopefully you can help <img src='http://crazytoon.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So today we decided that we are going to migrate one of our master database servers to new hardware.  Since we got the hardware this morning and we wanted to move on to it asap, we decided that we will take our slave down, copy data from it, and bring it up on future master server.  At that point, we will let it run as slave to the current master server until its time for us to take it down.  Reason we did that instead of mysqldump/import was to avoid the lag mysqldump creates on our server.</p>
<p>After we did all this and put up the new master server, we started to notice odd issues.  After looking around and comparing old db with new, we found out that new db was missing data.  How it happened is beyond me and is the reason why I am writing this.  We never had issues with the slave which would cause data to be lost; so what happened to those missing rows?  Is this something which is common?  Can we not trust our slave enough to use it as master if master died?  Can we not run backups off the slave with confident that our data is protected and up to date so to keep load down on our master?  All these questions which keep me awake and wondering&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/05/17/mysql-missing-data-on-slave-mysql-replicatio/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>MySQL:  How do you set up master-slave replication in MySQL? (CentOS, RHEL, Fedora)</title>
		<link>http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/</link>
		<comments>http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 03:12:57 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[MySQL cluster]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/</guid>
		<description><![CDATA[Before we go into how to set up master-slave replication in MySQL, let us talk about some of the reasons I have set up master-slave replication using MySQL.
1)    Offload some of the queries from one server to another and spread the load:  One of the biggest advantages to have master-slave set [...]]]></description>
			<content:encoded><![CDATA[<p>Before we go into how to set up master-slave replication in MySQL, let us talk about some of the reasons I have set up master-slave replication using MySQL.</p>
<p>1)    Offload some of the queries from one server to another and spread the load:  One of the biggest advantages to have master-slave set up in MySQL is to be able to use master for all of the inserts and send some, if not all, select queries to slave.  This will most probably speed up your application without having to diving into optimizing all the queries or buying more hardware.</p>
<p>2)    Do backups from slave:  One of the advantages people overlook is that you can use MySQL slave to do backups from.  That way site is not affected at all when doing backups.  This becomes a big deal when your database has grown to multiple gigs and every time you do backups using mysqldump, site lags when table locks happen.  For some sites, this could mean that site goes down for few secs to minutes.  If you have slave, you just take slave out of rotation (should be built into code) and run backups off the slave.  You can even stop slave MySQL instance and copy the var folder instead of doing mysqldump.</p>
<p>Ok let us dive into how to setup master-slave replication under MySQL.  There are many configuration changes you can do to optimize your MySQL set up.  I will just touch on very basic ones to get the replication to work.  Here are some assumptions:</p>
<blockquote><p>Master server ip:  10.0.0.1<br />
Slave server ip:  10.0.0.2<br />
Slave username:  slaveuser<br />
Slave pw:  slavepw<br />
Your data directory is:  /usr/local/mysql/var/</p></blockquote>
<p>Put the following in your master my.cnf file under [mysqld] section:</p>
<p><code># changes made to do master<br />
server-id           = 1<br />
relay-log           = /usr/local/mysql/var/mysql-relay-bin<br />
relay-log-index     = /usr/local/mysql/var/mysql-relay-bin.index<br />
log-error           = /usr/local/mysql/var/mysql.err<br />
master-info-file    = /usr/local/mysql/var/mysql-master.info<br />
relay-log-info-file = /usr/local/mysql/var/mysql-relay-log.info<br />
datadir             = /usr/local/mysql/var<br />
log-bin             = /usr/local/mysql/var/mysql-bin<br />
# end master</code></p>
<p>Copy the following to slave&#8217;s my.cnf under [mysqld] section:</p>
<p><code># changes made to do slave<br />
server-id           = 2<br />
relay-log           = /usr/local/mysql/var/mysql-relay-bin<br />
relay-log-index     = /usr/local/mysql/var/mysql-relay-bin.index<br />
log-error           = /usr/local/mysql/var/mysql.err<br />
master-info-file    = /usr/local/mysql/var/mysql-master.info<br />
relay-log-info-file = /usr/local/mysql/var/mysql-relay-log.info<br />
datadir             = /usr/local/mysql/var<br />
# end slave setup</code></p>
<p>Create user on master:<br />
<code>mysql&gt; grant replication slave on *.* to slaveuser@'10.0.0.2' identified by 'slavepw';</code></p>
<p>Do a dump of data to move to slave<br />
<code>mysqldump -u root --all-databases --single-transaction --master-data=1 &gt; masterdump.sql</code></p>
<p>import dump on slave<br />
<code>mysql &lt; masterdump.sql</code></p>
<p>After dump is imported go in to mysql client by typing mysql.  Let us tell the slave which master to connect to and what login/password to use:<br />
<code>mysql&gt; CHANGE MASTER TO MASTER_HOST='10.0.0.1',  MASTER_USER='slaveuser', MASTER_PASSWORD='slavepw';</code></p>
<p>Let us start the slave:<br />
<code>mysql&gt; start slave;</code></p>
<p>You can check the status of the slave by typing<br />
<code>mysql&gt; show slave status\G</code></p>
<p>The last row tells you how many seconds its behind the master.  Don’t worry if it doesn’t say 0, the number should be going down over time until it catches up with master (at that time it will show Seconds_Behind_Master: 0)  If it shows NULL, it could be that slave is not started (you can start by typing:  start slave) or it could be that it ran into an error (shows up in Last_errno: and Last_error under show slave status\G).</p>
<p>Related posts:</p>
<ul>
<li><a href="http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/" title="How do I dump all tables in a database into separate files?" target="_blank">How do I dump all tables in a database into separate files?</a></li>
<li><a href="http://crazytoon.com/2007/11/28/mysql-how-do-i-import-individual-table-dump-files-in-to-mysql-using-shell-script/" title="How do I import individual table dump files in to MySQL using shell script?" target="_blank">How do I import individual table dump files in to MySQL using shell script?</a></li>
<li><a href="http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/" title="MySQL backups using mysqldump" target="_blank">MySQL backups using mysqldump</a></li>
</ul>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2008/01/29/mysql-how-do-you-set-up-masterslave-replication-in-mysql-centos-rhel-fedora/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>MySQL:  How do I import individual table dump files in to MySQL using shell script?</title>
		<link>http://crazytoon.com/2007/11/28/mysql-how-do-i-import-individual-table-dump-files-in-to-mysql-using-shell-script/</link>
		<comments>http://crazytoon.com/2007/11/28/mysql-how-do-i-import-individual-table-dump-files-in-to-mysql-using-shell-script/#comments</comments>
		<pubDate>Thu, 29 Nov 2007 03:35:49 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[Notes for self]]></category>
		<category><![CDATA[Redhat]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/11/28/mysql-how-do-i-import-individual-table-dump-files-in-to-mysql-using-shell-script/</guid>
		<description><![CDATA[After I wrote the post: How do I dump all tables in a database into separate files? I got emails from couple people asking how to import the individual table files back in to MySQL.  First way to import each sql file created by  the post is to import each file individually by [...]]]></description>
			<content:encoded><![CDATA[<p>After I wrote the post: <a href="http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/" rel="bookmark" title="MySQL:  How do I dump all tables in a database into separate files?">How do I dump all tables in a database into separate files?</a> I got emails from couple people asking how to import the individual table files back in to MySQL.  First way to import each sql file created by  <a href="http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/" rel="bookmark" title="MySQL:  How do I dump all tables in a database into separate files?">the post</a> is to import each file individually by typing:<code>mysql db_name &lt; table1.sql</code>  This will work as long as you are only importing few files.  But if you need to import all of the files in the directory, which could be in 100&#8217;s, this method does not scale well.  To achieve this I wrote a shell script which does the work for me.  Of course, there are other ways to do this and I am only showing you one way of doing it.  This works for me so here it is:</p>
<p><code>#!/bin/bash<br />
db=$1<br />
if [ "$db" = "" ]; then<br />
echo "Usage: $0 db_name"<br />
exit 1<br />
fi<br />
mkdir done<br />
clear<br />
for sql_file in *.sql; do<br />
echo "Importing $sql_file";<br />
mysql $db&lt; $sql_file;<br />
mv $sql_file done;<br />
done</code></p>
<p>Related posts:</p>
<ul>
<li><a href="http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/" title="How do I dump all tables in a database into separate files?" target="_blank">How do I dump all tables in a database into separate files?</a></li>
<li><a href="http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/" title="MySQL backups using mysqldump" target="_blank">MySQL backups using mysqldump</a></li>
</ul>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/11/28/mysql-how-do-i-import-individual-table-dump-files-in-to-mysql-using-shell-script/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>MySQL:  How do I dump all tables in a database into separate files?</title>
		<link>http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/</link>
		<comments>http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/#comments</comments>
		<pubDate>Tue, 27 Nov 2007 00:22:53 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/</guid>
		<description><![CDATA[There have been numerous occasions where I needed to make backups of individual tables from selected database.  Usually I can achieve this by typing:
mysqldump database_name table1 &#62; table1.sql
mysqldump database_name table2 &#62; table2.sql

This could be very painful if you have 10’s or 100’s of tables. Until today, I never ran into a situation where I [...]]]></description>
			<content:encoded><![CDATA[<p>There have been numerous occasions where I needed to make backups of individual tables from selected database.  Usually I can achieve this by typing:</p>
<p><code>mysqldump database_name table1 &gt; table1.sql<br />
mysqldump database_name table2 &gt; table2.sql<br />
</code><br />
This could be very painful if you have 10’s or 100’s of tables. Until today, I never ran into a situation where I had to deal with dumping more than few tables at a time.   Today I had to do a dump of 181 tables.  I was not going to sit there and type in that command with 181 table names.  It is not just time consuming but it is also stupid.  So I wrote this script to help me with this task.  We still use mysqldump command as described above, except we do it programmatically to make it easier on us:</p>
<p><code>#!/bin/bash<br />
db=$1<br />
if [ "$db" = "" ]; then<br />
echo "Usage: $0 db_name"<br />
exit 1<br />
fi<br />
mkdir $$<br />
cd $$<br />
clear<br />
for table in `mysql $db -e 'show tables' | egrep -v 'Tables_in_' `; do<br />
echo "Dumping $table"<br />
mysqldump --opt -Q $db $table &gt; $table.sql<br />
done<br />
if [ "$table" = "" ]; then<br />
echo "No tables found in db:  $db"<br />
fi</code></p>
<p>You can also compress your files by adding bzip2, zip or any other compression commands after mysqldump command.  Here is the same script with bzip2 command added:<br />
<code>#!/bin/bash<br />
db=$1<br />
if [ "$db" = "" ]; then<br />
echo "Usage: $0 db_name"<br />
exit 1<br />
fi<br />
mkdir $$<br />
cd $$<br />
clear<br />
for table in `mysql $db -e 'show tables' | egrep -v 'Tables_in_' `; do<br />
echo "Dumping $table"<br />
mysqldump --opt -Q $db $table &gt; $table.sql<br />
bzip2 $table.sql<br />
done<br />
if [ "$table" = "" ]; then<br />
echo "No tables found in db:  $db"<br />
fi</code></p>
<p>I do not recommend doing compression on a production server since most compression program put descent amount of load on the server.  Also note that this will delay your dump considerably.  You may also want to use different parameters for running mysqldump.  Type <a href="http://www.lamp-tips.com/man-pages/mysqldump/" title="man mysqldump - man page for mysqldump" target="_blank"><code>man mysqldump</code></a> in your shell to read more.</p>
<p>Related posts:</p>
<ul>
<li><a href="http://crazytoon.com/2007/03/19/mysql-database-backup-file-compression-gzip-vs-bzip2/" target="_blank" title="MySQL database backup file compress gzip vs bzip2">MySQL database backup file compress gzip vs bzip2</a></li>
<li><a href="http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/" title="MySQL backups using mysqldump" target="_blank">MySQL backups using mysqldump</a></li>
</ul>
<p>————————————-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/11/26/mysql-how-do-i-dump-all-tables-in-a-database-into-separate-files/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>MySQL:  InnoDB: ERROR: the age of the last checkpoint is [number]</title>
		<link>http://crazytoon.com/2007/08/16/mysql-innodb-error-the-age-of-the-last-checkpoint-is-number/</link>
		<comments>http://crazytoon.com/2007/08/16/mysql-innodb-error-the-age-of-the-last-checkpoint-is-number/#comments</comments>
		<pubDate>Thu, 16 Aug 2007 21:32:59 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/08/16/mysql-innodb-error-the-age-of-the-last-checkpoint-is-number/</guid>
		<description><![CDATA[One of the mysql database servers I manage started to have issues with doing backups yesterday.  mysqldump was running but nothing was happening on the backup side.  I started to investigate to see why our full backups were failing.  I opened up the mysql error log file (mine is at:  /usr/local/mysql/var/hostname.err) [...]]]></description>
			<content:encoded><![CDATA[<p>One of the mysql database servers I manage started to have issues with doing backups yesterday.  mysqldump was running but nothing was happening on the backup side.  I started to investigate to see why our full backups were failing.  I opened up the mysql error log file (mine is at:  /usr/local/mysql/var/hostname.err) and notice there were many instances of following error.</p>
<p><code>070815 15:31:46  InnoDB: ERROR: the age of the last checkpoint is 9433957,<br />
InnoDB: which exceeds the log group capacity 9433498.<br />
InnoDB: If you are using big BLOB or TEXT rows, you must set the<br />
InnoDB: combined size of log files at least 10 times bigger than the<br />
InnoDB: largest such row.</code></p>
<p>I poked around and found out our log files were set to default (5 mb) and they needed to be increased.  After doing some calculations and research, I decided going to 50 mb at this point would be a good way to go.   So I made the change in my.cnf file and added:  <code>innodb_log_file_size = 50M </code></p>
<p>I then stopped our mysql server and restarted it.  And to my horror I saw following error messages show up in the mysql error logs:</p>
<p><code>070815 17:37:40 [ERROR] /usr/local/mysql/libexec/mysqld: Incorrect information in file: './dbname/table_name.frm'<br />
070815 17:37:40 [ERROR] /usr/local/mysql/libexec/mysqld: Incorrect information in file: './dbname/table_name.frm'</code></p>
<p>I stopped the mysql server right away.  I then remember, by help of a friend, that I have to remove the old log files if I change the size by changing <code>innodb_log_file_size</code>.  So I issued a command:  <code>mv ib_logfile? ..</code></p>
<p>This command moves both ib_logfile1 and ib_logfile2 down one directory.  I didn&#8217;t want to just remove &#8216;em so instead I moved them.  After that, I restarted mysql again and to my comfort, everything came back up without errors.  So lesson learned:  if you change ib_logfile size by using  <code>innodb_log_file_size</code> setting, make sure you move existing log files before you start mysql again.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
<small>DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. <strong>Use at your own risk</strong>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/08/16/mysql-innodb-error-the-age-of-the-last-checkpoint-is-number/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MySQL:  ibdata files do not shrink on database deletion [innodb]</title>
		<link>http://crazytoon.com/2007/04/03/mysql-ibdata-files-do-not-shrink-on-database-deletion-innodb/</link>
		<comments>http://crazytoon.com/2007/04/03/mysql-ibdata-files-do-not-shrink-on-database-deletion-innodb/#comments</comments>
		<pubDate>Tue, 03 Apr 2007 23:07:03 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[System admin]]></category>
		<category><![CDATA[innodb]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/04/03/mysql-ibdata-files-do-not-shrink-on-database-deletion-innodb/</guid>
		<description><![CDATA[One very interesting thing I noticed with MySQL was that if you delete a database, ibdata file doesn&#8217;t shrink by that much space to minimize disk usage.  I deleted the database and checked usage of /usr/local/mysql/var folder and noticed that ibdata file is still the same size.  So the problem I face now [...]]]></description>
			<content:encoded><![CDATA[<p>One very interesting thing I noticed with MySQL was that if you delete a database, ibdata file doesn&#8217;t shrink by that much space to minimize disk usage.  I deleted the database and checked usage of /usr/local/mysql/var folder and noticed that ibdata file is still the same size.  So the problem I face now is, how do I claim back this space?</p>
<p>After searching for a bit on google about this problem, apparently only way you can do that is by exporting your mysql databases, delete ibdata1 file, import databases.  This creates new ibdata file with correct space usage.  Atleast there is a way to get around this issue.  But honestly, too much pain on production boxes where we might be trying to remove old databases to reclaim some of the hard drive space.</p>
<p>An preventive measure one can use is to use option: <code>innodb_file_per_table</code> (&#8216;put innodb_file_per_table&#8217; in your my.cnf file under [mysqld] section).  This will create individual files for tables under database directory.  So now when I delete the database, all the space is returned since the directory is now deleted along with database along with all the tables inside the directory.  In my test after you put option <code>innodb_file_per_table </code>your my.cnf, you will have to still do export/import to be able to minimize disk usage and have the ability to delete database at your leisure without worrying about reclaiming the disk space.  Here are the steps I took.  DISCLAIMER:  Please make backup of your data and use following steps at your own risk.  Doing it on test server is <strong>HIGHLY</strong> recommended.  Please don&#8217;t come back and tell me that you lost your data because you followed my steps.  They work for <em>me</em> and they <em>may not </em>work for <em>you</em>!</p>
<p>That said, here are the steps:</p>
<ol>
<li>Add  <code>innodb_file_per_table </code>in your my.cnf file under [mysqld] section</li>
<li>run following commands at the prompt.  Your path to binaries might be different.</li>
<p><code>#note:  following assumes you are logged in as root<br />
mkdir -p /temp  #temp dir to save our sql dump<br />
#lets make a backup of current database. -p is used if there is pw set<br />
/usr/local/mysql/bin/mysqldump -R -q -p --all-databases &gt; /temp/all.sql<br />
#stop mysql so we can remove all the files in the dir<br />
/etc/init.d/mysql stop<br />
rm -fr /usr/local/mysql/var/* #remove all the files<br />
/usr/local/mysql/bin/mysql_install_db  #install default dbs<br />
#change ownership so mysql user can read/write to/from files<br />
chown -R mysql.mysql /usr/local/mysql/var/<br />
#start mysql so we can import our dump<br />
/etc/init.d/mysql start<br />
#note there is no -p since defaults don't have mysql pw set<br />
/usr/local/mysql/bin/mysql &lt; /temp/all.sql<br />
/etc/init.d/mysql restart</code></ol>
<p>This should be all you need to do.  At this point when you remove a database, it will delete the directory of the db and all the data contained within which in turn will give you your disk space back.</p>
<p>REMEMBER:  <strong>Backup your data</strong> and be smart about using code found on internet.  If you don&#8217;t know what you are doing, hire a consultant who does.</p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/04/03/mysql-ibdata-files-do-not-shrink-on-database-deletion-innodb/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>MySQL database backup file compression:  gzip vs bzip2</title>
		<link>http://crazytoon.com/2007/03/19/mysql-database-backup-file-compression-gzip-vs-bzip2/</link>
		<comments>http://crazytoon.com/2007/03/19/mysql-database-backup-file-compression-gzip-vs-bzip2/#comments</comments>
		<pubDate>Tue, 20 Mar 2007 01:12:29 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[System admin]]></category>
		<category><![CDATA[uh...]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/03/19/mysql-database-backup-file-compression-gzip-vs-bzip2/</guid>
		<description><![CDATA[In one of my previous posts: MySQL backups, I talked about using a script for automating backups.  I show that we can use gzip to compress backup file to compress and save.  Since then, our backup file has been growing meg or two a day which is causing our backup files to get [...]]]></description>
			<content:encoded><![CDATA[<p>In one of my previous posts: <a href="http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/" title="MySQL Backups">MySQL backups</a>, I talked about using a script for automating backups.  I show that we can use gzip to compress backup file to compress and save.  Since then, our backup file has been growing meg or two a day which is causing our backup files to get bigger and bigger every day.  We keep hourly backups for a week so you can imagine space usage is quite high.</p>
<p>I went and did few tests to see if its beneficial for us to use Bzip2 instead of gzip.  I could&#8217;ve tried 7z also but that is not something installed on most linux machines I work on and I didn&#8217;t want use a solution which will require me to add more software.  Here are the results:</p>
<p>Original sql file size: 584M<br />
Using gzip: 166M<br />
Time spent on compressing 1 minute 25 secs<br />
Using bzip2:  125M<br />
Time spent on compressing 1 minute 50 secs</p>
<p>As we can see that it takes longer to compress but file size is much smaller (adds up fast for multiple backups).  As our database grows bigger and bigger, the size difference will matter quite a bit.  Since we also ftp the file off the server to onsite/offsite location hourly as well.</p>
<p>Does anybody know of any backup techniques which we can use for free and we can do incrementals with? comments are always welcome.  To learn more about gzip or bzip2, see <a href="http://www.lamp-tips.com/man-pages/gzip/" title="man gzip - man page for gzip" target="_blank">man gzip</a> or <a href="http://www.lamp-tips.com/man-pages/bzip2/" title="man bzip2 - man page for bzip2" target="_blank">man bzip2</a> respectively.</p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/03/19/mysql-database-backup-file-compression-gzip-vs-bzip2/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>MySQL backups using mysqldump</title>
		<link>http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/</link>
		<comments>http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/#comments</comments>
		<pubDate>Wed, 24 Jan 2007 00:03:28 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[Data Backup]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL backup]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/</guid>
		<description><![CDATA[MySQL backups are essential to running a site with MySQL backend.  Generally you can get away with doing nightly backups but on our site, due to couple issues we had in past, we are forced to do hourly backups of our db.
Intially I was doing backup by using: mysqldump dbname &#62; weekdayHour.dbname.sql  hourly. [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL backups are essential to running a site with MySQL backend.  Generally you can get away with doing nightly backups but on our site, due to couple issues we had in past, we are forced to do hourly backups of our db.</p>
<p>Intially I was doing backup by using: <em>mysqldump dbname &gt; weekdayHour.dbname.sql</em>  hourly.  This allowed us to have week worth of backups done every hour and auto overwriting old backups.  Eventually we added stored procedures and triggers to the mix and all of the sudden this dump wasn&#8217;t getting all the stored procedures and triggers.  So we started using mysqldump with -R parameter which in man states:</p>
<blockquote><p>Dump stored routines (functions and procedures) from the dumped databases.</p></blockquote>
<p>Recently when we started to see more and more traffic, we noticed that our server was under heavy load on the hour.  Ofcourse we quickly found it was due to mysqldump running on the hour which was causing the lag.  Eventually we had enough traffic on the site where this was causing connection problems with mysql.  So I went through man mysqldump again to find solution.  And thanks to those smart people in mysqldump dev team, there I found couple more parameters to make this backup process little less painful.  At this point we are using:  <em>mysqldump -R  -q &#8211;single-transaction &gt; weekdayHour.dbname.sql</em>  This seems to have decreased the load on the server and we haven&#8217;t got errors connecting to mysql.  Since we use innodb tables in this particular db, we could use <em>single-transaction</em> parameter.  Here is what our friendly man mysqldump has to say about these two parameters:</p>
<blockquote><p> -q    &#8230;This option is useful for dumping large tables. It forces mysqldump to retrieve rows for a table from the   server a row at a time rather than retrieving the entire row set and buffering it in memory before writing   it out&#8230;</p>
<p>&#8211;single-transaction   &#8230;This option issues a BEGIN SQL statement before dumping data from the server. It is useful only with transactional tables such as InnoDB and BDB, because then it dumps the consistent state of the database at the time when BEGIN was issued without blocking any applications&#8230;</p></blockquote>
<p>If you are thinking about using these two parameters, please spend couple minutes reading through man mysqldump and look at other notes which might pertain to your setup.</p>
<p>One last but very important thing we do after our backups are run is to move the new backup files off the server just in case server dies.  I achieved this by using ncftp package which includes ncftpput command line utility.  With ncftp, you can store ip/login/pw in a file and tell ncftp to use that for login information.  Lets look at the script as a whole:</p>
<p>NOTE:  comments in this script is for information purposes only.  You can remove them if you like</p>
<p><code>#!/bin/bash<br />
#<br />
#<a href="http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/">http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/</a><br />
#<br />
DATE=`date '+%u%H'` # this sets up weekly rotation of backup files<br />
BACKUP_DIR="/admin/backups/domain.com/" # this dir will be created if it doesn't exist<br />
HOST=`hostname` #you may want to hard code this if you hostname returns wrong information<br />
mkdir ${BACKUP_DIR}mysql/ -p<br />
/usr/local/mysql/bin/mysqldump -R  -q --single-transaction --databases dbname1 dbname2 -ppassword &gt; ${BACKUP_DIR}mysql/$HOST$DATE.sql<br />
rm ${BACKUP_DIR}mysql/$HOST$DATE.sql.gz &gt; /dev/null 2&gt;&amp;1<br />
gzip -9 ${BACKUP_DIR}mysql/$HOST$DATE.sql &gt; /dev/null 2&gt;&amp;1<br />
/usr/bin/ncftpput -R -f ${BACKUP_DIR}hostinfo / ${BACKUP_DIR}mysql/$HOST$DATE.sql.gz</code></p>
<p>This is what your hostinfo file should contain (just make sure you edit it and put your own server ip, username, and password):<br />
<code>host 123.123.123.123<br />
user loginname<br />
pass loginpassword</code></p>
<p>To read more about mysqldump, see <a href="http://www.lamp-tips.com/man-pages/mysqldump/" title="man mysqldump - man page for mysqldump" target="_blank">man mysqldump</a></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/01/23/mysql-backups-using-mysqldump/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
