我有一台服务器,我可以访问 mysql 但不能访问 mysqlimport 或 mysqldump。它只是说“找不到命令”,而 whereis 什么也没报告。我尝试使用 PhpMyAdmin 转储数据库,但无法在另一台服务器上成功导入转储。我猜 phpMyAdmin 无法正确导出它(数据库有视图、过程、触发器等等——相当复杂的)。
我无法从“本地主机”外部访问数据库,也无法在服务器上安装任何东西。
有没有办法只用 mysql 命令导出数据库?或者其他方式来正确导出它?
使用此函数并传递合适的位置来存储文件
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.';
}
}
在我的 Debian 系统 (LMDE) 上,mysqldump 由 mysql-client-version pkg 安装。
在我的 RH 5.x 系统上,它是由 mysql pkg 安装的。
mysqldump 位于两者的 /usr/bin 中。那一定在你的路上。我认为您没有安装客户端。
要尝试的事情:
这应该是不可能的。希望您具有 root 访问权限,但不允许安装任何东西。