Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MYSQL dump and save 2

Status
Not open for further replies.

solex

Programmer
Joined
Feb 28, 2003
Messages
91
Location
GB
i need to make a script that will make a dump of the layout of tables and the data in them, and save this to a text file.

Is this possible?

thanx in advance

solex
 
This is a great way to make a nightly backup of the databases and content. You can put it in as a cron tab in any kind of *nix/linux context or write a little perl script that also rotates/gzips/etc.
 
i may sound stupid asking this, but how di i use the commands, in the web page you gave, in php?

thanx solex
 
You can execute the command through PHPs execute function.
There are several caveats here, since there is always a risk with executing shell functions from PHP through the web.
Another caveat is to be careful with not exposing the MySQL username and password through the code since you will have to hardcode it. You could also create a MySQL user that has just read privileges and is restricted to the server's IP as connection point.

If you don't worry about security concerns just use the command string in the exec() function.
 
ok, so if i connect to the data bace and do

$mysqldump = exec("mysqldump");

it should work?

how can i save the contence of $mysqldump in to a text file?

thanx for all your help the 3 of you.

SOLEX
 
You need not connect to the db for this.
ALl you need is execute it exactly the same way you would on the command line:
Code:
<?php
  exec(&quot;mysqldump -h hostname -u username -p password databasename > textfile.sql&quot;);
?>
Again, I would create a user that has only access privileges from localhost and SELECT privileges. Put the textfile with the path of the filesystem where you want it stored.
You can then later access is with FTP or PHPs file handling functions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top