我有一个可以访问mysql的服务器,但没有mysqlimport或mysqldump。它只是说“命令找不到”,而这里什么也没有报告。我尝试用PhpMyAdmin转储数据库,但转储无法在另一台服务器上成功导入。我想phpMyAdmin无法正确地导出它(数据库有视图、过程、触发器等等--相当复杂的一个)。
我没有从"localhost“外部访问DB的权限,也无法在服务器上安装任何东西。
是否有一种只使用mysql命令导出DB的方法?或者其他适当导出它的方法
发布于 2013-07-18 14:49:36
在我的Debian系统(LMDE)上,mysqldump由mysql客户端版本pkg安装。
在我的RH 5.x系统上,它是由mysql pkg安装的。
mysqldump生活在/usr/bin中。那一定是在你的路上。我想你没有安装客户。
要尝试的事情:
这应该是不可能的。希望您有根访问权限,但只是不允许安装任何东西。
发布于 2013-07-18 13:07:46
使用此函数并传递适当的位置来存储文件。
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
$link = mysql_connect($host,$user,$pass);
$return = "";
mysql_select_db($name,$link);
//get all of the tables
if($tables == '*')
{
$tables = array();
$result = mysql_query('SHOW TABLES');
while($row = mysql_fetch_row($result))
{
$tables[] = $row[0];
}
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
//cycle through
foreach($tables as $table)
{
$result = mysql_query('SELECT * FROM '.$table);
$num_fields = mysql_num_fields($result);
$return.= 'DROP TABLE '.$table.';';
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
$return.= "\n\n".$row2[1].";\n\n";
for ($i = 0; $i < $num_fields; $i++)
{
while($row = mysql_fetch_row($result))
{
$return.= 'INSERT INTO '.$table.' VALUES(';
for($j=0; $j<$num_fields; $j++)
{
$row[$j] = addslashes($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 to desired location
$handle = fopen(date('d_M_Y_H_m_s').'.sql','w+');
fwrite($handle,$return);
fclose($handle);
if($return == true)
{
$_GET['msg']= 'Backup is successfull.';
}
else
{
$_GET['msg']= 'Backup is Not successfull.';
}
}https://stackoverflow.com/questions/17724162
复制相似问题