drush sql-queryfor drush 7x

Execute a query against a database.

drush sql-query

  • Aliases

    sql-query has 1 alias/es:

    drush sqlq

  • Arguments

    sql-query accepts 1 argument/s:

    query : An SQL query. Ignored if 'file' is provided.

  • Options

    sql-query accepts 8 option/s:


    --result-file : result-file

    --file : Path to a file containing the SQL to be run. Gzip files are accepted.


    --extra : extra

    --db-prefix : Enable replacement of braces in your query.


    --db-spec : db-spec


    --database : database


    --target : target


    --db-url : db-url

  • Examples

    Browse user record. Table prefixes, if used, must be added to table names by hand.

    drush sql-query "SELECT * FROM users WHERE uid=1"

    Browse user record. Table prefixes are honored. Caution: curly-braces will be stripped from all portions of the query.

    drush sql-query --db-prefix "SELECT * FROM {users} WHERE uid=1"

    Import sql statements from a file into the current database.

    `drush sql-connect` < example.sql

    Alternate way to import sql statements from a file.

    drush sql-query --file=example.sql

  • Comments

    comments powered by Disqus