NOTE: You must be an admin user to use the Query Builder.
The SQL Query Builder launches with an empty tab, ready for a private query. Write your SQL commands in the editor below the tab. Then:
- Select a database from the dropdown
- Click the “Execute query” icon button
- Click the “Save query” icon to save your query
Create a new query #
To create a new query, click the “Menu” icon in the toolbar and choose:
- Private Query → visible only to your user account
- Global Query → accessible to all admin users
Open an existing query #
Click the “Menu” icon and select Open. You’ll see a dialog with your saved private and global queries. Simply select and load the one you need.
Multiple SQL commands #
The Query Builder supports not only SELECT queries but all SQL commands (DCL, DDL, DML) — provided your user privileges allow it. Note: If you’re on shared hosting, your permissions may be restricted.
Separate multiple SQL statements using a line with just a forward slash /. Example:
drop table if exists x
/
create table x
(x int)
/
insert into x values(1)
/
insert into x values(2)
/
update x
set x = x + 100
/
select *
from x
/
Multiple queries #
Each command opens in its own tab and shows the results or response for that statement.
User defined variables and dynamic queries #
You can use user-defined variables and build dynamic SQL queries in the Query Builder. Here is an example:
SET @column = "columnname"
/
SET @table = "tablename"
/
SET @select = CONCAT("SELECT ", @column, " FROM ", @table)
/
PREPARE stmt FROM @select
/
EXECUTE stmt
/
Query Parameters #
You can run or schedule a query with different parameter values using query parameters. Click the “Add Parameters” button. In the dialog, define a name and value for each parameter.
WordPress Table Protection #
To keep your site safe, WordPress tables are protected by default. It is generally not possible to DROP, ALTER, or TRUNCATE WordPress core tables.
Database response #
A scrollable table below the editor displays the result of your query. You can export this data to CSV, JSON and XML.
View raw output #
Click the SERVER RESPONSE tab to view the raw database output. The output is shown in JSON format and is read-only.
Save query #
Click the “Save query” icon button to save a query. Alternatively, use the control/s keys from within the editor.
Query context menu #
Each query tab comes with its own context menu, accessible via the three-dots icon button at the end of the tab toolbar. This menu provides quick access to essential actions to manage your query efficiently:
- Rename your query for easier identification
- Delete a query you no longer need
- Schedule execution at defined intervals
- Load from file to import saved SQL commands
- Save to file for local backups or version control
- Copy to clipboard to paste your SQL elsewhere
- Close the query tab when you’re done
These options help streamline your workflow and offer added flexibility for managing your SQL tasks directly from the WordPress dashboard.
Execution time #
To display SQL execution time (in parentheses after each result), add the following lines to your wp-config.php file:
define( 'WP_DEBUG_LOG', true );
define( 'SAVEQUERIES', true );