> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Backing up MySQL databases using AutoMySQLBackup

> Learn to back up MySQL databases using AutoMySQLBackup with our detailed guide, code snippets, and more.

This article describes how to use the AutoMySQLBackup tool to back up MySQL databases.

AutoMySQLBackup is a flexible script that enables you to create backups at varying intervals, such as daily, weekly, and monthly. By rotating your backups, you can preserve storage space on your account. You can even send backup files to external e-mail accounts for off-site backup redundancy.

<Note>
  * [Server Rewind](/docs/server-rewind) on managed VPS accounts does not include database backups and restores, so you should follow the procedures below to set up your own database backups on a managed VPS. AutoMySQLBackup does **not** work on Shared and Reseller servers, or on Dedicated servers running CloudLinux.

  * Although hosting.com servers are compatible with a wide variety of software applications, we cannot provide troubleshooting assistance for application-specific issues. The procedures below are for demonstration purposes only.
</Note>

## Downloading and installing AutoMySQLBackup

To download and install AutoMySQLBackup on your account, follow these steps:

1. Use your web browser to go to [http://sourceforge.net/projects/automysqlbackup](http://sourceforge.net/projects/automysqlbackup), and then click **Download**. Save the .tar.gz file on your computer.

2. Upload the .tar.gz file to your hosting.com account. To do this, you can use [FTP](/docs/using-ftp-file-transfer-protocol), [SFTP](/docs/using-ftp-file-transfer-protocol), or the [cPanel File Manager](/docs/upload-and-download-files) (if your account includes cPanel access).

3. Log in to your account using SSH.

4. At the command prompt, change to the directory where you uploaded the .tar.gz file in step 2.

5. To extract the application files from the .tar.gz file, type the following command:

   ```bash theme={null}
   tar xvzf automysqlbackup-v3.0_rc6.tar.gz
   ```

   > 📘 Note
   >
   > The exact filename may differ slightly, depending on the version you downloaded.

6. To install AutoMySQLBackup, type the following command:

   ```bash theme={null}
   ./install.sh
   ```

7. At the **Select the global configuration directory** prompt, type the path where the configuration files will be stored.

8. At the **Select directory for the executable** prompt, type the path where the program file will be stored.

## Configuring AutoMySQLBackup

After you download and install AutoMySQLBackup, you can configure the settings for your own environment. To do this, follow these steps:

1. Log in to your account using SSH.

2. Use a text editor to edit the *myserver.conf* file. The myserver.conf file is located in the configuration directory that you specified in the previous procedure.

3. To configure basic backup settings, remove the pound sign ( **#** ) from the start of the following lines in the myserver.conf file, and then change the values to match your own installation:

   ```
   CONFIG_mysql_dump_username='username'
   CONFIG_mysql_dump_password='password'
   CONFIG_backup_dir='/home/username/mysqlbackups'
   ```

   > 📘 Note
   >
   > Make sure you use a MySQL username and password, and not the username and password you use to log in to SSH. Addtionally, make sure that the path you specify for the backup directory exists. AutoMySQLBackup does not automatically create the directory.

4. To specify specific databases to back up, remove the pound sign (**#** ) from the start of the following line, and change the value to the databases you want to back up:

   ```
   CONFIG_db_names=()
   ```

   > 📘 Note
   >
   > By default, AutoMySQLBackup backs up all MySQL databases. You only need to change this setting if you want to back up specific databases.

5. To specify rotation settings for the different backup intervals, remove the pound sign (**#** ) from the start of the following lines, and then change the values to the rotation settings that you want:

   ```
   CONFIG_rotation_daily=6
   CONFIG_rotation_weekly=35
   CONFIG_rotation_monthly=150
   ```

6. To send backup files to an e-mail account, remove the pound sign (**#** ) from the start of the following lines, and then modify them as shown. [Replace*user@example.com*](mailto:Replace_user@example.com_) with the e-mail address where you want to send the backup files:

   ```
   CONFIG_mailcontent='files'
   CONFIG_mail_use_uuencoded_attachments='yes'
   CONFIG_mail_address='user@example.com'
   ```

   > 🚧 Important
   >
   > We strongly recommend that you periodically store database backup files at a location separate from the web server. The e-mail feature in AutoMySQLBackup is one way to easily accomplish this.

7. Save the changes to the *myserver.conf* file and exit the text editor.

## Running a backup

After you configure AutoMySQLBackup for your environment, you can run backups. To run a backup manually using AutoMySQLBackup, type the following command. Replace *path* with the path to the myserver.conf file:

```bash theme={null}
automysqlbackup "path/myserver.conf"
```

However, you will most likely want to automate the process and create backups automatically. To do this, you can set up a cron job that runs the following command. Replace the *username* and *path* values as required by your own configuration:

```bash theme={null}
/home/username/path/automysqlbackup "path/myserver.conf"
```

For more information about how to use cPanel to create a cron job, please see [this article](/docs/cron-jobs).

## Related articles

* [Connecting to MySQL from the command line](/docs/connect-to-mysql-from-the-command-line)

* [MySQL database backups using cron jobs](/docs/mysql-database-backups-using-cron-jobs)

* [Importing and exporting a MySQL database](/docs/import-and-export-a-mysql-database)

* [Managing MySQL databases, users, and tables from the command line](/docs/managing-mysql-databases-and-users-from-the-command-line)
