{"id":5302,"date":"2022-11-01T15:46:47","date_gmt":"2022-11-01T13:46:47","guid":{"rendered":"https:\/\/www.scalahosting.com\/kb\/?p=5302"},"modified":"2024-03-07T11:45:52","modified_gmt":"2024-03-07T09:45:52","slug":"how-to-back-up-a-mysql-database","status":"publish","type":"post","link":"https:\/\/www.scalahosting.com\/kb\/how-to-back-up-a-mysql-database\/","title":{"rendered":"How to Back Up a MySQL Database"},"content":{"rendered":"\n<p>Backing up your site&#8217;s files is <strong>relatively straightforward<\/strong>. In essence, you put them all in an archive, which you can later extract and restore everything. When it comes to generating backups of your <a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-create-a-database-in-mysql\/\"><strong>MySQL databases<\/strong><\/a>, however, things are a bit more complicated.<\/p>\n\n\n\n<p>Today, we&#8217;ll look into the <strong>different types of database backups<\/strong>, and we&#8217;ll see some of the most popular ways to back up and restore your website&#8217;s data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Types-of-MySQL-Backups\"><strong>Types of MySQL Backups<\/strong><\/h2>\n\n\n\n<p><strong>MySQL is a<\/strong> <strong>relational database management system <\/strong>used by most modern websites and applications. The information is stored in tables, with relations between the different datasets. In effect, these relations build <strong>the structure of the database<\/strong>.<\/p>\n\n\n\n<p>A working backup of a database must be able to recreate the tables and the relations between them in the way they are originally organized. Ideally, it must do it quickly and efficiently in order to minimize service interruption.<\/p>\n\n\n\n<p><em>There are two main types of MySQL database backups<\/em>:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Logical backups<\/strong><\/h3>\n\n\n\n<p>A logical backup exports (or dumps) the data and the data structure to a file with an SQL extension. SQL files are created by running scripts either through a third-party GUI-based tool or from a shell. Once generated, the backup can be stored locally, sent to another device on the network, or, ideally, transferred to an offsite location (it could be a server located in a different center, but it could also be an account with a popular cloud storage provider like Dropbox, for example).<\/p>\n\n\n\n<p>In addition to the data itself, a logical backup contains the <strong>SQL statements<\/strong> (e.g., <em>CREATE DATABASE, CREATE TABLE<\/em>, etc.) \u2013 instructions that enable MySQL to rebuild the database with the correct table structure and relations. The main advantage of logical backups is that they can be used to transfer a database from one host to another.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Physical backups<\/strong><\/h3>\n\n\n\n<p>A <strong>physical backup<\/strong> is a snapshot of the database&#8217;s <strong>datadir directory<\/strong>. All the tables and the data inside them are copied in their original file formats and can be restored in a <strong>fully functioning database<\/strong> as long as the structure is maintained.<\/p>\n\n\n\n<p>Physical backups are quicker but can only work if they are restored from the same database engine on the same <a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-check-the-mysql-version-on-the-server-hosting-my-account\/\"><strong>MySQL version<\/strong><\/a>. Hence, they aren&#8217;t always suitable for moving a database from one environment to another.<\/p>\n\n\n\n<p>Your<strong> backup strategy<\/strong> should be determined by a number of different factors including the hosting setup, the database size, and your requirements.<\/p>\n\n\n\n<p>Logical backups tend to be more common because, as we&#8217;ll find out in a minute, there are several ways of creating them, with tools readily available and fairly easy to use. Furthermore,<strong> logical backups<\/strong> can copy individual database objects, giving you <strong>more flexibility<\/strong> and a quicker resolution when you&#8217;re dealing with data corruption problems in <strong>specific tables<\/strong>. They are also more suitable if you&#8217;re looking for an incremental backup solution.<\/p>\n\n\n\n<p>Overall, while physical backups do make sense in a few<strong> specific scenarios<\/strong>, for the regular website owner, logical ones are easier to set up and manage. That&#8217;s why today&#8217;s article will focus on them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Creating-a-Database-Backup-via-the-Command-Line\"><strong>Creating a Database Backup via the Command Line<\/strong><\/h2>\n\n\n\n<p>If you use the command line, you&#8217;ll <strong>export MySQL databases with<\/strong> <strong>mysqldump command-line utility\u00a0 \u2013 a tool designed for this specific purpose<\/strong>. The lack of a graphical user interface means many will likely prefer one of the other methods. However, if you decide to give it a go, you&#8217;ll see that there&#8217;s nothing too complicated about the process.<\/p>\n\n\n\n<p>Your first job is to <a href=\"https:\/\/www.scalahosting.com\/kb\/ssh-access\/\"><strong>open an SSH shell<\/strong><\/a>. Modern operating systems support the protocol out of the box. Windows computers connect to remote servers via <strong>PowerShell or the Command prompt tool<\/strong>, and Unix-based systems do it with the <strong>Terminal<\/strong>.<\/p>\n\n\n\n<p>Some people <strong>prefer dedicated SSH clients like PuTTY<\/strong>, and if you have an SPanel server, you can open a shell directly via <a href=\"https:\/\/www.scalahosting.com\/blog\/ssh-terminal-in-spanel\/\"><strong>the SSH Terminal<\/strong><\/a> available on the homepage of the User Interface.<\/p>\n\n\n\n<p>Before you continue, make sure you use a <a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-create-or-delete-a-mysql-database-or-user\/\"><strong>MySQL user account<\/strong><\/a> with privileges over the database you&#8217;re about to back up. If you log in as <strong>root<\/strong> or any other account with SYSTEM_USER <strong>permissions<\/strong>, you can export data from any database you want.<\/p>\n\n\n\n<p>It is worth mentioning that mysqldump won&#8217;t be able to back up a database if one of the tables is corrupted. To make sure everything will go smoothly, you can use the <strong>mysqlcheck <\/strong>command-line utility to connect to the MySQL server and check for corrupted data.<\/p>\n\n\n\n<p><strong>The command looks like this:<\/strong><\/p>\n\n\n\n<p><em><em>$ mysqlcheck [the database&#8217;s name] -u [your MySQL user&#8217;s username] -p<\/em><\/em><\/p>\n\n\n\n<p><strong><strong>After you provide your user account&#8217;s password, mysqlcheck will scan all tables for data corruption. Ideally, the output will look like this:<\/strong><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"560\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/32-1024x560.png\" alt=\"How to Back Up a MySQL Database, Creating a Database Backup via the Command Line\" class=\"wp-image-5305\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/32-1024x560.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/32-300x164.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/32-768x420.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/32-1536x840.png 1536w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/32.png 1920w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>To check all databases, add the <strong><em>&#8211;all-databases <\/em><\/strong>option. With that done, you can proceed with the backup.<\/p>\n\n\n\n<p>The mysqldump utility covers quite a few scenarios. Here are the most common ones:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>Backing up a single database via the command line.<\/strong><\/strong><\/h3>\n\n\n\n<p><strong><strong>To back up one of the databases on your account, you need a command that looks like this:<\/strong><\/strong><\/p>\n\n\n\n<p><em><em>$ mysqldump -u [your MySQL account&#8217;s username] -p [the name of the database] > [the name of the backup file]<\/em><\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"581\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/1-1-1024x581.png\" alt=\"How to Back Up a MySQL Database, Backing up a single database via the command line.\" class=\"wp-image-5306\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/1-1-1024x581.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/1-1-300x170.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/1-1-768x436.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/1-1.png 1269w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>With the above command, the user <strong><em>test_user <\/em>exports the database <em>test_database<\/em><\/strong><em> <\/em>to the file <em>backup.sql<\/em>. All you need to do is enter the user account&#8217;s password. If<strong> <em>backup.sql<\/em><\/strong><em> <\/em>doesn&#8217;t exist, <strong>MySQL will automatically create it.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>Backing up specific tables from a selected database<\/strong><\/strong><\/h3>\n\n\n\n<p>The mysqldump utility can also back up specific tables only. Just add the table&#8217;s name after the database. Here&#8217;s an example:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"522\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/19-1024x522.png\" alt=\"How to Back Up a MySQL Database, Backing up specific tables from a selected database\" class=\"wp-image-5307\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/19-1024x522.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/19-300x153.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/19-768x392.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/19.png 1218w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>In the screenshot above, <em>test_user<\/em> is trying to back up the table <em>wp_posts<\/em> from <em>test_database2<\/em> to the <em>posts.sql <\/em>file. To dump multiple tables to the same file, simply add their names separated by spaces. For example:<\/p>\n\n\n\n<p><strong><em><strong><em>$ mysqldump -u test_user -p test_database2 wp_posts wp_options wp_users wp_links > wordpress.sql<\/em><\/strong><\/em><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>Multiple database backups<\/strong><\/strong><\/h3>\n\n\n\n<p>You can export more than one database to the same <strong>file with mysqldump<\/strong>. To do that, use the command above, adding the <strong><em>&#8211;databases <\/em><\/strong>option and the names of the databases separated by spaces. For example:<\/p>\n\n\n\n<p><strong><em><strong><em>$ mysqldump -u test_user -p &#8211;databases test_database test_database2 test_database3 > backup.sql<\/em><\/strong><\/em><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>Backing up all accessible databases<\/strong><\/strong><\/h3>\n\n\n\n<p>If you want to back up all the databases you have control over, replace the database name with the <strong><em>&#8211;all-databases<\/em><\/strong> option. For example:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"514\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/20-1024x514.png\" alt=\"How to Back Up a MySQL Database, Backing up all accessible databases\" class=\"wp-image-5310\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/20-1024x514.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/20-300x150.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/20-768x385.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/20.png 1218w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>This will dump all databases except<strong> information_schema<\/strong>,<strong> performance_schema<\/strong> and any other default <strong>MySQL schemas<\/strong>. To include them in the backup, add the<strong><em> &#8212; skip-lock-tables<\/em><\/strong> option.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>Backing up a database structure only<\/strong><\/strong><\/h3>\n\n\n\n<p>Sometimes, you may need to generate a backup of a <strong>database&#8217;s structure without the data stored<\/strong> in it. The mysqldump utility can do it if you include the <strong><em>&#8211;no-data<\/em><\/strong> option. Here&#8217;s what the command looks like:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"518\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/21-1024x518.png\" alt=\"How to Back Up a MySQL Database, Backing up a database structure only\" class=\"wp-image-5309\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/21-1024x518.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/21-300x152.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/21-768x388.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/21.png 1216w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>Backing up the data without the structure<\/strong><\/strong><\/h3>\n\n\n\n<p>The reverse is also possible \u2013 you can <strong>backup the data without the structure<\/strong>. The option is \u2013<strong><em>no-create-info<\/em><\/strong>, and the command looks like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"524\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/22-1024x524.png\" alt=\"How to Back Up a MySQL Database, Backing up the data without the structure\" class=\"wp-image-5311\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/22-1024x524.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/22-300x154.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/22-768x393.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/22.png 1223w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>The<strong> mysqldump utility<\/strong> won&#8217;t print a message telling you that it has successfully backed up your database, so you can use the <strong><em>ls<\/em><\/strong> command to confirm that the backup is completed.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"231\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/2-1024x231.png\" alt=\"How to Back Up a MySQL Database, Backing up the data without the structure 2\" class=\"wp-image-5312\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/2-1024x231.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/2-300x68.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/2-768x173.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/2.png 1221w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>Dumping a large database with mysqldump<\/strong><\/strong><\/h3>\n\n\n\n<p>Using <strong><em>mysqldump on larger databases<\/em><\/strong> could be trickier. If you have lots of GBs to back up, you may experience<strong> increased server load<\/strong>, and if the database is really big, the entire operation could fail.<\/p>\n\n\n\n<p>The first problem is the <strong>amount of storage the backup<\/strong> takes up. Large databases produce large files, and although mysqldump has some options like <em>&#8211;extend-insert<\/em> that help to some extent, they aren&#8217;t always as effective as you may hope.<\/p>\n\n\n\n<p>What is almost guaranteed to shrink the size of your backup is piping mysqldump&#8217;s backup through <strong>gzip <\/strong>and compressing the output file before writing it on the disk.<\/p>\n\n\n\n<p>The command will looks like this:<\/p>\n\n\n\n<p><strong><em><strong><em>$ mysqldump -u [your mysql account&#8217;s username] -p [your database&#8217;s name] | gzip > [filename].sql.gz<\/em><\/strong><\/em><\/strong><\/p>\n\n\n\n<p>On the one hand, this reduces the size of the generated backup, and on the other, it cuts the<strong> IO load<\/strong>.<\/p>\n\n\n\n<p>The mysqldump utility has a couple of other options that may also help. The <strong><em>&#8211;opt <\/em><\/strong>option <strong>encompasses several different command parameters<\/strong> that optimize the dump operation. Bear in mind that they make the backup more difficult to understand by other <strong>database systems<\/strong>, so this may not be the best approach if you want to migrate the database to a new host.<\/p>\n\n\n\n<p>The <strong><em>&#8211;quick<\/em><\/strong> option may also work. By default, mysqldump stores each table row into memory before dumping it into the backup file. with the<em> &#8211;quick option<\/em>, the data is transferred directly to the backup.<\/p>\n\n\n\n<p>If a large backup operation fails, you can try to increase the <strong>max_allowed_packet<\/strong> parameter in <strong>MySQL&#8217;s configuration file<\/strong> (<em>the my.cnf file usually stored in \/etc<\/em>). This is usually necessary only when you&#8217;re trying to shift dozens of gigabytes of information, and it&#8217;s not guaranteed to succeed.<\/p>\n\n\n\n<p>Putting that much data into a single file will never be easy, and many experts suggest that in such cases, you&#8217;re better off using <strong>a physical backup solution<\/strong> like <strong>MySQL Enterprise Backup<\/strong> or <strong>Percona XtraBackup<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Creating-a-Database-Backup-With-phpMyAdmin\"><strong><strong>How to Back Up a MySQL Database Using phpMyAdmin?<\/strong><\/strong><\/h2>\n\n\n\n<p>Many shared and managed hosting accounts come with phpMyAdmin preinstalled. Its default login URL is <strong><em>https:\/\/[your server&#8217;s IP]\/phpmyadmin<\/em><\/strong> (it&#8217;s deliberately changed by some hosts for security reasons), though it&#8217;s often accessible from the control panel, as well.<\/p>\n\n\n\n<p>It has an easy-to-use graphic interface, meaning you don&#8217;t need to learn any SQL commands to manage your database. You can also <strong>export data with a few mouse clicks<\/strong>. Here&#8217;s how to do it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>Backing up a single database<\/strong><\/strong><\/h3>\n\n\n\n<p>After you open phpMyAdmin, you&#8217;ll see a list of all the databases on your <a href=\"https:\/\/www.scalahosting.com\/web-hosting-for-small-business.html\"><strong>hosting account<\/strong><\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"535\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/3-1024x535.png\" alt=\"How to Back Up a MySQL Database, Backing up a single database\" class=\"wp-image-5313\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/3-1024x535.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/3-300x157.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/3-768x401.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/3.png 1232w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>Click on the one you want to back up and go to the <strong>Export<\/strong> tab.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"388\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/4-1024x388.png\" alt=\"How to Back Up a MySQL Database, Backing up a single database 2\" class=\"wp-image-5314\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/4-1024x388.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/4-300x114.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/4-768x291.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/4.png 1336w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>You can choose the export method and the format. It&#8217;s preferable to keep the <strong>SQL format<\/strong>, as this will give you more options when you need to restore the backup.<\/p>\n\n\n\n<p>As for the method, <strong>Quick<\/strong> is selected by default, and if you leave it like that, <a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-import-and-export-a-mysql-database\/\"><strong>phpMyAdmin<\/strong><\/a> will dump the entire database (<em>the data and the structure<\/em>) into the <strong>SQL file<\/strong>.<\/p>\n\n\n\n<p>If you select the <strong>Custom <\/strong>radio button, you&#8217;ll see quite a few more options. First, you can select which tables you&#8217;d like to dump. You can back up the structure, the data, or both.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"863\" height=\"637\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/23.png\" alt=\"How to Back Up a MySQL Database, Backing up a single database 3\" class=\"wp-image-5315\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/23.png 863w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/23-300x221.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/23-768x567.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>Further down, you can have<strong> phpMyAdmin automatically rename the database<\/strong>, its tables, and\/or columns while exporting them. This is where you specify the file name template as well. By default, it&#8217;s set to<strong> &#8220;@DATABASE@<\/strong>&#8221; which means that phpMyAdmin will name the backup file after your database.<\/p>\n\n\n\n<p>You can lock the database&#8217;s tables or export them as separate files. Options for the exported file&#8217;s <strong>encoding and compression<\/strong> are also available in this section. You can skip tables over a certain size and see the output as text <em>instead of dumping it into an SQL file<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"879\" height=\"439\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/24.png\" alt=\"How to Back Up a MySQL Database, Backing up a single database 4\" class=\"wp-image-5316\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/24.png 879w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/24-300x150.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/24-768x384.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>In the <strong>Format-specific options <\/strong>section, you decide whether to have comments, metadata, and other formatting elements in your backup. You can have <strong>phpMyAdmin export the database as a transaction<\/strong>, disable foreign key checks, and dump views as tables.<\/p>\n\n\n\n<p>There&#8217;s also a drop-down menu letting you make the backup backward compatible with a number of older systems.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"806\" height=\"422\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/25.png\" alt=\"How to Back Up a MySQL Database, Backing up a single database 5\" class=\"wp-image-5317\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/25.png 806w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/25-300x157.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/25-768x402.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>Next, you have the <strong>Object creation options <\/strong>section. It mainly deals with the statements that will be added to the backup, which concern the way the SQL file will recreate the database&#8217;s contents.<\/p>\n\n\n\n<p>For example, the <strong>CREATE DATABASE and USE <\/strong>statements can save you some time when you need to restore the data to a new empty database. If, on the other hand, you plan on restoring the data into an existing database, you can have the DROP statements overwrite the old data.<\/p>\n\n\n\n<p>If the <strong>IF NOT EXISTS <\/strong>option is enabled, your backup will check for matching tables before trying to create them, and with the <strong>AUTO_INCREMENT checkbox<\/strong>, you can append the backed up data to existing tables.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"561\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/26-1024x561.png\" alt=\"How to Back Up a MySQL Database, Backing up a single database 6\" class=\"wp-image-5318\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/26-1024x561.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/26-300x164.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/26-768x421.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/26.png 1039w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>In the <strong>Data creation options<\/strong> section, you&#8217;ll find more settings related to data restoration. There are a few advanced options that may require a tweak in certain cases. However, for most website owners, the default configuration should work fine.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"584\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/27-1024x584.png\" alt=\"How to Back Up a MySQL Database, Backing up a single database 7\" class=\"wp-image-5319\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/27-1024x584.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/27-300x171.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/27-768x438.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/27.png 1121w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>After you&#8217;re done tweaking the settings, click <strong>Go<\/strong> to<strong> generate the backup<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>Multiple database backups<\/strong><\/strong><\/h3>\n\n\n\n<p>The steps to back<strong> up multiple databases<\/strong> are pretty much the same as those for dumping a single one. The difference is, instead of selecting a database from the menu on the left, you need to go straight to the <strong>Export <\/strong>tab from the homepage.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"501\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/28-1024x501.png\" alt=\"How to Back Up a MySQL Database, Multiple database backups\" class=\"wp-image-5320\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/28-1024x501.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/28-300x147.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/28-768x376.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/28.png 1234w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>If you&#8217;d like to back up all your databases at once, set the export method to <strong>Quick<\/strong> and the format to <strong>SQL<\/strong>, and click <strong>Go<\/strong> to have phpMyAdmin generate the backup. If you select the <strong>Custom <\/strong>method, you will be choosing which databases to back up. Click <strong>Unselect all<\/strong> and mark the ones you want to back up using the <strong>Ctrl\/Cmd<\/strong> key.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"493\" height=\"481\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/29.png\" alt=\"How to Back Up a MySQL Database, Multiple database backups 2\" class=\"wp-image-5321\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/29.png 493w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/29-300x293.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>Further down, in the <strong>Format-specific options<\/strong> section, you can decide whether to dump data from the selected databases, back up the structure only, or both.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"767\" height=\"518\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/30.png\" alt=\"How to Back Up a MySQL Database, Multiple database backups 3\" class=\"wp-image-5322\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/30.png 767w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/30-300x203.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>The rest of the settings are the same as the ones you see when you&#8217;re exporting a single database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Creating-a-Database-Backup-With-MySQL-Workbench\"><strong><strong>Database Backups With MySQL Workbench<\/strong><\/strong><\/h2>\n\n\n\n<p>MySQL Workbench is another free database management tool. You can set it up on your home computer (it&#8217;s available for Linux, Windows, and MacOS) and control your databases remotely.<\/p>\n\n\n\n<p>You&#8217;ll first need to<strong> connect to your hosting account<\/strong>. There&#8217;s a <strong>+<\/strong> button in the <strong>MySQL Connections<\/strong> section on the homepage.<\/p>\n\n\n\n<p>Next, you have to determine how you&#8217;re going to connect to the server. The best option is to use the<strong> standard TCP\/IP protocol over SSH<\/strong>. This way, the communication will be encrypted, and your data will be safe.<\/p>\n\n\n\n<p>You&#8217;ll have to provide the <strong>SSH login credentials<\/strong> as well as the ones for your <strong>MySQL user account<\/strong>. After you fill in all the required fields, click <strong>Test Connection <\/strong>to ensure everything works. If it does, hit <strong>OK<\/strong> to save the the settings.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"786\" height=\"493\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/5.png\" alt=\"How to Back Up a MySQL Database, Database Backups With MySQL Workbench\" class=\"wp-image-5323\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/5.png 786w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/5-300x188.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/5-768x482.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>After you connect to the server, open the <strong>Administration tab<\/strong> in the <strong>Navigator<\/strong> section and click <strong>Data Export<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"443\" height=\"694\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/6.png\" alt=\"How to Back Up a MySQL Database, Database Backups With MySQL Workbench 2\" class=\"wp-image-5324\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/6.png 443w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/6-191x300.png 191w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>In the next window, you&#8217;ll see the databases your user can control and the <strong>different export options<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"583\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/7-1024x583.png\" alt=\"How to Back Up a MySQL Database, Database Backups With MySQL Workbench 3\" class=\"wp-image-5325\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/7-1024x583.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/7-300x171.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/7-768x437.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/7-1536x875.png 1536w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/7.png 1612w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>You can select the databases you want to with the using the checkboxes next to them. And when you click on a database, you&#8217;ll see all its tables, so you can <strong>exclude specific tables from the backup<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"807\" height=\"445\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/31.png\" alt=\"How to Back Up a MySQL Database, Database Backups With MySQL Workbench 4\" class=\"wp-image-5326\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/31.png 807w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/31-300x165.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/31-768x423.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>Below the lists of databases and tables, you have a drop-down menu letting you decide whether you want to back up the database, the structure, or both. When you&#8217;re ready with the configuration, click <strong>Start Export<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Creating-a-Database-Backup-With-SPanel\"><strong><strong>Database Backups in SPanel<\/strong><\/strong><\/h2>\n\n\n\n<p>SPanel strives to cover every aspect of modern website building and development. This includes database management, which is why every <strong>SPanel server comes with<\/strong> <strong>phpMyAdmin<\/strong> preinstalled.<\/p>\n\n\n\n<p>However, we wanted to ensure you have even more control over your site&#8217;s data, which is why, you have quite a few tools in the <strong>MySQL Databases <\/strong>section inside <strong>SPanel&#8217;s User Interface<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"897\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/8-1024x897.png\" alt=\"How to Back Up a MySQL Database, Database Backups in SPanel\" class=\"wp-image-5327\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/8-1024x897.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/8-300x263.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/8-768x672.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/8.png 1269w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>To get to the User Interface, you can either use the account&#8217;s login credentials at <strong><em>https:\/\/[the account&#8217;s domain name]\/spanel\/<\/em><\/strong> or log in to your server&#8217;s Admin Area and select <strong>Manage <\/strong>from the <strong>Actions<\/strong> drop-down menu next to your account.<\/p>\n\n\n\n<p>In the <strong>MySQL Databases<\/strong> section you&#8217;ll see a list of all the databases on your account. Locate the one you want to back up, open the <strong>Actions<\/strong> drop-down menu, and select <strong>Export &amp; Download Database<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"684\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/9-1024x684.png\" alt=\"How to Back Up a MySQL Database, Database Backups in SPanel 2\" class=\"wp-image-5328\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/9-1024x684.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/9-300x201.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/9-768x513.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/9.png 1309w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p><em>SPanel will put the data into an SQL file and save it inside the account&#8217;s home directory<\/em>. Then, a popup lets you download the file for local storage and remove it from the server.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"831\" height=\"344\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/10.png\" alt=\"How to Back Up a MySQL Database, Database Backups in SPanel 3\" class=\"wp-image-5329\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/10.png 831w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/10-300x124.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/10-768x318.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>This is the quickest way of backing up a database in SPanel, and it&#8217;s probably the one you should go for when you want to play it safe before making any changes to your website. It&#8217;s not the only method, though.<\/p>\n\n\n\n<p>If you want more options, go back to the SPanel user interface homepage and click <strong>Backups <\/strong>> <strong>New Manual Backup<\/strong>. Under <strong>Which databases do you want to include?<\/strong> section, you have a list of the existing databases on your account. you can select the ones you need via the checkboxes or click <strong>Add All <\/strong>to back up all of them.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"799\" height=\"224\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image22.webp\" alt=\"How to Back Up a MySQL Database, Database Backups in SPanel 4\" class=\"wp-image-5711\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image22.webp 799w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image22-300x84.webp 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image22-768x215.webp 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>Further down, you have a range of options, letting you configure anything from the backup&#8217;s contents to the encryption and compression mechanisms. You can even send it to a remote location by entering the target server&#8217;s FTP credentials.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"856\" height=\"896\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image21.webp\" alt=\"How to Back Up a MySQL Database, Database Backups in SPanel 5\" class=\"wp-image-5712\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image21.webp 856w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image21-287x300.webp 287w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image21-768x804.webp 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>Click <strong>Submit<\/strong>, and a few seconds later, the archive will be available under the <strong>Backups <\/strong>> <strong>Manual Backups <\/strong>section. Your last backup is at the top of the list.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"526\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image17-1024x526.webp\" alt=\"How to Back Up a MySQL Database, Database Backups in SPanel 6\" class=\"wp-image-5713\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image17-1024x526.webp 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image17-300x154.webp 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image17-768x395.webp 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image17-1536x789.webp 1536w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image17.webp 1903w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>In addition to the manual backups they create themselves, every SPanel customer at ScalaHosting has <strong>daily secure copies of their files and databases, which are stored in a remote backup location<\/strong>.<\/p>\n\n\n\n<p>They&#8217;re <strong>not in the same data center<\/strong> as your production site, so even if the system crashes and the entire server fails, you can recover the information in seconds. If your backed up databases are stored in a cloud environment, you have <strong>multiple servers <\/strong>working simultaneously to guarantee that the data can be restored should the need arises.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Automatically Back Up a MySQL Database in Linux<\/strong><\/h2>\n\n\n\n<p>If you use a self-managed web hosting service, you are unlikely to have a tool for creating automatic database backups. You&#8217;ll have to create one yourself, which will probably sound a bit intimidating. If you&#8217;re not used to working with Linux, the prospect may sound even more daunting.<\/p>\n\n\n\n<p>However, once you understand the logic, you&#8217;ll see that there&#8217;s nothing scary about the task.<\/p>\n\n\n\n<p>In essence, our backup solution revolves around a simple script that uses the mysqldump utility to dump selected databases, compresses them with gzip, and, after naming them according to a predetermined convention, saves them to a backup folder on your server.<\/p>\n\n\n\n<p>There are several options for creating the script. You can use a text editor on your local computer and then upload the script to the server. If your server comes with a control panel, you can also use the File Manager and the built-in editor to set it up. And for those who prefer to use the command line for these sorts of things, there are text editors like GNU nano and Vim.<\/p>\n\n\n\n<p>We&#8217;re creating a shell script, so the file must have an .sh extension (e.g., dbbackup.sh). You can situate it in any directory on your server.<\/p>\n\n\n\n<p>In addition to creating new backups, the script is also responsible for deleting old ones. All this in no more than a few dozen lines of code. Here it is:<\/p>\n\n\n\n<p><strong><em>#!\/usr\/bin\/bash<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Date format<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>DATE_FORMAT=$(date +&#8221;%Y-%m-%d&#8221;)<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># MySQL login credentials<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>MYSQL_HOST=&#8221;localhost&#8221;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>MYSQL_USER=&#8221;[Your MySQL account&#8217;s username.]&#8221;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>MYSQL_PASSWORD=&#8221;[Your MySQL account&#8217;s password.]&#8221;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Backup directory<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>LOCAL_BACKUP_DIR=&#8221;[The directory reserved for storing backups.]&#8221;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Retention period for the backup files<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>BACKUP_RETAIN_DAYS=07<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Database name(s)<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>DATABASES=&#8221;[The name of the database. If you want to back up multiple databases, simply separate them with spaces]&#8221;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Creating the backup directory<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>mkdir -p ${LOCAL_BACKUP_DIR}<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Using mysqldump to back up the databases and gzip to compress them<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>for db in $DATABASES; do<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp;mysqldump \\<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp;&nbsp;<\/em><\/strong><strong><em> <\/em><\/strong><strong><em>-h ${MYSQL_HOST} \\<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp;&nbsp;<\/em><\/strong><strong><em> <\/em><\/strong><strong><em>-u ${MYSQL_USER} \\<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp;&nbsp;<\/em><\/strong><strong><em> <\/em><\/strong><strong><em>-p${MYSQL_PASSWORD} \\<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp;&nbsp;<\/em><\/strong><strong><em> <\/em><\/strong><strong><em>&#8211;single-transaction ${db} | gzip -9 &gt; ${LOCAL_BACKUP_DIR}\/${db}-${DATE_FORMAT}.sql.gz<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>done<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Removing backups once their retention period runs out<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>DBDELDATE=`date +&#8221;${DATE_FORMAT}&#8221; &#8211;date=&#8221;${BACKUP_RETAIN_DAYS} days ago&#8221;`<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>if [ ! -z ${LOCAL_BACKUP_DIR} ]; then<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;cd ${LOCAL_BACKUP_DIR}<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;if [ ! -z ${DBDELDATE} ] &amp;&amp; [ -d ${DBDELDATE} ]; then<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;rm -rf ${DBDELDATE}<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;fi<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>fi<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>## End<\/em><\/strong><\/p>\n\n\n\n<p>Before you save the script, make sure you enter the correct information in the placeholders above. The next step is to ensure your shell script is executable. If you use a File Manager or an FTP client, you&#8217;ll likely have a button or a context menu option. Through SSH, you can use the following command:<\/p>\n\n\n\n<p><strong><em>$ chmod +x [the name of the script file]<\/em><\/strong><\/p>\n\n\n\n<p>At this point, you may want to test the script and ensure it works. Because we have a shell script, we can only start it from the command line. You can use the <strong><em>sh <\/em><\/strong>command followed by the name of the file.<\/p>\n\n\n\n<p>With that done, it&#8217;s time to add the script to a cron job and make sure it&#8217;s executed at regular intervals. If your server is equipped with a control panel, you most likely have a GUI-based tool for managing your cron jobs. It most likely looks something like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"803\" height=\"1024\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image24-803x1024.webp\" alt=\"How to Back Up a MySQL Database, Automatically Back Up a MySQL Database in Linux\" class=\"wp-image-5714\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image24-803x1024.webp 803w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image24-235x300.webp 235w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image24-768x980.webp 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image24.webp 881w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>The first fields and drop-downs determine how frequently the script will be executed, and in <strong>Cron command<\/strong>, you need to enter <strong><em>sh [the backup script&#8217;s filepath]<\/em><\/strong><strong>.<\/strong><\/p>\n\n\n\n<p>Alternatively, you can do it all from the command-line interface. To do that, you have to edit the <strong>crontab<\/strong> file. Your Linux server likely has multiple text editors installed and ready to use. However, GNU nano is recognized as the easiest to use, so the command we&#8217;ll enter looks like this:<\/p>\n\n\n\n<p><strong><em>$ EDITOR=nano crontab -e<\/em><\/strong><\/p>\n\n\n\n<p>You&#8217;ll see a configuration file with all your currently active cron jobs. If there aren&#8217;t any, the file will be blank.<\/p>\n\n\n\n<p>We want our dbbackup.sh file to be executed daily, but we don&#8217;t want it to run during the busy part of the day, when the server&#8217;s under heavy load. That&#8217;s why, we&#8217;ll schedule its execution for 2 AM. The line you need to add to your file is:<\/p>\n\n\n\n<p><strong><em>0 2 * * * sh [the filepath for your backup script]<\/em><\/strong><\/p>\n\n\n\n<p>On the next day, you can confirm whether the script has been executed correctly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Automatically Back Up a MySQL Database to Amazon S3<\/strong><\/h2>\n\n\n\n<p>The previous section showed you how to automate database backups on a self-managed Linux server. It&#8217;s a great way of getting some extra peace of mind, but the setup isn&#8217;t quite perfect.<\/p>\n\n\n\n<p>The backups you create with it are stored on your production server. If, for whatever reason, it goes down, your backups will become inaccessible, and you won&#8217;t be able to restore them as quickly as possible and minimize downtime. Worst case scenario, you could irreversibly lose some data.<\/p>\n\n\n\n<p>That&#8217;s why experts recommend storing your backups in a <strong>remote location<\/strong>.<\/p>\n\n\n\n<p>Now, you could get yourself another server just for your backups, but this will hardly be the most cost-effective solution. If it&#8217;s situated in the same data center as the production machine, it won&#8217;t be <a href=\"https:\/\/www.scalahosting.com\/blog\/the-importance-of-data-backups\/\">the most secure<\/a>, either.<\/p>\n\n\n\n<p>Using one of the popular cloud storage services like an AWS S3 bucket is a much better choice. As an added bonus, configuring your server to automatically send your database backups to Amazon&#8217;s cloud is relatively straightforward.<\/p>\n\n\n\n<p>Your first job is to make sure you have AWS CLI installed on your server.<\/p>\n\n\n\n<p>AWS CLI is available in most package managers, so if you use Ubuntu or another Debian-based distribution, you can install it with:<\/p>\n\n\n\n<p><strong><em>$ sudo apt install awscli<\/em><\/strong><\/p>\n\n\n\n<p>For CentOS 7 and similar distros, the command is:<\/p>\n\n\n\n<p><strong><em>$ sudo dnf install awscli<\/em><\/strong><\/p>\n\n\n\n<p>And for CentOS 8 and Fedora, it&#8217;s:<\/p>\n\n\n\n<p><strong><em>$ sudo yum install awscli<\/em><\/strong><\/p>\n\n\n\n<p>Alternatively, you can download the zip archive from <a href=\"https:\/\/awscli.amazonaws.com\/awscli-exe-linux-x86_64.zip\" rel=\"nofollow\">https:\/\/awscli.amazonaws.com\/awscli-exe-linux-x86_64.zip<\/a>, extract it, and install the utility manually.<\/p>\n\n\n\n<p>With AWS CLI installed, you need to head over to the AWS Management Console. Click on your root account email in the top-right corner, and select <strong>Security Credentials<\/strong> from the drop-down menu. Find the <strong>Access keys<\/strong> section and click <strong>Create access key<\/strong>.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"402\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image40-1024x402.webp\" alt=\"How to Back Up a MySQL Database, Automatically Back Up a MySQL Database to Amazon S3\" class=\"wp-image-5715\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image40-1024x402.webp 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image40-300x118.webp 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image40-768x301.webp 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image40-1536x603.webp 1536w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image40.webp 1861w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>This access key allows you to connect to your AWS account via AWS CLI. All you need to do is configure AWS CLI to use it. The command is:<\/p>\n\n\n\n<p><strong><em>$ aws configure<\/em><\/strong><\/p>\n\n\n\n<p>AWS CLI will as you for the Access Key ID, the Secret Access Key, the default region, and the output format. After you provide the information, you will be able to use AWS CLI to create a new S3 bucket and send your database backups to it.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"631\" height=\"120\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image35.webp\" alt=\"How to Back Up a MySQL Database, Automatically Back Up a MySQL Database to Amazon S3 2\" class=\"wp-image-5716\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image35.webp 631w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2024\/03\/image35-300x57.webp 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>Next, it&#8217;s time to create the bucket that will hold your backups. As you have an open shell, the easiest way to do it is with AWS CLI. The command is:<\/p>\n\n\n\n<p><strong><em>$ aws s3api create-bucket &#8211;bucket [the bucket&#8217;s name] &#8211;region [the nearest AWS location to your server]<\/em><\/strong><\/p>\n\n\n\n<p>If you prefer to use a graphical user interface, you can also set up the bucket via the AWS management console.<\/p>\n\n\n\n<p>The code from the previous section can already take care of creating, compressing, and cleaning backups, so what we need to do now is add the functionality that sends the secure copies to your AWS S3 bucket. With it, your shell script should look like this:<\/p>\n\n\n\n<p><strong><em>#!\/usr\/bin\/bash&nbsp;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Date format<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>DATE_FORMAT=$(date +&#8221;%d-%m-%Y&#8221;)<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># MySQL login credentials<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>MYSQL_HOST=&#8221;localhost&#8221;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>MYSQL_USER=&#8221;[Your user&#8217;s username]&#8221;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>MYSQL_PASSWORD=&#8221;[The user&#8217;s password]&#8221;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Backup directory on the server<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>LOCAL_BACKUP_DIR=&#8221;[a directory on your server where you&#8217;ll store backups, e.g., home\/user\/backups\/]&#8221;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># S3 bucket details<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>S3_BUCKET_NAME=&#8221;[your S3 bucket&#8217;s name]&#8221;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>S3_BUCKET_PATH=&#8221;[a directory in the bucket reserved for your backups]&#8221;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Retention period for local backup files<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>BACKUP_RETAIN_DAYS=7<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Database name(s)<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>DATABASES=&#8221;[if you want to back up multiple databases, add their names separated by spaces]&#8221;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Creating a new directory for today&#8217;s backup<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>mkdir -p ${LOCAL_BACKUP_DIR}<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;# Setting the local and remote backup directories<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>LOCAL_DIR=${LOCAL_BACKUP_DIR}<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>REMOTE_DIR=s3:\/\/${S3_BUCKET_NAME}\/${S3_BUCKET_PATH}<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Using mysqldump to back up the selected databases and gzip to archive them<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>for db in $DATABASES; do<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp;mysqldump \\<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-h ${MYSQL_HOST} \\<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-u ${MYSQL_USER} \\<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-p${MYSQL_PASSWORD} \\<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211;single-transaction ${db} | gzip -9 &gt; ${LOCAL_BACKUP_DIR}\/${db}-${DATE_FORMAT}.sql.gz<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Using AWS CLI to send the backup to the S3 bucket<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aws s3 cp ${LOCAL_DIR}\/${db}-${DATE_FORMAT}.sql.gz ${REMOTE_DIR}\/${DATE_FORMAT}\/<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>done<\/em><\/strong><\/p>\n\n\n\n<p><strong><em># Removing backups after their retention period runs out<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>DBDELDATE=`date +&#8221;${DATE_FORMAT}&#8221; &#8211;date=&#8221;${BACKUP_RETAIN_DAYS} days ago&#8221;`<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>if [ ! -z ${LOCAL_BACKUP_DIR} ]; then<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>cd ${LOCAL_BACKUP_DIR}<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>if [ ! -z ${DBDELDATE} ] &amp;&amp; [ -d ${DBDELDATE} ]; then<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>rm -rf ${DBDELDATE}<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>fi<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>fi<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>## end<\/em><\/strong><\/p>\n\n\n\n<p>From here on, the steps are the same as the ones described in the previous section: you add execution permissions to the SH file, test it to make sure it works, and add it as a cron job.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Restoring-a-MySQL-Database\"><strong><strong>Restoring a MySQL Database<\/strong><\/strong><\/h2>\n\n\n\n<p>Once again, you have several methods to choose from, and which one you&#8217;ll pick depends on many things, including your <strong>hosting platform<\/strong>, your technical skills, and your needs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>How to restore\u00a0 MySQL databases via the command line?<\/strong><\/strong><\/h3>\n\n\n\n<p>To restore a database from the command line, you first need to <strong>upload the backup file<\/strong> to your hosting account. The easiest way is via an FTP client or from your control panel&#8217;s File Manager.<\/p>\n\n\n\n<p>You can place it in any folder you want, but to keep the commands simple, it&#8217;s probably best to save it <strong>in the home directory<\/strong>. After you restore the database, you can delete the backup file to free up some storage.<\/p>\n\n\n\n<p>Next, <a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-create-a-database-in-mysql\/\">create a new empty database<\/a> and a MySQL user account with access to it. You can also use an account with SYSTEM_USER privileges.<\/p>\n\n\n\n<p><strong><strong>Connect to your hosting account via SSH and use the following command:<\/strong><\/strong><\/p>\n\n\n\n<p><em><em>$ mysql -u [your user account&#8217;s username] -p [the name of the database] &lt; [the name of the backup file]<\/em><\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"893\" height=\"562\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/11-1.png\" alt=\"How to Back Up a MySQL Database, How to restore\u00a0 MySQL databases via the command line?\" class=\"wp-image-5330\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/11-1.png 893w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/11-1-300x189.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/11-1-768x483.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>In the above example, user account <strong>test_user <\/strong>is restoring data into database <strong>test_database2<\/strong> from the file <strong>backup.sql<\/strong>. There are a few optional parameters with various functions, which are explained in detail in MySQL&#8217;s documentation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>Restoring a database with phpMyAdmin<\/strong><\/strong><\/h3>\n\n\n\n<p>You can use<strong> phpMyAdmin&#8217;s import feature to recover data from SQL files<\/strong>. You need to remember that there&#8217;s often a limit on how big the backup file can be, so if you have a larger database, you&#8217;ll probably need to use one of the other methods.<\/p>\n\n\n\n<p>To import data into an existing database, open phpMyAdmin and select the database you want to restore from the menu on the left. If the database doesn&#8217;t exist, you&#8217;ll need to create it first.<\/p>\n\n\n\n<p>Go to the <strong>Import <\/strong>tab, click <strong>Choose File<\/strong>, and select the SQL backup from your computer.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"538\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/12-1024x538.png\" alt=\"How to Back Up a MySQL Database, Restoring a database with phpMyAdmin\" class=\"wp-image-5331\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/12-1024x538.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/12-300x158.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/12-768x403.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/12-1536x806.png 1536w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/12.png 1619w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>The most important option on this screen is the <strong>Format<\/strong> drop-down. You have to ensure it&#8217;s set to <strong>SQL<\/strong>. The default configuration will likely work fine for most website owners. After you click <strong>Go<\/strong>, phpMyAdmin will update the selected database with the information from the backup file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>Restoring a database with MySQL Workbench<\/strong><\/strong><\/h3>\n\n\n\n<p>Like the other utilities we&#8217;re discussing in today&#8217;s tutorial, <strong>MySQL Workbench<\/strong> has both export and import capabilities. To restore a database, launch MySQL Workbench and open a connection to your server. In the <strong>Navigator <\/strong>section, select the <strong>Administration <\/strong>tab and click <strong>Data Import\/Restore<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"624\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/13-1024x624.png\" alt=\"How to Back Up a MySQL Database, Restoring a database with MySQL Workbench\" class=\"wp-image-5332\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/13-1024x624.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/13-300x183.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/13-768x468.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/13.png 1442w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>Click the <strong>Import from Self-Contained File<\/strong> radio button, and select the SQL backup file from your computer.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/14-1024x640.png\" alt=\"How to Back Up a MySQL Database, Restoring a database with MySQL Workbench 2\" class=\"wp-image-5333\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/14-1024x640.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/14-300x188.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/14-768x480.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/14.png 1468w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>Finally, click <strong>Start Import<\/strong> to restore the database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>Restoring a database with SPanel<\/strong><\/strong><\/h3>\n\n\n\n<p>If you have an SPanel server, you can <strong>restore your database from an SQL backup file <\/strong>using any of the methods we&#8217;ve described so far. However, you can also retrieve the data from one of the<strong> automatic daily backups SPanel generates.<\/strong><\/p>\n\n\n\n<p>When <strong>setting up your new SPanel server at ScalaHosting<\/strong>, you can choose how many backups you want to have stored at any given time. By default, you have a daily backup that is kept for 24 hours. However, we also have three- and seven-day options.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"762\" height=\"467\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/15.png\" alt=\"How to Back Up a MySQL Database, Restoring a database with SPanel\" class=\"wp-image-5334\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/15.png 762w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/15-300x184.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>The backups are accessible via the <strong>Restore backup <\/strong>section on the homepage of SPanel&#8217;s User Interface.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"684\" height=\"1024\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/16-684x1024.png\" alt=\"How to Back Up a MySQL Database, Restoring a database with SPanel 2\" class=\"wp-image-5335\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/16-684x1024.png 684w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/16-200x300.png 200w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/16-768x1150.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/16-1026x1536.png 1026w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/16.png 1318w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>First, choose the date of the backup you want to restore and click <strong>Browse Databases<\/strong> to see the dumped databases from the selected day.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"845\" height=\"633\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/17.png\" alt=\"How to Back Up a MySQL Database, Restoring a database with SPanel 3\" class=\"wp-image-5336\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/17.png 845w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/17-300x225.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/17-768x575.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>Find the database you need and open the <strong>Restore <\/strong>drop-down menu.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full mpg-gallery\"><img decoding=\"async\" width=\"856\" height=\"221\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/18.png\" alt=\"How to Back Up a MySQL Database, Restoring a database with SPanel 4\" class=\"wp-image-5337\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/18.png 856w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/18-300x77.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/18-768x198.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p><strong>You have three options:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Download an SQL file<\/strong> with a backup of the database.<\/li>\n\n\n\n<li><strong>Restore the original database<\/strong>.<\/li>\n\n\n\n<li><strong>Restore the data in another database<\/strong>. SPanel will open a dialog requesting the name of the database you&#8217;d like to use. You can restore the data in an existing database or enter the name of a new one. SPanel will automatically set it up for you.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Potential-Problems-While-Trying-to-Backup-a-MySQL-Database\"><strong><strong>Potential Problems While Trying to Backup a MySQL Database<\/strong><\/strong><\/h2>\n\n\n\n<p>The export process can fail and result in an error for a couple of different reasons. Luckily, troubleshooting the problem is usually pretty straightforward. Let&#8217;s have a look at some of them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>The MySQL Server isn&#8217;t working<\/strong><\/strong><\/h3>\n\n\n\n<p>First, you need to make sure the <a href=\"https:\/\/www.scalahosting.com\/kb\/what-is-my-mysql-server-hostname\/\"><strong>MySQL server<\/strong><\/a> is running on your hosting account. You can do it over SSH with the following command:<\/p>\n\n\n\n<p><em>$ service mysql status<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"522\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/33-1024x522.png\" alt=\"How to Back Up a MySQL Database, The MySQL Server isn&#8217;t working\" class=\"wp-image-5338\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/33-1024x522.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/33-300x153.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/33-768x392.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/33.png 1226w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>If you use SPanel, you can also check whether the MySQL installation is running from the Admin Interface. The list of essential services is available in the Server Status menu, and if the <strong>MariaDB Database Server<\/strong> is down for some reason, you can bring it back online from the <strong>Restart Service<\/strong> section.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"637\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/34-1024x637.png\" alt=\"How to Back Up a MySQL Database, The MySQL Server isn&#8217;t working 2\" class=\"wp-image-5339\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/34-1024x637.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/34-300x187.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/34-768x478.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/34.png 1278w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>There are corrupted tables in your database<\/strong><\/strong><\/h3>\n\n\n\n<p>As we mentioned already, you can use the <strong><em>mysqlcheck<\/em><\/strong><em> <\/em>command-line utility to see whether there are any corrupted database tables. It can also fix errors in case it fails because of a broken row or table.<\/p>\n\n\n\n<p>All you need is the <strong><em>-r <\/em><\/strong>option:<\/p>\n\n\n\n<p><strong><em><strong><em>$ mysqlcheck [the database&#8217;s name] -u [the user account&#8217;s username] -p -r<\/em><\/strong><\/em><\/strong><\/p>\n\n\n\n<p>Corrupted databases can also be fixed via phpMyAdmin and SPanel.<\/p>\n\n\n\n<p>In <strong>phpMyAdmin<\/strong>, pick the database from the menu on the left, and you will be redirected straight to the <strong>Structure <\/strong>tab, where you&#8217;ll see a list of all the database&#8217;s tables. Use the checkboxes to select tables for repairs (<em>if you&#8217;re not sure where the issues are, you can use the <\/em><strong><em>Check all<\/em><\/strong><em> option at the bottom<\/em>) and click <strong>Repair table<\/strong> from the <strong>With selected<\/strong> menu.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"681\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/35-1024x681.png\" alt=\"How to Back Up a MySQL Database, There are corrupted tables in your database\" class=\"wp-image-5340\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/35-1024x681.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/35-300x200.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/35-768x511.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/35.png 1399w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<p>With SPanel, the process is even simpler. Log in to the account&#8217;s User Interface and go to <strong>MySQL Databases<\/strong>. Scroll down to the list of databases, find the one you want and open the <strong>Actions<\/strong> drop-down menu next to it. After you select <strong>Repair database<\/strong>, SPanel will locate and fix any errors that might be present in the database&#8217;s tables.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large mpg-gallery\"><img decoding=\"async\" width=\"1024\" height=\"323\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/36-1024x323.png\" alt=\"How to Back Up a MySQL Database, There are corrupted tables in your database 2\" class=\"wp-image-5341\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/36-1024x323.png 1024w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/36-300x95.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/36-768x242.png 768w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/11\/36.png 1223w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><strong>The disk is full<\/strong><\/strong><\/h3>\n\n\n\n<p>The backup is generated on the server, so it inevitably takes up some of your account&#8217;s storage capacity. If you exceed it<strong> <\/strong>while you&#8217;re creating a backup, the process will fail.<\/p>\n\n\n\n<p>Your first option is to <strong>pipe the backup through gzip<\/strong>. This will reduce its size and may be enough to let you retrieve an archive with the SQL inside it. However, you should also think about deleting any unnecessary information from your account, <strong>optimizing your database<\/strong>, and possibly upgrading your account, so you can have more storage.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Backing up your site&#8217;s files is relatively straightforward. In essence, you put them all in an archive, which you can later extract and restore everything. When it comes to generating backups of your MySQL databases, however, things are a bit more complicated. Today, we&#8217;ll look into the different types of database backups, and we&#8217;ll see [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":5378,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","_seopress_analysis_target_kw":"","footnotes":""},"categories":[34],"tags":[],"class_list":["post-5302","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-hosting"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/5302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/comments?post=5302"}],"version-history":[{"count":6,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/5302\/revisions"}],"predecessor-version":[{"id":5717,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/5302\/revisions\/5717"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/media\/5378"}],"wp:attachment":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/media?parent=5302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/categories?post=5302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/tags?post=5302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}