Documentation

Connect to the Database

With every project, connecting to the database is often useful to get an idea of what's going on. You may want to quickly check out a bit of data, do a bit of debugging, or get to the bottom of some slow queries.

Note: If you're looking to import data, we'd recommend taking a look at the Import Database documentation.

Using a database client #

You can connect to Servd using any MySQL/MariaDB compatible database client, such as TablePlus or SequelAce. Here's a few steps to get you connected:

  1. Go to your project's Access Control page.

  2. At the bottom of the "Database Access" section, check that the "Allow external database connections" option is checked.

  3. If it's not checked, enable it and then hit "Save". You should see an "Updating external database access" task appear in the taskbar. Once it has complete, you can now connect via your database client of choice.

  4. Using the details from the Access Control page, input the host, port, username and password into your database client.

    Note: the staging host name is used for connecting to both the staging and production databases.

    Here's an example of what it might look like inputted into TablePlus:

    Connecting to the database using TablePlus
  5. Your client should now be able to connect directly to your database.

    After you have finished, you may want to disable the "Allow external database connections" option again to improve the security of your project.

Using the mysql CLI #

If you prefer using the CLI, or don't have access to database client, you can connect directly to your database using the mysql CLI tooling.

  1. Go to your project's Access Control page.

  2. At the bottom of the "Database Access" section, check that the "Allow external database connections" option is checked.

  3. If it's not checked, enable it and then hit "Save". You should see an "Updating external database access" task appear in the taskbar. Once it has complete, you can now connect via your database client of choice.

  4. Using the details from your project's Access Control page, open up your shell and run the following command:

    mysql -h <host> --port <port> -u <username> -p<password>

    Note: don't include a space between the -p flag and your password, otherwise you'll be prompted to re-enter your password.

  5. Your shell should now be connected directly to the database.

    After you have finished, you may want to disable the "Allow external database connections" option again to improve the security of your project.