How To Import And Export Database In MySQL Or MariaDB

In this post, I will guide you on How To Import And Export Database In MySQL Or MariaDB. Use data dumps to back up and restore your information.

You can use import and export database to backup and restore your data. In addition, you can also use them to migrate data to a new server or development environment.

Prerequisites

  • MySQL or MariaDB installed.
  • A database created in your database server.

Export Database

You will need your database name and credentials. We will use mysqldump to export the database:

mysqldump -u username -p database-name > data-dump.sql
  • username is the username to log in to your database.
  • database_name is the name of the database you want to export.
  • data-dump.sql is the file in the current directory that stores the output.

Enter the password to continue if applicable.

Inspect the contents of data-dump.sql to check if it’s a legitimate SQL dump file with the command:

head -n 5 data-dump.sql

You can see output like this:

-- MySQL dump 10.16  Distrib 10.1.44-MariaDB, for Linux (x86_64)
--
-- Host: localhost    Database: database-name
-- ------------------------------------------------------
-- Server version       10.1.44-MariaDB

Import Database

First, log in to MySQL as root or another user with privileges can create the database.

mysql -u root -p

Next, Create a new database with the following command:

CREATE DATABASE new_database;

Then exit the MySQL with the following command:

exit

Import the dump file with the following command:

mysql -u username -p new_database < data-dump.sql
  • username is the username to log in to your database.
  • new_database is the name of the database you want to import.
  • data-dump.sql is the file in the current directory that stores the output.

You can log in to mysql, using the USE new_database and SHOW TABLES; commands respectively to check the result or use phpMyAdmin.

This is the end of the post.

Follow us for the more helpful posts!

We hope this is a useful post for you How To Remove Delete Attribute Option From Product Attribute In Magento 2.

Thank you for reading!

3.7 3 votes
Article Rating

Aaron LX

Aaron is a passionate writer, crazy about shopping, eCommerce and trends. Besides his outstanding research skills and a positive mind, Aaron eagerly shares his experience with the readers.

Leave a Reply or put your Question here

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x