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.
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 ways — phpMyAdmin 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.
Open phpMyAdmin from the Databases section on the homepage.
SPanel will redirect you to the phpMyAdmin web interface. Click Import on the top menu bar.
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
Select the file format and click on the Go button to begin the import.
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
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.
Click Export on the top bar.
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.
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.