> For the complete documentation index, see [llms.txt](https://docs.glesys.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.glesys.com/products/database/how-tos/connect-to-a-database.md).

# Connect to a database

Connecting to a database works the same for MySQL and PostgreSQL

***

All the details needed to connect to a database are shown on the specific database's overview page in the control panel.

<figure><img src="https://3379166260-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlMZhhdQNcWOpX5Bj48GK%2Fuploads%2FTaWlOmIOsCEPMKq8rJCZ%2Fdbaas-connection-details.png?alt=media&amp;token=cc7b3ad0-3c53-4d3e-b0b2-906789bb9c50" alt=""><figcaption></figcaption></figure>

The connection string shown in the overview can be used directly in most programs and programming languages. However, some tools instead require separate values for hostname, port, username, and password. These values can be extracted from the connection string.

For example, given the following connection string:

```
postgresql://dbadmin:xxxyyy@db-4f959.database-v1.glesys.com:5432/defaultdb?ssl-mode=required
```

* The database type is *PostgreSQL*.
* The username is *dbadmin*.
* The password is *xxxyyy*.
* The hostname is [*db-4f959.database-v1.glesys.com*](http://db-4f959.database-v1.glesys.com) (after the @ symbol).
* The port is *5432* (the default port for PostgreSQL).
* The database name is *defaultdb*.
* The connection requires SSL encryption, as indicated by the `ssl-mode=required` parameter.

## Custom users and databases

For databases and users you have created yourself, you can use the connection string builder on the overview page. This lets you create complete connection strings for your custom users and databases using the drop-down menus. If you click the eye icon, it even includes your password. Note that the drop-down menus only appear if you have created custom users and databases.

<figure><img src="https://3379166260-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlMZhhdQNcWOpX5Bj48GK%2Fuploads%2F0GczkpjynebPBMlNhurN%2Fdbaas-connection-string-builder.png?alt=media&amp;token=4ba92af1-26a0-49cc-b736-5fc77601f82c" alt=""><figcaption></figcaption></figure>

## Example with DBeaver

After launching the DBeaver application, either click **Database → New Database Connection** from the menu or press <kbd>Shift+Ctrl+N</kbd> on the keyboard. This opens the dialog for creating a new database connection.

First, select the type of database—either *MySQL* or *PostgreSQL*. In this example, we want to connect to a PostgreSQL database. Click **PostgreSQL**, then click **Next**. (The procedure is pretty much the same for MySQL.)

<div align="left"><figure><img src="https://3379166260-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlMZhhdQNcWOpX5Bj48GK%2Fuploads%2FhWv3XNLJFk9kkLfHEJpk%2Fdbaas-dbeaver1.png?alt=media&amp;token=a369df19-3d75-46ae-af33-65afe9bc6b27" alt=""><figcaption></figcaption></figure></div>

In the next dialog box, enter all the necessary information for the database connection, such as hostname, port, database name, username, and password.

<div align="left"><figure><img src="https://3379166260-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlMZhhdQNcWOpX5Bj48GK%2Fuploads%2FEd4TpBbOVZxft0nLPGWL%2Fdbaas-dbeaver2.png?alt=media&amp;token=4c68357c-b64c-457b-beb6-08e2ef752e4a" alt=""><figcaption></figcaption></figure></div>

Once you’ve filled in all the required information on the **Main** tab, click the **SSL** tab. Here, check **Use SSL**. Under **SSL mode**, select **require**. Finally, click **Finish**.

<div align="left"><figure><img src="https://3379166260-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlMZhhdQNcWOpX5Bj48GK%2Fuploads%2FefSJfV7t5n7pbu4JqE7U%2Fdbaas-dbeaver3.png?alt=media&amp;token=4b1f08f9-4c52-45aa-9ea2-7e18d045b1f6" alt=""><figcaption></figcaption></figure></div>

Now, click the down-arrow icon in front of *defaultdb* under **Connections**. DBeaver should now connect to the database. You can then continue expanding the tree by clicking the down arrows until you see the *defaultdb* database and its contents.

<div align="left"><figure><img src="https://3379166260-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlMZhhdQNcWOpX5Bj48GK%2Fuploads%2Fprrp2ScHe7Eylds920E4%2Fdbaas-dbeaver4.png?alt=media&amp;token=1083cfe2-3925-4195-9766-92680539f131" alt=""><figcaption></figcaption></figure></div>

From here, you can start working with your database—either by using the SQL console (**SQL Editor → Open SQL Console**) or by using the graphical interface to create and modify tables.

For example, if you expand **Schemas**, then **public**, and right-click on **Tables**, you can create new tables or view existing ones.

## Retrieving connection details using the API

Use the [database/connectiondetails](https://github.com/GleSYS/API-docs/wiki/API-Documentation#databaseconnectiondetails) endpoint to retrieve the connection string. To list available databases and users in an instance, use the [database/details](https://github.com/GleSYS/API-docs/wiki/API-Documentation#databasedetails) endpoint.
