Import A Database
Introduction
First of all, you must provide:
1. The saved database file, called dump, obtained when the database is saved (see
BackupBaseMySQL or instructions on your program if you have created your database on your computer).
2. Access codes for your database (you have received them by e-mail from the creation of the database or the creation of your GP webhosting pack/plan).
It is equally as important to add the following line at the top of your saved file:
use name_of_your_database;
Where "name_of_your_database" corresponds to the database name where you import this data.
By script
Once you have the data described below, you can edit the script following this code:
In the script below, replace
database_name.sql with your file name,
server_sql by server name for which your database is installed,
database_name with your database name and
password with the password of your database.
In PHP (importbase.php):
echo "Your database is restoration is in progress.......";
system("cat database_name.sql | mysql --host=server_sql --user=data_base_name --password=password_of_database");
echo "Finished. Your database is now on the website.";
?>
In perl (importbase.cgi) :
- !/usr/bin/perl
print "Your database restoration is in progress.......";
system("cat name_of_database.sql | mysql --host=server_sql --user=user_name --password=password name_of_database");
print "It is finished. Your database is placed on your hosting.";
Upload the script if you have created it and the dump of your database in the WWW directory of your website and call your script with a navigator via this URL:
http://yourdomain.com/chemin_du_script/importbase.php
Notice : If your dump is compressed in the form of .sql.gz, place this command before the script:
system("gunzip nom_de_la_base.sql.gz");
Example :
In PHP :
echo "Decompression of file.....";
system("gunzip testbackup.sql.gz");
echo "Your database restoration is in progress......";
system("cat testbackup.sql | mysql --host=sql3 --user=testimport --password=RtPgDsmL testimport");
echo "Finnihed. Your database is now on the website.";
?>
In perl:
- !/usr/bin/perl
print "Decompressing file.....";
system("gunzip testbackup.sql.gz");
print "Database restoration in progess.......";
system("cat testbackup.sql | mysql --host=sql3 --user=testimport --password=RtPgDsmL testimport");
print "Finished. Your database is placed on the website.";
Thanks to this URL I've executed the import properly:
http://your_domain.com/your_directory/importbase.php
Command by line
For the 720 and xxl offers, you can directly save by ssh.
If you connect to ssh in your webspace, and then find your file to import in the directory and enter this command:
cat nom_de_la_base.sql | mysql --host=serveur_sql --user=nom_de_la_base --password=mot_de_passe nom_de_la_base
Example :
cat testbackup.sql | mysql --host=sql3 --user=testimport --password=RtPgDsmL testimport
Return to the MYSQL Databases Page
See
BasesMySQL for more information on MySQL databases.