Importing a MySQL Database to a Managed Server

Please Note:

The text on this page was translated by translation software. A revised version from our editors will be available soon.

You can import MySQL databases to your managed server using the SSH shell or PHP script.

This kind of import is an alternative to using phpMyAdmin.

Import via SSH (shell)

Step 1

Upload the backup of your database to your managed server.

Step 2

Connect to your server via SSH.

step 3

You perform the import using the command line client mysql. The following example imports the database file dump.sql into a MySQL5 database.

Please note: For MySQL5.1 databases the socket /tmp/mysql5.sock belonging to MySQL5.1 must be specified.

For MySQL 5.1:

mysql --host=localhost --user=dbo123456789 --password=******** -S /tmp/mysql5.sock db123456789 < dump.sql

For MySQL 5.5:

mysql --host=localhost --user=dbo123456789 --password=******** db123456789 < dump.sql 

Explanation of parameters

Parameter Description
--host= Here must stop localhost
user= Your database user name
--password= Your database password
-S /tmp/mysql5.sock Necessary for MySQL5.1 databases
db123456789 Your database name
dump.sql The name of the backup file to import

Import via PHP script

Step 1

Upload the backup of your database to your managed server.

Step 2

Create an import script using the following template:

For MySQL 5.1:

<?php
// Bitte hier Ihre Daten eintragen
$host= 'dbxx.1und1.de';
$user= 'dboxxxxxx';
$pass= 'xxxxxxxx';
$db= 'dbxxxxxxx';
// gzip entpacken und in die Datenbank einlesen
system(sprintf( 'gunzip -c %s/dumpDB.sql.gz | mysql -h %s -u %s -p%s -S /tmp/mysql5.sock %s', getenv('DOCUMENT_ROOT'), $host, $user, $pass, $db )); echo '+DONE'; ?>

For MySQL 5.5:

<?php
// Bitte hier Ihre Daten eintragen
$host= 'dbxx.1und1.de';
$user= 'dboxxxxxx';
$pass= 'xxxxxxxx';
$db= 'dbxxxxxxx';
// gzip entpacken und in die Datenbank einlesen
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'; ?>

Explanation of parameters

Parameter Description
$host Here must stop localhost
$user Your database user name
$pass Your database password
$db Your database name
Step 3

Load the script filled with the appropriate parameters into the directory to which you previously uploaded the backup file. In the example script we call the file dumpDB.sql.gz.

Step 4

Execute the script from the browser. For example, if you named the PHP script import_mysql.php and loaded it into the root directory of the web space, you can run the script via http://yourdomain.com/import.mysql.php.

Step 5

Executing the script performs the import into the specified MySQL database.