How to load a problem's database into DBeaver


This guide explains how to load into DBeaver the database of an SQL problem (the one you get with the Download the database button) so you can try your queries on your own computer before sending them to the judge.

The screenshots are from DBeaver Community 26.2 in English; with another version or operating system, the menus may look a little different.

What you need

  • DBeaver Community, which is free. It is only the client: the tool where you write and run your queries.
  • A database server on your computer, of the same kind as the problem's: MariaDB or MySQL (for example, the one that comes with XAMPP, where the user is root and the password is empty) or PostgreSQL. The kind is written in the sentence next to the download button.
  • The database's .sql file (step 1). MongoDB databases can't be loaded with DBeaver Community.

1. Download the file

Open the problem, press View the database schema and, on the page that opens, press Download the database (you must be logged in). You will get a .sql file named after the database, for example hotel.sql.

Button to download the database

2. Connect DBeaver to your server

  1. In DBeaver, open the Database → New Database Connection menu (or press Ctrl+Shift+N).
  2. Choose MariaDB, MySQL or PostgreSQL, as the problem's page says, and press Next.

    Choosing the database type

    With PostgreSQL, DBeaver asks which driver you want: leave PostgreSQL (standard driver) selected and press Next.

    Choosing the PostgreSQL driver

  3. The host (localhost) and the port (3306 for MariaDB and MySQL, 5432 for PostgreSQL) are already filled in. Enter your user name and password.

    Connection settings

  4. Press Test Connection. The first time, DBeaver will offer to download the driver: press Download.

    Downloading the driver

    When it says Connected, press OK and then Finish.

    Connection works

3. Create an empty database

  1. Select the connection in the Connections panel on the left and open an SQL editor with SQL Editor → New SQL script (Ctrl+]).
  2. Type CREATE DATABASE hotel; (with any name you like) and run it with Ctrl+Enter. It should say Updated Rows 1.

    Creating the database

  3. Click the connection and press F5 (Refresh) so the new database shows up.

  4. PostgreSQL only: for DBeaver to show all the databases and not just the one you opened, edit the connection (F4) and, on the Main tab, tick Show all databases. With MariaDB it is ticked by default.

    Show all databases in PostgreSQL

4. Load the file

  1. Menu File → Open File... (Ctrl+O) and pick the .sql you downloaded. It opens in an SQL editor, with <none> in the tab's title because it isn't tied to any connection yet.

    File, Open File

    Picking the file

  2. In the editor's toolbar, press < N/A > (Active datasource, Ctrl+9), choose your connection and press Select.

    Choosing the connection

    Right next to it a second selector will appear (Database/Schema, Ctrl+0): choose in it the database you created in the previous step. With PostgreSQL a window with two lists opens: pick the database on the left and public on the right. Without this, DBeaver doesn't know where to load it. When you're done, the toolbar must show the connection's name and the database's:

    Connection and database chosen

    If the new database isn't in the list, close it, press F5 on the connection (on the left) and try again.

  3. Run the whole file with Alt+X (SQL Editor → Execute SQL script). Careful: Ctrl+Enter only runs one statement.

  4. DBeaver will ask you one or two questions. MariaDB and MySQL files start by deleting the tables that already exist (DROP TABLE IF EXISTS), which is why this one appears. Press Yes To All:

    DROP warning

    And, since the file is long, it will also ask whether you want to stop it from showing the result of every statement. Answer Yes, it will go much faster:

    Large script

  5. Wait for it to finish (a few seconds). A Statistics tab will show the number of statements run:

    Script finished

    Press F5 on the connection and expand Databases → your database → Tables to see the tables.

    The loaded tables

5. Try your queries

Select the database in the panel on the left, open an SQL editor (Ctrl+]) and write your queries. For example, on the hotel database: SELECT * FROM Rooms LIMIT 10;. Run it with Ctrl+Enter and the result appears below. When they look right, copy them into the problem's submission.

A query

If something fails

  • Nothing was loaded, or it says no database is selected: you didn't choose the database in the editor's toolbar (step 4.2).
  • The new database isn't in the list: press F5 on the connection, on the left, and try again.
  • PostgreSQL only shows the postgres database: tick Show all databases in the connection (step 3.4).
  • MySQL 8: Public Key Retrieval is not allowed: in the connection, Driver properties tab, set allowPublicKeyRetrieval to true.
  • PostgreSQL: unrecognized configuration parameter: your server is older than PostgreSQL 12; install a newer version.
  • Without DBeaver: you can also load the file from a terminal, once the empty database is created. For MariaDB/MySQL: mysql -u root -p hotel < hotel.sql. For PostgreSQL: psql -U postgres -d hotel -f hotel.sql.
  • The databases are generated with MariaDB 10.5 and PostgreSQL 17, the same ones the judge uses. They haven't been tested with MySQL 8: if you get errors, use MariaDB.