0

I am trying to import a .sql file to mysql database. The size of mysql file is around 90MB.

I also found a similar question how to import .sql file in mysql database using php

I am using this script which is similar to the other one

$mysqlDatabaseName = 'db_test';
$mysqlUserName = 'db_dev';
$mysqlPassword = '1234abcd';
$mysqlHostName = 'localhost';
$mysqlImportFilename = 'dbbackup.sql';
$command = 'mysql -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' < ' .$mysqlImportFilename;
    exec($command,$output = array(),$worked);
    switch($worked){
        case 0:
            echo "Import file ".$mysqlImportFilename." successfully imported to database ".mysqlDatabaseName.";
        break;
        case 1:
            echo 'There was an error during import. Please make sure the import file is saved in the same folder as this script.';
        break;
    }

I am getting the following error

There was an error during import. Please make sure the import file is saved in the same folder as this script.

How can i fix it ??

Community
  • 1
  • 1
Yunus Aslam
  • 2,447
  • 4
  • 25
  • 39
  • 2
    What does `$output` contain? (That error is from the script: clearly whomever wrote it through that was the only reason it could fail.) – Richard May 05 '15 at 12:03
  • can you var_dump the return of 'which mysql' command and give it here ? maybe your mysql executable isnt in your PATH – Bobot May 05 '15 at 12:03
  • as i tried with sample data it works for the above code... When already data exist in the database, case 1 will execute in my opinion – Jagadeesh May 05 '15 at 12:11
  • @jagadeesh, you mean that the database should not be present there prior to running the script ?? – Yunus Aslam May 05 '15 at 12:34
  • Do you absolutely have to use PHP to import the file? It would be so much easier to use the command line or even *PHPMyAdmin* which has an upload feature – Phil May 05 '15 at 22:45
  • @illusion, nope database must present with no tables – Jagadeesh May 06 '15 at 04:58
  • @Phil.. I have to use php. My Clients wants a button which when clicked will copy the live database to a development database. In this way he can have a back up whenever he wants. – Yunus Aslam May 06 '15 at 06:08
  • As far as I know, the above script is not working due to the large size of the database. – Yunus Aslam May 06 '15 at 06:09

1 Answers1

0

Check the file system path of your dump file and place it in this line of the code your regarded:

$mysqlImportFilename = '/path/to/the/file/dbbackup.sql';

For large size: Increase your some of your PHP settings, php.ini, such as memory limit and maximum execution time

Community
  • 1
  • 1
SaidbakR
  • 13,303
  • 20
  • 101
  • 195
  • @SEMSEM, I already tries this. I added $_SERVER['DOCUMENT_ROOT'] and also tries with a hard coded path to the file. Relative, absolute, I tried almost every way. But still giving the same issue. may be the file size is large so it is giving that error. – Yunus Aslam May 08 '15 at 05:21
  • Please update your question and show what do you have tried for the path of the file? By the way, what's the OS? @Illusion – SaidbakR May 08 '15 at 11:52