You are Here: FAQ ->Scripting & Programming->MySQL->Article #14


WebHosting 5.0 This article is for 1&1 Linux WebHosting only.


How to restore a Database from an SQL dump that has been GZiped




The following PHP Script will restore a backup of a MySQL Database in a GZip file

Please note
The SQL dump must be called dump.sql.gz and must be on the DOCUMENT_ROOT


<?php
  // Please Enter your Database details
  $host= 'dbxx.oneandone.co.uk';
  $user= 'dbxxxxxx';
  $pass= 'xxxxxxxx';
  $db=   'dbxxxxxxx';

  // GZip is unpacked and feed into the Database
  system(sprintf(
    'gunzip -c %s/dumpDB.sql.gz | mysql -h %s -u %s -p%s %s',
    getenv('DOCUMENT_ROOT'),
    $host,
    $user,
    $pass,
    $db
  ));
  echo '+DONE';
?>


If the script times out then you may have to do this using the SSH Command line interface.


Restore by SSH



If you have a Business Pro Package, Professional Package or a Managed Server then you can also do this using the Secure Shell interface. Log in and run the following commands.


pXXXXXXX@kundenserver:~ > mysql -hdbXX.oneandone.co.uk -upXXXXXXX -p******** dbXXXXXXX < dbXXXXXXXX.sql


(******** = your password)

If the SQL Dump is GZiped then you can use the following command:


pXXXXXXX@kundenserver:~ > gunzip -c dbXXXXXXX.sql.gz | mysql -hdbXX.oneandone.co.uk -upXXXXXXX -p******** dbXXXXXXX


For more information please see http://dev.mysql.com/doc/


Print Article
How useful was this article?
(From 5 = Very Useful to 1 = Not Very Useful at all):
1 2 3 4 5