Import And Export Mysql Heavy Database

February 3, 2012 | In: MySql

Exporting and Importing database through PhpMyadmin is only good if you have small database. But you want to import and export big database then it is not possible. Here I show you script which is easily import and export heavy mysql database.


Import big mysql database

<?php
$mysqlDatabaseName ='MyDBName';
$mysqlUserName ='username';
$mysqlPassword ='yourPassword';
$mysqlHostName ='localhost';
$mysqlImportFilename ='db.sql';


$command='mysql -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' < ' .$mysqlImportFilename;
exec($command,$output=array(),$worked);
switch($worked){
    case 0:
        echo 'Import file <b>' .$mysqlImportFilename .'</b> successfully imported to database <b>' .$mysqlDatabaseName .'</b>';
        break;
    case 1:
        echo 'Error during import. Please make sure the import file is saved in the same folder as this script and check your mysql details like username, password, host and database name.';
        break;
}
?>


Export big database

<?php
$mysqlDatabaseName ='MyDBName';
$mysqlUserName ='username';
$mysqlPassword ='yourPassword';
$mysqlHostName ='localhost';
$mysqlExportPath ='db.sql';


$command='mysqldump --opt -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' > ~/' .$mysqlExportPath;
exec($command,$output=array(),$worked);
switch($worked){
    case 0:
        echo 'Database <b>' .$mysqlDatabaseName .'</b> successfully exported to <b>~/' .$mysqlExportPath .'</b>';
        break;
    case 1:
        echo 'Warning during the export of <b>' .$mysqlDatabaseName .'</b> to <b>~/' .$mysqlExportPath .'</b>';
        break;
    case 2:
        echo 'Error during export. Please check your check your mysql details like username, password, host and database name.';
        break;
}
?>

Comments

comments

Leave a Reply

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

*


*

 

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Categories

PSD to Magento Advertisement Advertisement Advertisement