When you need to backup a MySQL database and no phpMyAdmin or SSH available, you can use a PHP script with exec function.
<?php
exec("mysqldump --opt -u DB_USER -p'DB_PASSWORD' DB_NAME --result-file=DB_NAME.sql 2>&1", $result, $rval);
if ($rval === 0) {
echo "Backup successful!";
} else {
echo "Backup failed! Verify Database credentials.";
echo "<pre style='color:red'>";
foreach ($result as $line) {
echo $line . "\n";
}
}
In the above code, replace DB_USER, DB_PASSWORD and DB_NAME with actual database user, password and database name.
You can execute this program by going to your website and accessing the PHP file.
Backup will be saved in current directory with .sql extension.
Back to MySQL Backup
Leave a Reply