I'm using laravel and mysql as database, and I want to make a backup database in hosting with one click button in html, but I wonder what is the best query for them instead of query all data in all table with loop, then insert it one by one to host with loop. Thanks before
Asked
Active
Viewed 1,023 times
-1
-
2Wat? you do mysqldump and specify the database, you dont loop or anything. – Xatenev Aug 11 '16 at 07:40
-
Oh my bad, I mean with code, not a command :) – user5436320 Aug 11 '16 at 09:30
-
1Also see: http://stackoverflow.com/questions/38655929/how-do-i-load-data-automatically-from-another-server-everyday/38656052#38656052 – e4c5 Aug 11 '16 at 14:10
1 Answers
3
Use mysqldump
$ mysqldump -h <host> -u <user> -p<password> <database_name> > backup.sql
This will create a sql file backup.sql
with all your data.
Note the missing space beween -p
and <password>.
It's okay to give the password interactively (in which case, you'll have to skip the <password>
part), but since you mentioned laravel in the question, I am assuming you want to code this and want it to be non-interactive.
EDIT: Using code
Execute the command with exec()
$cmd = "mysqldump -h <host> -u <user> -p<password> <database_name> > backup.sql";
exec($cmd, $output, $return_value);

linuxartisan
- 2,396
- 3
- 21
- 40
-
Thank you, but with code I mean, so I dont need to touch the command prompt :| – user5436320 Aug 11 '16 at 09:31
-