DBeaver export to csv: "No database selected"

select * from users u
where u.id < 1000

When I right-click to script, and export I get no database selected error.

When I add "use db" command at above,I get a syntax error.

use db
select * from users u
where u.id < 1000

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * FROM..'

How do I export in DBeaver? I use a MacOS, and db is using MariaDB if that matters.


Solution 1:

Based on your comment I understand now this is a usage question about DBeaver. You simply need to make sure to select your database in the menu bar above the script tab as outlined here: https://dbeaver.com/docs/wiki/SQL-Editor/. See below screenshots for example:

enter image description here

enter image description here

Solution 2:

Either you have to separate multiple statements by a semicolon (1) or you can pass the database name directly to your statement (2):

(1):

use db;
select columns from users u ...

(2):

select columns from db.users u ....