Search


print PDF Finnish
ImportBaseMySQL


How to import a database ?




Introduction


First of all, you must provide :



1. the saved database file, called dump, obtained when the database is saved (see BackupBaseMySQLBackupBaseMySQL 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 nom_de_votre_base;

Where "database_name" 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.......
<br>";

system("cat database_name.sql | mysql --host=server_sql --user=data_base_name --password=password_of_database");

echo "Finnished. Your database is now on the website.";

?>




In perl (importbase.cgi) :



  1. !/usr/bin/perl


print "Your database restoration is in progress.......
<br>";

system("cat nom_de_la_base.sql | mysql --host=serveur_sql --user=nom_de_la_base --password=mot_de_passe nom_de_la_base");

print "C'est fini. Votre base est en place sur cet hébergement.";





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://votredomaine.com/chemin_du_script/importbase.php />


Notice : If ever 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.....
<br>";

system("gunzip testbackup.sql.gz");

echo "Your database restoration is in progress......
<br>";

system("cat testbackup.sql | mysql --host=sql3 --user=testimport --password=RtPgDsmL
RtPgDsmL testimport");

echo "Finnishedi. Your database is now on the website.";

?>






In perl :



  1. !/usr/bin/perl


print "Decompressing file.....
<br>";

system("gunzip testbackup.sql.gz");

print "Database restoration in progess.......
<br>";

system("cat testbackup.sql | mysql --host=sql3 --user=testimport --password=RtPgDsmLRtPgDsmL testimport");

print "Finnished. 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:

Vous vous connectez donc en ssh sur votre espace, puis vous vous dirigez dans le répertoire où

vous avez placer le fichier à importer et vous tapez cette commande :





cat nom_de_la_base.sql | mysql --host=serveur_sql --user=nom_de_la_base --password=mot_de_passe nom_de_la_base





Example :










Return to the MYSQL Databases Page




To consult other sections of the guides on BasesMySQL