[regression] drush 8.3.3 site-install: DROP USER drops all grants
Describe the bug
drush 8.3.3 introduced a change (#4261) that added a DROP USER command before recreating the DB user. Dropping the DB user implicitly removes all grants for the user. This is a problem if the same user is used for accessing DBs of multiple sites.
To Reproduce
# Install site A
drush site-install --db-url=mysql://user:pw@localhost/drupal_site_a --db-su=root --db-su-pw=super-secret minimal
# Site A works.
# Install site B
drush site-install --db-url=mysql://user:pw@localhost/drupal_site_b --db-su=root --db-su-pw=super-secret minimal
# Site A is broken because the user can’t access the first database anymore.
Expected behavior
Existing grants for the DB user should not be harmed by installing a new Drupal site.
Actual behavior
Existing grants are deleted when running drush si.
Workaround
Manage databases and grants outside of drush by not passing --db-su or downgrade to versions before 8.3.3
System Configuration
| Q | A |
|---|---|
| Drush version? | 8.3.3 |
| Drupal version? | 7.96 |
| PHP version | 7.4.33 |
| OS? | Debian 12 |
Additional information
I was able to git bisect the problem to b559117576bea1f958cb5e8151af5161b3f6d3ce .
Hm, yes, in hindsight, it does make a lot more sense to create the user if it does not exist rather than to drop it if it does exist. PRs welcome.
Was there a reason to not use CREATE USER IF NOT EXISTS back then? It seems both MySQL and MariaDB support it.
I think that would have been the right solution.