There are multiple ways to import a database. In this article we will use phpMyAdmin and shell commands. If you are not familiar with the terminal and shell commands we recommend you stick to phpMyAdmin.
If you wonder how to export databases, please check out this article.
Table of contents
Importing Databases with phpMyAdmin
To import your database through phpMyAdmin, you first have to login to phpMyAdmin. Before importing your database, make sure you are on the correct database, and not
information_schema. When you have clicked on the database you want to import to, click choose file and select a
.sql file either raw or compressed which you have saved locally. Click go and you should see a success screen.
Importing Databases with mysql
When using terminal for importing a database all you have to do is upload the database dump to the server using
scp or with a FTP program like FileZilla. Once the file is located on the server you can run the following command (replace USERNAME, DATABASENAME and FILENAME):
mysql -u USERNAME -p DATABASENAME < FILENAME.sql
If you have a compressed
.sql file you can decompress it and pipe the output into
mysql in one go. Here’s an example with
gunzip which decompresses
gzip formatet files. By passing the
-c flag we also outputs the decompressed file:
gunzip -c FILENAME.sql | mysql -u USERNAME -p DATABASENAME
When hitting enter, you are asked to pass the database password. After filling in the correct password, the server will do the rest.
Importing Databases with WP-CLI
If you have a WordPress site you can use the WP-CLI command line extension. WP-CLI is quite a bit easier than using
mysql because it will fetch the database credentials for you. Simply run
wp db import FILENAME.sql in your main WordPress directory and it will do the rest for you.
FILENAME.sql is your uploaded database dump. Be sure to add the
--path= parameter if you run the command outside that directory.
And as always, should you have any additional questions please don’t hesitate to contact our support chat at servebolt.com!
Give us your feedback on this article
Want to speed up your site, easily?
Set up your site on Servebolt, free of charge for 14 days, and see for yourself how fast it can be on our extremely fast hosting.
A faster site converts better, ranks better on Google, and is better for the climate.