# Create and connect a database

Create PostgreSQL or MySQL safely, connect an application and verify imports, credentials and backups.

## Before you start

- Know whether the application supports PostgreSQL, MySQL or both.

- Have the required schema, migration commands or an export file ready.

- Know which application and environment will use the database.

- For imports, confirm the export engine and format match the selected database engine.

Create a standalone database or create one while deploying an application.
- [Create Database](/dashboard/databases/create) — Create and manage a database independently.
- [Deploy Application](/dashboard/applications/create) — Create and connect a database in one flow.

## 1. Choose the correct engine

Use the engine required by the application and its libraries. PostgreSQL and MySQL are not interchangeable dump formats. Source detection may suggest an engine from manifests and environment examples, but the repository documentation remains authoritative.

## 2. Create names and credentials

1. Choose PostgreSQL or MySQL and an available version.
2. Enter the editable portion of the database name. Ghost Deploy adds the workspace prefix automatically.
3. Create a restricted database user or select an existing workspace database user.
4. Generate a strong password, copy it into the application's environment values and store it in an approved secret manager.
5. Wait for the database status to become Active before importing data or starting the application.

## 3. Connect the application

Use the Environment editor to fill separate host, port, database, username and password keys, or generate a connection URL when the application expects one value. Never use the management endpoint shown for external administration as an internal application hostname unless the guide explicitly says so.

## 4. Import or migrate data

1. Open the database and choose Import / Export.
2. Select the format that matches the file. Plain SQL and native archive formats use different restore tools.
3. Keep compatibility adjustments enabled for third-party exports unless you need strict failure behaviour.
4. Review every reported compatibility adjustment. Ghost Deploy changes only a temporary import copy.
5. After completion, open Tables and verify important tables and representative rows.

> **success:** A database connection is proven only when the application can connect and expected migrations or queries succeed. An Active database status proves the service is running, not that application credentials are correct.

## If something does not work

- Connection refused or timed out: confirm the correct host, port and network context.

- Authentication failed: re-copy the database name, restricted username and password; invisible spaces are common.

- Import says the archive is invalid: verify whether the file is plain SQL, a custom PostgreSQL archive or a compressed file before retrying.

- Server-version mismatch during backup: use a dump client matching or newer than the database server major version.

- Migration fails after deployment: open the deployment log, fix the first migration error and use a safety backup before retrying destructive changes.

## Related guides and references

- [Open Databases](/dashboard/databases) — Review database status, backups, imports and access.

- [PostgreSQL backup documentation](https://www.postgresql.org/docs/current/backup-dump.html) — Official pg_dump and pg_restore format guidance.

- [MySQL backup documentation](https://dev.mysql.com/doc/refman/8.4/en/backup-and-recovery.html) — Official MySQL backup and recovery guidance.

Source: https://ghostdeploy.com/docs/databases/create-and-connect-a-database