--- title: "Connect to a DBaaS instance" description: "Find your DBaaS instance's Endpoint and port, and connect with a client, an application, or SSL." content_type: "how-to" product: "database" platform: "MyAccount" url: "/myaccount/database/how-to/connect-to-a-database/" topic: ["create-and-connect"] relationships: {"requires":["/myaccount/database/how-to/create-a-database/"]} --- # Connect to a DBaaS instance Connect to a DBaaS instance from a command-line client or from your application, using the connection details on its details page. ## Before you begin Have the DBaaS instance **Running**, and its current password to hand. ## Find the connection details On the DBaaS instance's details page, under **Connection Details**, note its **Endpoint**, **Username**, **Port**, and **Database Name**. If you have lost the password, see [Reset the DBaaS instance password](/myaccount/database/how-to/reset-the-database-password/). Choose the address to connect to: - Use **Endpoint** to connect from the internet, from any IP address the whitelist allows. It works while the **Public IP** row shows **Attached**. If the row shows **Detached**, click **Attach** and confirm with **Attach**. - Use **Private IPv4** to connect from something inside a VPC attached to the DBaaS instance. ## Connect to MySQL or MariaDB ```bash mysql -h -P 3306 -u -p ``` `` is the **Endpoint** or **Private IPv4** you chose, and `` is the **Username** under **Connection Details**. Enter the password when asked. The client needs to use SSL; if it connects without SSL and is refused, use the SSL command in [Connect with SSL on](#connect-with-ssl-on). ## Connect to PostgreSQL ```bash psql -h -p 5432 -U -d ``` `` is the **Endpoint** or **Private IPv4** you chose, and `` and `` are the **Username** and **Database Name** under **Connection Details**. Enter the password when asked. The client needs to use SSL; if it connects without SSL and is refused, use the SSL command in [Connect with SSL on](#connect-with-ssl-on). ## Connect from an application Most drivers and object-relational mappers accept a connection URL instead of separate fields: ```text mysql://:@:3306/ postgresql://:@:5432/ ``` Replace ``, ``, ``, and `` with the values from **Connection Details**. In a connection URL, URL-encode any special characters in the password: for example, write `@` as `%40`. ## Connect with SSL on SSL is on for every new DBaaS instance. A DBaaS instance with SSL on requires SSL on every connection, on MySQL, MariaDB, and PostgreSQL. If SSL is off on an older DBaaS instance, turn it on first; see [Enable SSL on a DBaaS instance](/myaccount/database/how-to/enable-ssl-on-a-database/). Once SSL is on, in the **CA Certificate** row under **Connection Details**, click **Download** to get the CA certificate, `ca-cert.pem`. Then point your client at it. For MySQL and MariaDB, use the MySQL 8.0 client: ```bash mysql -h -P 3306 -u -p --ssl-mode=VERIFY_CA --ssl-ca=ca-cert.pem ``` PostgreSQL: ```bash psql "host= port=5432 user= dbname= sslmode=verify-ca sslrootcert=ca-cert.pem" ``` ``, ``, and `` are the values from **Connection Details**. Both commands check the server against the CA certificate you downloaded. Keep that CA check, and leave the host-name check out; if a client reports a certificate error, see [Troubleshooting DBaaS](/myaccount/database/troubleshooting/database/#a-certificate-check-fails-with-does-not-match-host-name-or-certificate-verify-failed). A successful connection shows the client's prompt, and you are working in your database. If a connection times out or is refused, see [Troubleshooting DBaaS](/myaccount/database/troubleshooting/database/#a-connection-times-out-or-is-refused).