drush sql-queryfor drush 8x


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 : Save to a file. The file should be relative to Drupal root. Optional.

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

    --extra : Add custom options to the database connection command.

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

    --db-spec : A database specification

    --database : The DB connection key if using multiple connections in settings.php.

    --target : The name of a target within the specified database connection. Defaults to 'default'.

    --db-url : A Drupal 6 style database 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