Skip to content

sql:connect

Print a string for connecting to the database.

For PostgreSQL the password is not part of the string; psql reads it from PGPASSFILE or ~/.pgpass. With --format the connection info is printed as structured data instead, as sql:conf does.

Examples

  • sql:connect $(dr sql:connect) < example.sql
  • sql:connect eval (dr sql:connect) < example.sql
  • sql:connect --extra=--skip-column-names
  • sql:connect --db-url=mysql://root:pass@127.0.0.1/drupal
  • sql:connect --format=json
  • sql:connect $(dr sql:connect) -e "SELECT * FROM users LIMIT 5;"
  • sql:connect dr php:eval --format=json "return \Drupal::service('database')->query('SELECT * FROM users LIMIT 5')->fetchAll()"

Options

  • --extra=EXTRA. Add custom options to the connect string (e.g. --extra=--skip-column-names)
  • --database=DATABASE. The DB connection key if using multiple connections in settings.php. [default: default]
  • --target=TARGET. The name of a target within the specified database connection. [default: default]
  • --db-url=DB-URL. A database URL such as mysql://root:pass@localhost:3306/dbname, used instead of the site's settings.
  • --format=FORMAT. Print the connection info as json or yaml instead of a connect string. [possible values: yaml, json]

Global Options

  • -h, --help. Display help for the given command. When no command is given display help for the list command
  • --silent. Do not output any message
  • -q, --quiet. Only errors are displayed. All other output is suppressed
  • -v|vv|vvv, --verbose. Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
  • -V, --version. Display this application version
  • --ansi. Force (or disable --no-ansi) ANSI output
  • --no-ansi. Negate the --ansi option.
  • -n, --no-interaction. Do not ask any interactive question
  • --url=URL. A base URL (e.g. example.com). Used for building links, selecting a multi-site, etc.
  • -e, --env=ENV. The Environment name. [default: prod]
  • --no-debug. Switches off debug mode.

Aliases

  • sql-connect

Legend

  • An argument or option with square brackets is optional.
  • Any default value is listed at end of arg/option description.
  • An ellipsis indicates that an argument accepts multiple values separated by a space.