tags:

views:

93

answers:

2

hi, I am so worry :(

I dropped one of the tables from the database accidentally. fortunately, I have back-up. (I have used the "Auto backup for mysql")

The back-up of the table is stored as .txt file (56 Megabytes) on my PC.

I tried to import it by PhpMyAdmin and the import failed because the file is too large to import.

then I uploaded the file to /home/tablebk directory. I have some experiences in php. I know that I would import it with this code, but i don't know the sql statment for this import.

what is have to put as $line variable?

please help me :( :(

<?php

    $dbhost = 'localhost';          
$dbuser = 'mysite';         
$dbpw = 'password';         
$dbname = 'databasename';

$file = @fopen('country.txt', 'r');

if ($file)
{
    while (!feof($file))
    {
        $line = trim(fgets($file));
        $flag = mysql_query($line);

        if (isset($flag))
        {
            echo 'Insert Successfully<br />';
        }

        else
        {
            echo mysql_error() . '<br/>';
        }

        flush();
    }

    fclose($file);
}

echo '<br />End of File';

?>
A: 

Try BigDump, which solves the problem elegantly and reliably. It basically does what you want, but with more safety mechanisms and several ways to restart in the middle of the file. Also, it has beautiful progress indicators, and... oh, it's already written, so you don't need to write your own script. No need to reinvent the wheel. (I'm not affiliated with BigDump or its developer(s) in any way.)

MvanGeest
I tryed it , by when I go to http://mysite.com/Bigdump/bigdump.php , this page says: Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request.Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.
safaali
Have you inserted the database configuration as per the documentation on the page I linked to? Try reading the FAQs too.
MvanGeest
no I didn't changed that file, let me see :(
safaali
yep I inserted the host, database, username and password, bu still there is a Internal Server Error :((
safaali
Very interesting. What's your MySQL and PHP version? You can also try checking the Apache error log to see what the exact error is. There could be several reasons for this, like permission errors, forbidden directories, files changed during upload, PHP turned off for a specific directory, etc. Is the dump uploaded to that directory?
MvanGeest
I could finally run BigDump.php but my backup is .txt file and it compressed it to .gz file. BUT. it couldn't import it. says: BigDump: Staggered MySQL Dump Importer v0.32bProcessing file: cdb_posts.txt.gzStarting from line: 1Stopped at the line 301.At this place the current query includes more than 300 dump lines. That can happen if your dump file was created by some tool which doesn't place a semicolon followed by a linebreak at the end of each query, or if your dump contains extended inserts.
safaali
What it says is probably your problem: extended inserts. Un-gzip the file and check the text: is there an INSERT for each line? If not, extended inserts are preventing a smooth upload. You could try this perl script: http://platon.sk/cvs/cvs.php/scripts/perl/mysql/mysqldump-convert.pl. If you don't have any perl experience, contact an expert.
MvanGeest
+1  A: 

Why not use MySQL's batch commands:

shell> mysql db_name < text_file

mmattax
Most cheap hosting providers don't allow shell access, but it's certainly the fastest and most straightforward way.
MvanGeest
how can I go tho shell? it is a shared hosting, i have only access to phpmyadmin and home directory , please help :(
safaali
That's what I was afraid of... shell does not seem to be an option :(
MvanGeest