简体   繁体   中英

Can I dump database with mysql (not mysqldump)?

I have a server where I have access to mysql but not mysqlimport or 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. I guess phpMyAdmin cannot export it properly (the database has views, procedures, triggers and such- quite complicated one).

I don't have access to the DB from outside the "localhost" and I cannot install anything on the server.

Is there a way to export the DB with just mysql command? 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.

On my RH 5.x system, it is installed by the mysql pkg.

mysqldump lives in /usr/bin on both. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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