php - 如何使用php下载大型mysql数据库
问题描述
在我的情况下,数据库几乎超过 2GB,所以它花费了太多时间,所以如何分解它任何想法请帮助 `backup_tables('localhost','xyz','xyz','xyz');
函数backup_tables($host,$user,$pass,$name) { $link = mysqli_connect($host,$user,$pass,$name);
if($tables == '*')
{
$tables = array();
$result = mysqli_query($link, 'SHOW TABLES');
while($row = mysqli_fetch_row($result)){
$tables[] = $row[0];}
}
else{ $tables = is_array($tables) ? $tables : explode(',',$tables);}
//cycle through
foreach($tables as $table)
{
$result = mysqli_query($link, 'SELECT * FROM '.$table);
$num_fields = mysqli_num_fields($result);
$return.= 'DROP TABLE '.$table.';';
$row2 = mysqli_fetch_row(mysqli_query($link,'SHOW CREATE TABLE '.$table));
$return.= "\n\n".$row2[1].";\n\n";
for ($i = 0; $i < $num_fields; $i++)
{
while($row = mysqli_fetch_row($result))
{
$return.= 'INSERT INTO '.$table.' VALUES(';
for($j=0; $j < $num_fields; $j++)
{
$row[$j] = addslashes($row[$j]);
$row[$j] = ereg_replace("\n","\\n",$row[$j]);
if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
if ($j < ($num_fields-1)) { $return.= ','; }
}
$return.= ");\n";
}
}
$return.="\n\n\n";
}
// save file
$path = 'downloads/';
$handle = fopen($path.'db-backup-'.(md5(implode(',',$tables))).'.sql','w+');
$filewrite = fwrite($handle,$return);
$fileList = glob('downloads/*.sql');
echo $filename = basename($fileList['0']);
fclose($handle);`
解决方案
只需转到 phpmyadmin 并进行转储,最好的解决方案。
推荐阅读
- citations - 引用 Mendeley 的机构作者
- css - webpack:将全局样式文件导入所有组件
- javascript - 在两个 ajax 请求都完成后,这段代码片段如何运行最终函数?
- r - 如何将 Benjamini-Hochberge 校正的 p 值添加到箱线图中,而不是 R 中默认的“holm”校正 p 值?
- java - 如何在 javaparser 中使用 getRange 获取源代码
- encoding - 将 std::string 从 UTF8、UTF16、ISO88591 转换为十六进制
- mongodb - 如何配置mongodb索引以在特定类型的时间范围内按值排序?
- python - 在 python3 中使用 pickle 加载时的内存泄漏
- c++ - 在此代码中验证半径时遇到问题
- angular - 从服务访问模板引用