我被要求使用php脚本而不是phpmyadmin创建一个将其结构和数据导出并导入mysql数据库的.sql文件,以使用户能够备份其数据?
有人知道该怎么做吗?
提前致谢
http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/using-php-to-backup- mysql-databases.aspx
要么
$tableName = 'mypet'; $backupFile = 'backup/mypet.sql'; $query = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName"; $result = mysql_query($query);
$backupFile = $dbname . date("Y-m-d-H-i-s") . '.gz'; $command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile"; system($command);