<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Backup on Citizix, The Best blog for Linux, Opensource, Devops, Cloud and all things awesome tech.</title><link>https://citizix.com/tags/backup/</link><description>Recent content in Backup on Citizix, The Best blog for Linux, Opensource, Devops, Cloud and all things awesome tech.</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><copyright>Citizix, Ltd.</copyright><lastBuildDate>Tue, 28 Jul 2026 13:56:41 +0300</lastBuildDate><atom:link href="https://citizix.com/tags/backup/index.xml" rel="self" type="application/rss+xml"/><item><title>How to backup and restore databases in Mysql or Mariadb</title><link>https://citizix.com/how-to-backup-and-restore-databases-in-mysql-or-mariadb/</link><pubDate>Mon, 15 Nov 2021 16:16:36 +0000</pubDate><guid>https://citizix.com/how-to-backup-and-restore-databases-in-mysql-or-mariadb/</guid><description>&lt;p&gt;In this guide we will learn how to back up and restore – inporting and exporting data in Mysql or Mariadb – the commands are interchangeable.&lt;/p&gt;
&lt;p&gt;Importing and exporting databases is a common task in software development. You can use data dumps to back up and restore your information. You can also use them to migrate data to a new server or development environment.&lt;/p&gt;
&lt;h4 id="related-content"&gt;Related Content
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="https://citizix.com/how-to-run-mariadb-with-docker-and-docker-compose/" title="https://citizix.com/how-to-run-mariadb-with-docker-and-docker-compose/"
 target="_blank" rel="noopener"
 &gt;How to run Mariadb with Docker and Docker-Compose&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://citizix.com/how-to-install-mysql-server-8-on-opensuse-leap-15-3/" title="https://citizix.com/how-to-install-mysql-server-8-on-opensuse-leap-15-3/"
 target="_blank" rel="noopener"
 &gt;How to install Mysql Server 8 on OpenSUSE Leap 15.3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="prerequisites"&gt;Prerequisites
