How to import large Dump mysql database file for mysql?

If you have big mysql database and you try to import using phpmyadmin, you may face lot's of trouble and it also takes too much time to upload large sql file from local to mysql server.

Example :

You can use below php script to import mysql file into database.

//ENTER THE database configuration at BELOW

$mysqlDatabaseName ='database-name';
$mysqlUserName ='root';
$mysqlPassword ='*****';
$mysqlHostName ='localhost';
$mysqlImportFilename ='mysql.sql'; // upload this mysql file into server using ftp
echo file_exists($mysqlImportFilename);
echo "<br>".$command='mysql -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' < ' .$mysqlImportFilename;

exec($command,$output=array(),$worked); // php will execute this mysql command to import data
    case 0:
        echo 'Import file <b>' .$mysqlImportFilename .'</b> successfully imported to database <b>' .$mysqlDatabaseName .'</b>';
    case 1:
        echo 'There was an error during import. Please make sure the import file is saved in the same folder as this script and check your values:<br/><br/><table><tr><td>MySQL Database Name:</td><td><b>' .$mysqlDatabaseName .'</b></td></tr><tr><td>MySQL User Name:</td><td><b>' .$mysqlUserName .'</b></td></tr><tr><td>MySQL Password:</td><td><b>NOTSHOWN</b></td></tr><tr><td>MySQL Host Name:</td><td><b>' .$mysqlHostName .'</b></td></tr><tr><td>MySQL Import Filename:</td><td><b>' .$mysqlImportFilename .'</b></td></tr></table>';

Note : You will have to upload both imortdb.php and mysql.sql file into same directory or you can upload mysql file in different directory by changing directory path in $mysqlImportFilename variable.
After configure above code, you will have to execute this file imortdb.php into web browser to import large mysql dump file into database.


Leave a Reply

Your email address will not be published. Required fields are marked *