Copy my entire database from shared hosting to my new cloud server

I have only ever used cheap shared web hosting in the past.
Now I have rented a cloud server with Ubuntu 20.04 Server

I have set up MySQL on the cloud server. It is working.

With a little ssh tunneling, I can open phpMyAdmin on my laptop to modify tables on the cloud server.

What is the best way to migrate the entire contents of my database: allstudentsdb from the shared hosting to my new cloud server??

I am no expert and I have certainly never tried this before!!

You’ll need to talk to your shared host for details on how to get the database as they all have different tooling. You should be able to get it as an SQL dump; basically a text file full of SQL statements that will build your database.

Once you have this, copy it to your new server (use scp if it’s available) then you can import the database using something like:

mysql -u username -p < path/to/database.sql

You will be prompted for your password.

1 Like

Also, on most shared servers, you have access to MyPHPAdmin control panel. In there, you can select your database and use the EXPORT option to save a full copy of it. Then, you can IMPORT it on your other server the same way. Or, if you want to do it with code, you can use something like this:

        //  Create a new full backup
        $result=exec('mysqldump ' . $DatabaseName . ' -u' . $DatabaseUserName . ' -p' . $DatabasePassword . ' > ' . $filename);
        //  We now have a full backup of the database, start a download of the file to the local system...
        header('Content-Type: application/download');
        header('Content-Disposition: attachment; filename=' . $filename);
        header("Content-Length: " . filesize($filename));
        $fp = fopen($filename, "r");

With this code, you just need to run the page and it will force a full backup of the database to download to you in SQL format. Then, import it into your full server’s MyPHPadmin control panel. On several sites I manage, I use this called by a button to backup databases or even just one table at a time. Works great.

Sponsor our Newsletter | Privacy Policy | Terms of Service