Reputation: 41
I want single table (MySQL) backup/dump using PHP. Actually I am working on remote database server from my PC (XAMMP server is not installed on my PC). I tried following command:
$command = "mysqldump -u username -p databaname tablename > filepath";
Here password is empty (-p
), I execute it using system($command, $result);
result contains 1 and this command creates an empty file. I searched for this problem and found that there shouldn't be space between -ppassword
. I tried this but the problem is same. is there another way to do this without command in PHP or what should I fix in this command?
Upvotes: 1
Views: 122
Reputation: 1651
try
<?php
$filename = 'database_backup_'.date('G_a_m_d_y').' . sql';
$result = exec('mysqldump database_name table1 table2 table3 --password=your_pass --user=root --single-transaction >/var/backups/' . $filename, $output);
if(!empty($output)) {
var_dump($output);
}
Upvotes: 1
Reputation: 11
mysqldump -u yourUsername -p yourdatabasename yourtablename > yourdumptablename.sql
then hit enter so you ask for password of your db
Upvotes: 0