# Import a large database
Source: https://docs.webgee.com/en/databases/how-to-import-a-large-database-into-mysql



Import a `.sql` file that phpMyAdmin cannot handle. Applies to shared, reseller
and Premium hosting.

phpMyAdmin imports through your browser, so it is limited by upload size and
execution time. Anything much over 50 MB tends to time out part-way, leaving a
half-imported database — which is worse than a clean failure.

## Before you begin [#before-you-begin]

You need:

* **The `.sql` file uploaded to your account**, usually to your home directory.
  Use File Manager or FTP — see
  [Upload files with FileZilla](/en/hosting/using-filezilla-to-upload-files-via-sftp-ssh-or-ftps-ssl-tls).
* **An existing, empty database** and a user with privileges on it. The import
  does not create one — see
  [Create and manage MySQL databases](/en/databases/how-to-create-and-manage-mysql-databases-in-cpanel).
* **SSH access** — see [Connect over SSH](/en/development/connect-via-ssh).

## Import over SSH [#import-over-ssh]

Connect, then run:

```bash
mysql -p -u cpaneluser_dbuser cpaneluser_dbname < ~/database.sql
```

Enter the database user's password when prompted. Both names carry your cPanel
username as a prefix.

Nothing is printed while it runs. A large import takes minutes; the prompt
returning is the signal it finished.

<Callout type="info">
  Put the password on the command line only if you must — `-p'password'` with no
  space. It ends up in your shell history, so prefer being prompted.
</Callout>

### A compressed dump [#a-compressed-dump]

No need to extract it first:

```bash
gunzip < ~/database.sql.gz | mysql -p -u cpaneluser_dbuser cpaneluser_dbname
```

## Check it worked [#check-it-worked]

```bash
mysql -p -u cpaneluser_dbuser cpaneluser_dbname -e "SHOW TABLES;"
```

Compare the table count against the source database. A short list means the
import stopped early.

## If SSH is not available [#if-ssh-is-not-available]

Split the file instead. Most database export tools can export table by table, so
you can import each part through phpMyAdmin separately.

Alternatively compress the dump — phpMyAdmin accepts `.sql.gz`, and the smaller
upload often gets under the limit that was stopping you.

## If the import fails part-way [#if-the-import-fails-part-way]

* **`MySQL server has gone away`** — a single statement exceeded the packet
  limit, usually a very large row. Open a ticket.
* **`Access denied`** — the user has no privileges on that database. Check
  **Add User To Database** in cPanel.
* **`Table already exists`** — the database was not empty. Drop the tables and
  import again; a partial import cannot be resumed.

## Related [#related]

* [Create and manage MySQL databases](/en/databases/how-to-create-and-manage-mysql-databases-in-cpanel)
* [Allow remote MySQL connections](/en/databases/mysql-remote-connections)
* [Connect over SSH](/en/development/connect-via-ssh)
