EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials MariaDB Tutorial MariaDB Mysqldump
Secondary Sidebar
MariaDB Tutorial
  • MariaDB
    • MariaDB Versions
    • MariaDB? list users
    • MariaDB Commands
    • MariaDB odbc
    • MariaDB Workbench
    • MariaDB for windows
    • MariaDB Server
    • MariaDB? Data Types
    • MariaDB? boolean
    • MariaDB phpMyAdmin
    • MariaDB Mysqldump
    • MariaDB Java Connector
    • MariaDB insert
    • MariaDB UPDATE
    • MariaDB? rename column
    • MariaDB AUTO_INCREMENT
    • MariaDB Timezone
    • MariaDB GROUP_CONCAT
    • MariaDB wait_timeout
    • MariaDB MaxScale
    • MariaDB? with
    • MariaDB GUI
    • MariaDB? create?table
    • MariaDB? SHOW TABLES
    • MariaDB alter table
    • MariaDB List Tables
    • MariaDB JSON Functions
    • MariaDB Foreign Key
    • MariaDB? trigger
    • MariaDB Grant All Privileges
    • MariaDB Select Database
    • MariaDB? create database
    • MariaDB Delete Database
    • MariaDB Join
    • MariaDB JSON
    • MariaDB? show databases
    • MariaDB List Databases
    • MariaDB Functions
    • MariaDB? TIMESTAMP
    • MariaDB create user
    • MariaDB add user
    • MariaDB Max Connections
    • MariaDB show users
    • MariaDB Delete User
    • MariaDB? change user password
    • MariaDB? change root password
    • MariaDB reset root password
    • MariaDB IF
    • MariaDB bind-address
    • MariaDB Transaction
    • MariaDB Cluster
    • MariaDB Logs
    • MariaDB Encryption
    • MariaDB? backup
    • MariaDB Replication
    • MariaDB max_allowed_packet
    • MariaDB? performance tuning
    • MariaDB export database
    • MariaDB? import SQL

MariaDB Mysqldump

MariaDB Mysqldump

Introduction to MariaDB Mysqldump

MariaDB mysqldump is the utility provided in MariaDB using which you can take a backup of your current database so that when the situation arises of loss of data or inconsistent data due to unavoidable circumstances in a development environment, you can easily restore that data by using the dump file generated from mysqldump command and making sure the availability of the data to the user 24 * 7. In this article, we will firstly have a look at what is MariaDB mysqldump in detail and further study how we can use it for taking backup and restoration along with additional comments.

What is MariaDB Mysqldump?

When we make the use of mysqldump in MariaDB then a file gets generated which is actually having the flat-file format. The flat file contains the SQL statements which can be executed again to have the same database content as in the state when the backup was taken. Mysqldump can only be used if you as a user of that database have the privilege to access the database and entities of the tables such as tables and views.

If you can retrieve the data from MariaDB using, SELECT clause then surely you can make the use of mysqldump utility to generate a backup file. CSV, XML, or any other file which has a certain delimiter can also be produced by using mysqldump command. When we will execute the backup command at that time the database will be in the same state as it was while performing the mysqldump functionality which is done by using the execution of generated dump file.

Use mysqldump

We can make the use of mysqldump on a particular database only provided if you have the access privilege of SELECT command on the tables and views of the database that you want to dump and take a backup of. You can dump one or more than one database simultaneously. You can make the use of the following syntax for dumping the database in order to create a dump file for backup purposes in MariaDB –

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

For dumping one or more than one database present on the same server –

> mysqldump [required options] –databases database name … > sampleBackupFile.sql

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,328 ratings)

For dumping all databases present on the server –

> mysqldump [required options] –all-databases > sampleBackupFile.sql

For dumping one or more tables of a database, use the below mysqldump syntax –

> mysqldump [required options] database name [table name …] > sampleBackupFile.sql

Make sure to fire the above command on the MariaDB shell or command prompt. The terminologies used in the above command are as discussed below in detail –

  • Database name – This is the name of the database whose backup is supposed to be taken.
  • sampleBackupFile – The name which you want your dump file to have. Note that it should have the extension of .sql only.

To get the complete details regarding required options used in the above syntax, you can type a quick command on the command prompt shown below –

Mysqldump -u root p -help that generates the output shown in the below image –

Mariadb mysqldump 1

As you can observe from the above output that the list of the options used for specifying additional information that can be specified in mysqldump is very big, we can even go for exporting the same in a new file which can be done by making the use of the below command on command prompt –

mysqldump -u root p --help > temp

We can see that if we get a new command prompt after its execution the command has executed successfully creating a file containing the details of all options that can be specified in mysqldump command –

Mariadb mysqldump 2

The file created with name temp looks as shown below after opening –

6

In order to restore the data that is backup by using mysqldump command, we can make the use of the restore command whose syntax is as shown below –

MySQL name of database < name of backup file.sql

  • name of database – it is the database in which you want your data to restore.
  • Name of the backup file – The file that was created by using mysqldump command.

How to Backup and Restore?

Let us now understand how we can actually implement backup and restore by using the mysqldump command with the help of one example. We have one database named educba which contains the table named developers stored in it. This table has some records. To check the complete contents of the developer’s table, let us fire the select query on the developer’s table –

Select * from educba.developers;

Note that previously we have already executed the use educba; command to make sure that our current database is educba. We can see that the developer’s table contains the following rows as its contents –

7

Consider that we have to take the backup of the educba database having only one table developer in it. This can be done by making the use of the following mysqldump command –

Mysqldump -u root -p –databases educba >backupOfEducba.sql

The execution of the above command gives the following output on a terminal and creating a file named backupOfEducba.sql containing all the commands which can be used for restoration purposes –

8

After opening the backupOfEducba.sql file, you can observe the following contents in it –

MariaDB Mysqldump

You can observe that the old existing tables are dropped, deleting all the previous structure of the table as well as its contents. After that, the table is recreated and data is inserted in it after locking the table to make sure that the data consistency is maintained.
Let us now see how we can restore the data on any other database with the help of the dump flat file generated from mysqldump command and restore command. Create the database named educba in a new server. Fire restore command. Our statement will be as shown below –

mysql -u root -p <backupOfEducba.sql

The output of the execution of the following command is as shown below –

MariaDB Mysqldump

After that, we can confirm the existence of the same tables in the educba database that we have created in a new database.

mysqldump comments – Mysqldump comment can be used only if you have the select privilege over the entity whose backup you will be taking. Whether it will be a database or the table in it. Proper syntax corresponding to the requirement of database or table to be dumped should be chosen for the dumping of mysqldump.

Conclusion

MariaDB mysqldump command is used for taking the backups of existing databases or databases and restoring when needed in case of data loss due to unavoidable circumstances.

Recommended Articles

This is a guide to MariaDB Mysqldump. Here we discuss the Introduction, What is MariaDB Mysqldump? examples with code implementation. You may also have a look at the following articles to learn more –

  1. MariaDB insert
  2. MariaDB create table
  3. MariaDB alter table
  4. MariaDB TIMESTAMP
Popular Course in this category
MySQL Training Program (12 Courses, 10 Projects)
  12 Online Courses |  10 Hands-on Projects |  92+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more