Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,655 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,155 people online right now. Registration is fast and FREE... Join Now!




how to backup table with data

 
Reply to this topicStart new topic

how to backup table with data

kummu4help
post 20 Aug, 2008 - 09:40 PM
Post #1


D.I.C Head

Group Icon
Joined: 4 Aug, 2008
Posts: 153



Dream Kudos: 25
My Contributions


Hi all,
I know, in oracle we have import/export to back up table with data.is there anything like that in MYSQL. so that i can backup my table and table data.

also when i used import/export i got a huge file above 700mb size.
i don't want such a huge file.i need a tiny file that backups only my table and it's data.

i'm sure my table has lessthan 30 rows.so i con't bare such a huge size.

Also is there any command to view my create table command that i used to create my table.i mean to say 1st i created a table employee with
create employee(.......);

so after that is there any command to view the above create command
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 21 Aug, 2008 - 12:09 AM
Post #2


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


In mysql you should be able to dump the database to a flat file with the command mysqldump.

The file can then be transported to backup storage, & later reloaded if need be.
User is offlineProfile CardPM

Go to the top of the page

pemcconnell
post 21 Aug, 2008 - 01:49 AM
Post #3


D.I.C Regular

Group Icon
Joined: 5 Aug, 2008
Posts: 394



Thanked 35 times

Dream Kudos: 75
My Contributions


How the McLuvin did you end up with a 700mb file with a database table with only 30 rows?

Anywho...

The following code will allow you to build an admin page where you can export individual tables into a file. You'll probibly want to modify the code to suit your needs, and add in data to your database to allow for a dynamic database restore section, but it's all up to you.

The code assumes you already have an active database connection and that you will be wrapping certain sections in conditions, e.g. isset($_POST) so that it doesn't execute every time the page loads.

You can use this to get a list of your database tables:

CODE

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="sel_bak" id="sel_bak">
<?php
$sql = mysql_query('SHOW TABLES');
while($row = mysql_fetch_array($sql, MYSQL_ASSOC)){
    echo '<option value="'.$row[$dbasename].'">'.$row[$dbasename].'</option>'."\n";
}
?>
</form>


Then this to get that tables data into a file:

CODE

<?php
mysql_query("SELECT * INTO OUTFILE 'mytablebackup.sql' FROM ".$_POST['sel_bak']);
?>


And just because I'm a nice guy, here's the code to 'restore' that information:

CODE

<?php
$dbTable = $_POST['sel_bak'];
mysql_query("LOAD DATA INFILE 'mytablebackup.sql' INTO TABLE $dbTable";
?>


Enjoy smile.gif

This post has been edited by pemcconnell: 21 Aug, 2008 - 01:53 AM
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 21 Aug, 2008 - 01:53 AM
Post #4


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


QUOTE(pemcconnell @ 21 Aug, 2008 - 05:49 AM) *

How the McLuvin did you end up with a 700mb file with a database table with only 30 rows?

Too many varchars.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 05:26AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month