-
Notifications
You must be signed in to change notification settings - Fork 0
drupal db query
Paulo Maia Carvalho edited this page May 20, 2026
·
1 revision
Run a SQL query against the Drupal database via Drush.
/drupal-db-query SELECT COUNT(*) FROM node_field_data
/drupal-db-query SELECT nid, title FROM node_field_data WHERE status = 1 LIMIT 10
Passes the query to drush sql:query and returns the result as a table in the chat.
Count published nodes:
SELECT COUNT(*) FROM node_field_data WHERE status = 1List users:
SELECT uid, name, mail FROM users_field_data WHERE uid > 0Check for broken aliases:
SELECT source, alias FROM path_alias WHERE status = 1 LIMIT 20Find large watchdog entries:
SELECT type, COUNT(*) as count FROM watchdog GROUP BY type ORDER BY count DESC- Read-only queries are safe to run freely. Destructive queries (
UPDATE,DELETE,DROP) are executed immediately without additional confirmation — be careful. - Table names use Drupal's default prefix (none by default). If your project uses a table prefix, include it in the query.
- Results are truncated at ~50 rows in the chat output. For larger result sets, export with
/drupal-db-exportand query the dump.
- drupal-db-export — full database dump
- drupal-db-import — restore from a dump
- drupal-logs — watchdog log viewer (no SQL needed)