# Using phpMyAdmin to copy a MySQL database

> Copy a MySQL database with phpMyAdmin, either by exporting and importing it or with the built-in copy option.

Source: https://helpcenter.ruachost.com/cpanel/databases/using-phpmyadmin-to-copy-a-mysql-database/

phpMyAdmin provides a simple way to duplicate a database. This is useful for creating backups, testing changes, or migrating data to a new environment.

## Why Copy a Database?

- Create a **backup** before making major changes.
- Set up a **staging environment** for testing.
- Duplicate data for **migration** to another domain or server.

## Method 1: Export and Import

This is the most common and reliable way to copy a database.

### Step 1: Export the Source Database

1. Log in to **cPanel → phpMyAdmin**.
2. Select the database you want to copy from the left sidebar.
3. Click the **Export** tab.
4. Choose **Quick** export method and **SQL** format.
5. Click **Go** → download the `.sql` file to your computer.

### Step 2: Create a New Database

1. In **cPanel → MySQL Databases**, create a new database.
2. Create a new user and assign it to the database with **ALL PRIVILEGES**.

### Step 3: Import into the New Database

1. In **phpMyAdmin**, select the new database.
2. Click the **Import** tab.
3. Upload the `.sql` file you exported.
4. Click **Go** → phpMyAdmin imports all tables and data.

## Method 2: Copy Within phpMyAdmin (Single Database Server)

phpMyAdmin also allows copying tables directly if both databases exist on the same server.

1. Log in to **phpMyAdmin**.
2. Select the source database → choose a table.
3. Click **Operations** tab.
4. Under **Copy table to (database.table)**:

   - Enter the destination database name.
   - Choose whether to copy **structure only** or **structure and data**.
5. Repeat for each table until the database is duplicated.

## Notes

- Export/Import is recommended for **full database copies**.
- Table‑by‑table copy is useful for **partial duplication**.
- Always back up before making changes.
- Large databases may take longer to export/import.
