简体   繁体   English

我可以使用mysql(而不是mysqldump)转储数据库吗?

[英]Can I dump database with mysql (not mysqldump)?

I have a server where I have access to mysql but not mysqlimport or mysqldump. 我有一个服务器,我可以访问mysql但不能访问mysqlimport或mysqldump。 It just says "command not found" and whereis reports nothing. 它只是说“命令未找到”而且哪里没有报告。 I tried dumping the database with PhpMyAdmin but the dump cannot be imported successfully on another server. 我尝试使用PhpMyAdmin转储数据库,但转储无法在另一台服务器上成功导入。 I guess phpMyAdmin cannot export it properly (the database has views, procedures, triggers and such- quite complicated one). 我猜phpMyAdmin无法正确导出它(数据库有视图,程序,触发器等 - 非常复杂的)。

I don't have access to the DB from outside the "localhost" and I cannot install anything on the server. 我无法从“localhost”外部访问数据库,我无法在服务器上安装任何东西。

Is there a way to export the DB with just mysql command? 有没有办法用mysql命令导出数据库? Or some other way to export it properly ? 或者其他一些方法来正确导出它?

Use this function and pass the suitable location to store the file 使用此功能并传递合适的位置来存储文件

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.'; 
    }   



}

On my Debian system (LMDE), mysqldump is installed by the mysql-client-version pkg. 在我的Debian系统(LMDE)上,mysqldump由mysql-client-version pkg安装。

On my RH 5.x system, it is installed by the mysql pkg. 在我的RH 5.x系统上,它由mysql pkg安装。

mysqldump lives in /usr/bin on both. mysqldump位于/ usr / bin上。 That must be in your path. 那必须在你的道路上。 I think you have no client installed. 我认为你没有安装客户端。

Things to try: 要尝试的事情:

This should be impossible wo root. 这根本不可能。 Hopefully you have root access, but are just not allowed to install anything. 希望你有root权限,但是不允许安装任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM