function drush_sql_su

6.x drush_sql_su($db_spec, $site_alias_record = NULL)
4.x drush_sql_su($db_spec)
5.x drush_sql_su($db_spec, $site_alias_record = NULL)

Build DB connection array with superuser credentials if provided.

The options 'db-su' and 'db-su-pw' will be retreived from the specified site alias record, if it exists and contains those items. If it does not, they will be fetched via drush_get_option.

Note that in the context of sql-sync, the site alias record will be taken from the target alias (e.g. `drush sql-sync @source @target`), which will be overlayed with any options that begin with 'target-'; therefore, the commandline options 'target-db-su' and 'target-db-su-pw' may also affect the operation of this function.

2 calls to drush_sql_su()
drush_sql_sync in commands/sql/
_drush_sql_create in commands/sql/
Generate CREATE DATABASE sql plus additonal preparations.


commands/sql/, line 1449
Drush sql commands


function drush_sql_su($db_spec, $site_alias_record = NULL) {
  $create_db_target = $db_spec;
  $create_db_target['database'] = '';
  $db_superuser = drush_sitealias_get_option($site_alias_record, 'db-su');
  if (isset($db_superuser)) {
    $create_db_target['username'] = $db_superuser;
  $db_su_pw = drush_sitealias_get_option($site_alias_record, 'db-su-pw');
  // If --db-su-pw is not provided and --db-su is, default to empty password.
  // This way db cli command will take password from .my.cnf or .pgpass.
  if (!empty($db_su_pw)) {
    $create_db_target['password'] = $db_su_pw;
  elseif (isset($db_superuser)) {
  return $create_db_target;