Answer the question
In order to leave comments, you need to log in
How to backup mysql database using php?
Hey!
I need to backup/dump a database using php.
I tried this solution but none of them helped:
//разумеется тут данные свои, имя пользователя, пароль и название бд
exec("mysqldump --user={$user} --password={$pass} --host={$host} {$database} --result-file={$dir} 2>&1", $output);
$backup_file = $dbname . date("Y-m-d-H-i-s") . '.gz';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass ". "test_db | gzip > $backup_file";
system($command);
exec('mysqldump --user=... --password=... --host=... DB_NAME > /path/to/output/file.sql');
Answer the question
In order to leave comments, you need to log in
For you should specify the path to the executable file:
$path = 'C:\path\to\mysqldump\';
exec("{$path}mysqldump --user={$user} --password={$pass} --host={$host} {$database} --result-file={$dir} 2>&1", $output);
And if the author's path changes, then what should he do? At one time, for myself, I wrote a script that made a backup of a database, or a table, or the entire server. I spent two days on this, but it was worth it. So I recommend that you write the same script for yourself and then everything will be ok. The logic is simple. You need to create some functions. One will prepare the table, the other will prepare the data from the table, and the third will collect it all into one file.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question