Prerequisite: With SSH landing privileges
Work Step:
Download software putty, set SSH login option
After landing, enter your home page directory * (accessible via FTP)
Executes the mysqldump command to perform a database backup, while the Mysqlrestore command restores the database.
Format:
pXXXXXXX@kundenserver:~ > mysqldump -hdbXX.puretec.de -upXXXXXXX -p******** dbXXXXXXX > dbXXXXXXXX.sql
pXXXXXXX@kundenserver:~ > mysql -hdbXX.puretec.de -upXXXXXXX -p******** dbXXXXXXX < dbXXXXXXXX.sql
After the mysqldump is executed, a backup file is generated in the current directory (size and database size)
Download the backed up database package via FTP
Restore database work contrary to the above two parts
You can also write a PHP script to do the above:
Backing up files
include "../config.php";
MYSQL_CONNECT($dbhost, $dbuser, $dbpw) or die ( "<H3>无法访问数据库</H3>");
MYSQL_SELECT_DB($dbname) or die ( "<H3>数据库尚未建立</H3>");
$path = getenv("DOCUMENT_ROOT")."/DB_backup";
$result = MYSQL_QUERY("SHOW TABLES");
$numrow = MYSQL_NUM_ROWS($result);
for($i = 0;$i < $numrow;$i++) {
$table = MYSQL_RESULT($result,$i);
echo "$table ... ";
system(sprintf("mysqldump --opt -h $dbhost -u $dbuser -p$dbpw $dbname $table | gzip > %s/$table.sql.gz",$path));
echo "DONE\n\n";
}
MYSQL_CLOSE();
Recover files
include "../config.php";
system(sprintf(
"gunzip -c %s/dump.sql.gz | mysql -h %s -u %s -p%s %s",
getenv("DOCUMENT_ROOT"),
$dbhost,
$dbuser,
$dbpw,
$dbname
));
echo "+DONE";