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 :
Filename:
imortdb.php

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

<?php
//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
switch($worked){
    case 0:
        echo 'Import file <b>' .$mysqlImportFilename .'</b> successfully imported to database <b>' .$mysqlDatabaseName .'</b>';
        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 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>';
        break;
}
?>

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.

Comments

Leave a Reply

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

18215