&lt;/h2&gt;&lt;p&gt;To follow along, you need the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Access to a mysql or mariadb server&lt;/li&gt;
&lt;li&gt;Terminal access with mysql command installed&lt;/li&gt;
&lt;li&gt;A database in the db server created&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="table-of-content"&gt;Table of Content
&lt;/h2&gt;&lt;ol&gt;
&lt;li&gt;Exporting a database&lt;/li&gt;
&lt;li&gt;Importing a database&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id="1-exporting-a-databasee"&gt;1. Exporting a databasee
&lt;/h2&gt;&lt;p&gt;The &lt;code&gt;mysqldump&lt;/code&gt; console utility exports databases to SQL text files. This makes it easier to transfer and move databases. You will need your database’s name and credentials for an account whose privileges allow at least full read-only access to the database.&lt;/p&gt;
&lt;p&gt;Use &lt;code&gt;mysqldump&lt;/code&gt; to export your database:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;mysqldump -u root -p citizix_db &amp;gt; citizix_db.sql
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Copy&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;root&lt;/code&gt; is the username you can log in to the database with&lt;/li&gt;
&lt;li&gt;&lt;code&gt;citizix_db&lt;/code&gt; is the name of the database to export&lt;/li&gt;
&lt;li&gt;&lt;code&gt;citizix_db.sql&lt;/code&gt; is the file in the current directory that stores the output.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The command will produce no visual output, but you can inspect the contents of &lt;code&gt;citizix_db.sql&lt;/code&gt; to check if it’s a legitimate SQL dump file.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ ls &lt;span class="p"&gt;|&lt;/span&gt; grep sql
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;citizix_db.sql
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Run the following command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;head -n &lt;span class="m"&gt;5&lt;/span&gt; citizix_db.sql
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The top of the file should look similar to this, showing a MySQL dump for a database named &lt;code&gt;database_name&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# head -n 5 citizix_db.sql&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;-- MariaDB dump 10.19 Distrib 10.7.1-MariaDB, &lt;span class="k"&gt;for&lt;/span&gt; debian-linux-gnu &lt;span class="o"&gt;(&lt;/span&gt;x86_64&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;--
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;-- Host: localhost Database: citizix_db
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;-- ------------------------------------------------------
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;-- Server version	10.7.1-MariaDB-1:10.7.1+maria~focal
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If any errors occur during the export process, &lt;code&gt;mysqldump&lt;/code&gt; will print them to the screen.&lt;/p&gt;
&lt;h2 id="2-importing-a-database"&gt;2. Importing a database
&lt;/h2&gt;&lt;p&gt;Log in to MySQL as &lt;strong&gt;root&lt;/strong&gt; or another user with sufficient privileges to create new databases:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;mysql -u root -p
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Type in your password. This command will bring you into the MySQL shell prompt.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;$ mysql -u root -p
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Enter password:
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Welcome to the MariaDB monitor. Commands end with &lt;span class="p"&gt;;&lt;/span&gt; or &lt;span class="se"&gt;\g&lt;/span&gt;.
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Your MariaDB connection id is &lt;span class="m"&gt;349&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Server version: 10.7.1-MariaDB-1:10.7.1+maria~focal mariadb.org binary distribution
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Copyright &lt;span class="o"&gt;(&lt;/span&gt;c&lt;span class="o"&gt;)&lt;/span&gt; 2000, 2018, Oracle, MariaDB Corporation Ab and others.
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Type &lt;span class="s1"&gt;&amp;#39;help;&amp;#39;&lt;/span&gt; or &lt;span class="s1"&gt;&amp;#39;\h&amp;#39;&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; help. Type &lt;span class="s1"&gt;&amp;#39;\c&amp;#39;&lt;/span&gt; to clear the current input statement.
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;MariaDB &lt;span class="o"&gt;[(&lt;/span&gt;none&lt;span class="o"&gt;)]&lt;/span&gt;&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you don’t have a database in your case, you can create a database using this command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sql" data-lang="sql"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;create&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;database&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;database_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I have a database &lt;code&gt;citizix_db&lt;/code&gt; in my case that I will use for this example. Check the databases with this command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sql" data-lang="sql"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;MariaDB&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[(&lt;/span&gt;&lt;span class="k"&gt;none&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;show&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;databases&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;--------------------+
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;Database&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;--------------------+
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;citizix_db&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;information_schema&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;mysql&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;performance_schema&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;--------------------+
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;rows&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;set&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;005&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;sec&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The export operations will be done fom the bash shell so exit the MySQL shell by pressing &lt;code&gt;CTRL+D&lt;/code&gt;. From the normal command line, you can import the dump file with the following command:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;mysql -u root -p citizix_db &amp;lt; citizix_db.sql
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;root&lt;/code&gt; is the username you can log in to the database with&lt;/li&gt;
&lt;li&gt;&lt;code&gt;citizix_db&lt;/code&gt; is the name of the freshly created database&lt;/li&gt;
&lt;li&gt;&lt;code&gt;citizix_db.sql&lt;/code&gt; is the data dump file to be imported, located in the current directory&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the command runs successfully, it won’t produce any output. If any errors occur during the process, &lt;code&gt;mysql&lt;/code&gt; will print them to the terminal instead. To check if the import was successful, log in to the MySQL shell and inspect the data. Selecting the new database with &lt;code&gt;USE new_database&lt;/code&gt; and then use &lt;code&gt;SHOW TABLES;&lt;/code&gt; or a similar command to look at some of the data.&lt;/p&gt;
&lt;h2 id="conclusion"&gt;Conclusion
&lt;/h2&gt;&lt;p&gt;In this tutorial we learnt how to import and export a MySQL or MariaDB database. &lt;code&gt;mysqldump&lt;/code&gt; has additional settings that you can use to alter how the system creates data dumps. You can learn more about from the &lt;a class="link" href="http://dev.mysql.com/doc/refman/5.7/en/mysqldump.html" target="_blank" rel="noopener"
 &gt;official mysqldump documentation page&lt;/a&gt;.&lt;/p&gt;</description></item></channel></rss>