Importing a SQL file with your WordPress data

Migrate to WordPress

All the data about your posts, pages, comments, users, forum threads,… of your new WP site generated during the migration is stored in a SQL file.

Watching all your old posts, comments,… “magically” appear in your WordPress dashboard is as easy as importing the SQL file in your WordPress database.

There are two ways to import this file:

– (recommended) From Outside WordPress, using any database import tool like phpmyadmin 
– From Within WordPress, using one of the (few) available restore modules.

Let’s take a closer look at both options.

From outside: PHPMyAdmin

PHPMyAdmin is a free tool to manage MySQL databases (the only official database backend for WP). PHPMyAdmin is available from your control panel. Once inside phpmyadmin, you just need to select the WP database on the left column. If your site contains several databases and you´re not sure which one is the one WP is installed on, open wp-config.php and look for a sentencel like define(‘DB_NAME’, ‘this is the name of your database’);.

After selecting the database just go the import tab and select the SQL file to import.

admin-import

If the file is too large for your current phpmyadmin import limits read this complementary post: Importing large SQL files with phpMyAdmin

From within: Adminer plug-in

An alternative option is to install a WP plug-in that allows us to select and execute a SQL file from within the WP dashboard. For this my recommendation would be to install the Adminer plug-in (WordPress version of the Adminer tool, kind of a competitor of phpmyadmin (as the Adminer people say in their web page: “Replace phpMyAdmin by Adminer and you will get tidier user interface, better support for MySQL features, higher performance and more security.”).

Once installed, you’ll find the Adminer option under the Tools Menu. Once you click on it you’ll have the option to execute Adminer in a separate tab

adminer php mysql tool

and the Adminer interface will immediately pop up. As with phpmyadmin, you have the list of tables on the left. The right hand side show the data/structure of the selected table.

adminer3

In the upper left corner, you’ll see the two most important options, the DUMP button (to export the data of the database) and, the option we were looking for, SQL command (to execute a SQL sentence, possibly importing it from an external file). Upload here your file and Adminer will take care of executing all SQL commands in it.

import sql adminer

Another option would be to use a Backup&Restore plug-in (perhaps surprisingly, the number of plug-ins for doing backup largely outnumbers the number of plug-ins that can also restore the database from a backup file). Among the few plug-ins that offer a Restore feature we have WP-DB ManagerXcloner and UpdraftPlus  (my favourite one, BackWPup recently stopped offering the restore feature).

We hope you’ll find this information useful. If something is not clear or missing, please let us know and we will improve the explanation.

Posted in: Content export / import