How to Import and Export a MySQL Database

This article provides a quick guide on how to import and export a MySQL database. We’ll be guiding you through all you need to know to run these simple tasks.

You can create MySQL databases and set up MySQL users via the MySQL databases tool available in SPanel’s User Interface.

How to Import and Export a MySQL Database

And here’s how to import and export data.

How to Import a MySQL Database

There would probably be an occasion where you’d want to import a MySQL database into your server. You can do that through either of these two waysphpMyAdmin or using the command line. Use this guide to get started.

Method 1: Using PhpMyAdmin

PhpMyAdmin is a free database management platform that allows you to control your databases via a browser-based graphical interface.

Here’s how.

Log in to your SPanel’s User Interface.

How to Import and Export a MySQL Database

Open phpMyAdmin from the Databases section on the homepage.

How to Import and Export a MySQL Database

SPanel will redirect you to the phpMyAdmin web interface. Click Import on the top menu bar.

How to Import and Export a MySQL Database

Select the file you want to import.

Before that, compress the file as gzip, bzip2 or zip, or leave it uncompressed. Save it on your computer using this nomenclature — .[format].[compression] — example, .sql.zip

How to Import and Export a MySQL Database

Select the file format and click on the Go button to begin the import.

How to Import and Export a MySQL Database

The process will start running, and you’ll see the imported database after completion.

Method 2: Using Command Line

Importing a MySQL database through the command line requires a secure shell (SSH) access. SSH allows you to remotely log in to your hosting account to perform tasks through text commands.

It enables webmasters to perform tasks as if they’re right in front of their servers. Follow this guide to import a MySQL database to your server remotely.

Log in to your FTP client to upload the file you want to import into the database. Let’s assume you saved the file as dbimport.sql

How to Import and Export a MySQL Database

Log in to your hosting account using SSH. 

Navigate to the directory where you uploaded the file, using the cd command.

Use this command to import the file to your database: mysql -u username -p dbname < dbimport.sql .

Username and dbname in the above command should be your database’s username and name, respectively.

How to Export a MySQL Database

Databases can also be exported through both phpMyAdmin and the command line.

Method 1: Using PhpMyAdmin

To export your database using PhpMyAdmin, then log into SPanel’s User Interface and open phpMyAdmin.

How to Import and Export a MySQL Database

Click Export on the top bar.

How to Import and Export a MySQL Database

Click on the “Custom” radio button to list all the databases on the server. Choose the export format, then select the database you intend to export.

How to Import and Export a MySQL Database

Configure the export options and click on the “Go” button to export the file to your computer.

Method 2: Using Command Line

Using phpMyAdmin places a limit on the file size you can export. The command line provides a safe and efficient way to export both small and large databases.

Here’s how to export a database using the command line.

Log in to your server remotely using SSH.

Use this command mysqldump –routines -u username -p dbname > dbexport.sql  to export the database. Replace “username” and “dbname” in the command with the username and database name of the database you want to export. 

Replace dbexport.sql with the file name and format you want to export the database to. When prompted, enter the user’s password to run the export. The database export will reside in your server in the file name and format you specified. 

Connect remotely to the server using FTP to download the file to your local computer.

Was this helpful?

What’s your goal today?

1. Sign up to our newsletter and keep up to date with the latest news. Our team consist of highly skilled ex-sysadmins and hosting veterans, ready to share their unique hosting-related knowledge with you.

Sign up for ScalaHosting monthly News Letter and we will keep you up to date about the most valuable pieces of content we publish on our blog

2. Explore our VPS Hosting - with our 30-day unconditional money-back guarantee and free, effortless migration, you can try our award-winning Managed Cloud VPS solutions risk-free.

Rado
Author

Working in the web hosting industry for over 13 years, Rado has inevitably got some insight into the industry. A digital marketer by education, Rado is always putting himself in the client's shoes, trying to see what's best for THEM first. A man of the fine detail, you can often find him spending 10+ minutes wondering over a missing comma or slightly skewed design.

Write a Comment

Required*

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.