Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backup a mysql database and download as a file

Tags:

php

mysql

How to backup the mysql database and download it as a .sql file by using PHP Codes

like image 889
mrN Avatar asked Sep 20 '10 11:09

mrN


3 Answers

A very simple solution would be something like (first example): http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/using-php-to-backup-mysql-databases.aspx

Naturally this will only make a Data dump of the table.

What you could do is use this code:

http://snipplr.com/view/173/mysql-dump/

What this code does is actually gets a description of the table (i.e its structure), creates all the tables and pushes data. pretty much like any other tool does.

Then its just a matter of saving it from string to a file (file_put_contents() for instance or something similar, depending on your preference and need)

like image 172
Alexej Kubarev Avatar answered Oct 25 '22 21:10

Alexej Kubarev


Use phpmyadmin

Edit:

You can use shell_exec to execute this command

mysqldump -u username -p password database > file

This will generate a dump file,and then redirect user to this generated file.

like image 22
jmj Avatar answered Oct 25 '22 21:10

jmj


mysqldump -u username -p password database > file

Alternatively, phpMyAdmin can do this too with the Export tool.

like image 26
Delan Azabani Avatar answered Oct 25 '22 21:10

Delan Azabani