Jump to content

Exporting mySQL data as a .TXT or .SQL file for backup


Recommended Posts

Hello:

 

I have a question and I think this is where to ask it.

 

I want to add a feature in my admin panel that is a link that - when click - will export all the data from a mySQL database as a .TXT or .SQL (preferred) and open it in a "Save As" prompt box so the admin can save a copy to his or her computer.

 

Basically, I want the admin to download a copy of the database each time they make an update so he or she has a current copy of the database stored as a backup on his or her local machine.

 

Can this be done? If so, how?

 

My GOOGLE searches have not produced any results for this.

 

Thanks.

Hi:

 

Thanks for the reply, but I'm not sure what you mean.

 

Something like:

 

Export.php

<?php

SELECT myDataBase INTO OUTFILE 'file_name' 

?>


Admin.php

<a href="Export.php">Export Database</a>

 

??

 

Sorry, a little confused ..

 

 

 

 

 

 

 

 

 

OK, I see what you mean .. but what if I want to do all the tables, not just one.

 

Meaning, I want to export the whole database as one file.

 

Also, is there a trick to add the date and time to each file, so it can be easy to find by date and time.

 

Thanks very much!

to dump all of your tables into a file you would write

$table_dump = mysql_query("select * INTO OUTFILE '/example/path/file.txt'") or die("unable to move data");

 

change the table_name to *...teling it to select all of the tables instead of specified ones..hope this helps

Hi:

 

Maybe I am not understanding it properly ..

 

Do I need to do soemthing like this:

<?php

include('../include/myConn.php');

$table_dump = mysql_query("SELECT * INTO OUTFILE 'DataBaseBackUp.txt'") or die("unable to move data");

while($result=mysql_fetch_array($query))

echo ". $result().";

?>

 

Just using the one line produced "unable to move data" ..

 

As does the above code ...

 

Do I somehow need to write it out into the file?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.