• Help & contact
    • Spring Offers
      %

    In this article, we'll show you how you can import MySQL databases to your Managed Server using SSH or a PHP script.

    This import method is used as an alternative to going through phpMyAdmin.

    Importing Via SSH (Shell)

    • Upload the backup of your database to your managed server.

    • Connect to your server using SSH.

    • You can then perform the import using the command line client mysql. In the following example, the database file dump.sql is imported into a MySQL 5.5 and a MySQL 5.7 database.

    For MySQL 5.5:
    mysql --host=localhost --user=dbo123456789 --password=******** db123456789 < dump.sql 
    bash
    For MySQL 5.7:
    mysql --host=db5000012345.hosting-data.io --user=dbu1234 --password=****** dbs12345 < dump.sql
    bash
    Explanation of the parameters
    Parameters Description
    --host= MySQL 5.5: Here you have to stop localhost for MySQL 5.5 databases.
      MySQL 5.7: The hostname for MySQL 5.7 databases must be specified here.
    --user= Your database user name
    --password= Your database password
    db123456789 Your database name
    dbs12345 Your database name
    dump.sql The name of the backup file to be imported

    Importing with a PHP Script

    • Upload the backup of your database to your managed server.

    • Create an import script according to the following template:

    For MySQL 5.5:
    <?php
    // Please enter your data here
    $host= 'localhost';
    $user= 'dboxxxxxx';
    $pass= 'xxxxxxxx';
    $db= 'dbxxxxxxx';
    system (sprintf( 'mysql -h %s -u %s -p%s %s < dump.sql ', $host, $user, $pass, $db ));
    echo '+DONE';
    ?>
    php
    For MySQL 5.7:
    <?php
    // Please enter your data here
    $host= 'HOSTNAME';
    $user= 'dboxxxxxx';
    $pass= 'xxxxxxxx';
    $db= 'dbxxxxxxx';
    system (sprintf( 'mysql -h %s -u %s -p%s %s < dump.sql ', $host, $user, $pass, $db ));
    echo '+DONE';
    ?>
    php
    Explanation of the parameters
    Parameters Description
    $host MySQL 5.5: Here you have to stop localhost for MySQL 5.5 databases.
      MySQL 5.7: For MySQL 5.7 databases, the corresponding hostname must be entered here.
    $user Your database username
    $pass Your database password
    $db Your database name
    • Load the script filled with the appropriate parameters into the directory where you previously uploaded the backup file. In the example script, we name the file dumpDB.sql.gz.

    • Run the script from a browser. If you have named the PHP script, for example, import_mysql.php and loaded it into the main directory of the webspace, the file can be loaded using the format yourdomain.de/import.mysql.php.

    • By executing the script, the import into the specified MySQL database will be performed.