Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
1) aborting install should return non zero exit code (so calling script can know it must stop)
2) when put in a shell script, drush seams to not be able to take term prompt
3) when providing a user and password not able to DROP/CREATE database, mysql yields :
ERROR 1044 (42000) at line 1: Access denied for user '****'@'localhost' to database '*****'
but drush proudly says install [ok] and stops ....
4) drush should provide a way to install drupal with a mysql user NOT allowed to DROP/CREATE database. ie with the user from the settings.php !!!!!
cheers
Comment | File | Size | Author |
---|---|---|---|
#18 | dbexists.diff | 4.13 KB | moshe weitzman |
#2 | drush-script-options.patch | 1.2 KB | xatoo |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commented1) We handle user initiated abort in this script consistent with the rest of drush. Scripts usually don't have user interaction. See drush_user_abort()
3,4) drush tries to drop/create and if not possible, it tries to drop all tables instead. Typically the configured mysql user at least has that perm. If you are not seeing your tables get dropped, make sure the drupal mysql user has enough perms. Then reopen this issue.
Comment #2
xatoo CreditAttribution: xatoo commentedI use site-install in a script as well.
Since the drupal database user has limited permissions I rather handle database creation by my own. Besides that I'd like my script to skip any confirmation.
In order to accomplish these things I applied the attached patch and then run drush site-install with the --no-db-create --yes options.
I also agree with point 1.
Comment #3
msonnabaum CreditAttribution: msonnabaum commentedThe "yes" option is unnecessary. You can already pass -y to it.
The current workflow of how the database is handled works, but I do think its a little silly to always try to drop it first. I too always use a more limited db user and seeing that error is annoying.
It seems like we could accomplish the same by checking if the db exists and then if so, drop all tables, if not, create it. I'm not convinced that the "no-db-create" option is useful.
Comment #4
quazardous CreditAttribution: quazardous commentedhi,
2) was a side effect of using piped commande... I ve found a workaround
3) is just a warning
4) ok it works ... was wrong
Comment #5
moshe weitzman CreditAttribution: moshe weitzman commentedreframing the issue per #3
Comment #6
quazardous CreditAttribution: quazardous commentedand user abort should be able to return a non zero exit code : maybe with an option --error-on-abort
Comment #7
donquixote CreditAttribution: donquixote commentedI agree that we should assume that this is all run with a limited-access user.
For me it says
ERROR 1044 (42000) at line 1: Access denied for user 'xxx'@'localhost' to database 'xxx'
which is only because of the DROP DATABASE.
Showing an error is just too strong a statement.
Comment #8
laurentchardin CreditAttribution: laurentchardin commentedThere's one use-case when you don't want to drop the database : execute multiple site-install at once, using --db-prefix so you can store all tables in the same database (yes, i had this once).
Since site-install drops the DB, you cannot script a multiple drupal instances installation procedure.
Comment #9
Agileware CreditAttribution: Agileware commentedSubscribe
Patch #2 worksforme2
Comment #10
hass CreditAttribution: hass commentedDroping DB is no good idea as user may not have permission to recreate and multisites (not yet tested myself) seems a real problem here.
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedwas looking into this, because i'm getting warnings even with a user that can create/drop the site db.
but, my user doesn't have the rights to do this in drush_sql_build_createdb_sql():
so, that needs to die. not sure if that handles the case where a user for the site doesn't have drop/create privileges, but that line has to go.
Comment #12
moshe weitzman CreditAttribution: moshe weitzman commented#3 makes sense, but there is no platform independent way to check if a given DB exists. So we need implementations for mysql, postgres, sqlite, and sqlsrv.
Comment #13
greg.1.anderson CreditAttribution: greg.1.anderson commented#11: The grant command should only happen if the db is created.
#12: We could use the drush sql-query wrapper to try to contact the db; that way, the db-specific implementations are already provided.
I should fix all of this sql stuff at the sprint.
Comment #14
Anonymous (not verified) CreditAttribution: Anonymous commentedre #13 - IMHO, the grant stuff should only happen if its explicitly asked for.
Comment #15
donquixote CreditAttribution: donquixote commented#14
makes sense. add an option to create the db (if not exists), and otherwise assume that a db already exists.
Maybe even add another option to delete tables (if applies), and otherwise stop if the db is found to be not empty?
Comment #16
greg.1.anderson CreditAttribution: greg.1.anderson commentedMaybe "ALL PRIVILEGES" is too much for some users, but if you have no grant statement, then the db will not work until some privs are granted by hand. I therefore think that at least some privs should be granted; otherwise the create option is not too useful. If we do not have a mechanism to specify the exact permissions desired, "all" is okay for a dev machine. If you don't want "all", you can create the db and set the privs by hand, and then skip the --create-db option. A patch to select the desired permission level would be welcome, though.
Comment #17
moshe weitzman CreditAttribution: moshe weitzman commentedI will try to get to this
Comment #18
moshe weitzman CreditAttribution: moshe weitzman commentedThe good news is that I got pretty far on this. See patch.
The bad news is that my approach needs tweaking. On mysql at least, a limited privilege user can't query INFORMATION_SCHEMA as that requires 'Show Databases' perm. When regular user does that, mysql return NULL and success exit code. This response is indistinguishable from a permissioned user requesting a non-existent DB. Ugh.
Comment #19
greg.1.anderson CreditAttribution: greg.1.anderson commentedWith a bit of refactoring, you could use
_drush_sql_query
to run a "show tables;" query. If you got back zero rows, then do nothing (empty db is good to go); one or more rows, call sql_drop. If there is no database, then the sql connect should return an error, and you can then call sql_create.Didn't have time to try that, but I would think that would work.
Comment #20
moshe weitzman CreditAttribution: moshe weitzman commentedSomeone else will have to push this along.
Comment #21
greg.1.anderson CreditAttribution: greg.1.anderson commentedI'll add it to my queue, but it may be a while. Anyone else who wants to jump in with a patch should feel free.
Comment #22
moshe weitzman CreditAttribution: moshe weitzman commentedI managed to fix drush_sql_db_exists() for mysql so committed to master.
I am seeing all tests pass except for one unrelated fail in completeTest (@dev/@stage confusion).
I'd like to backport this in 4.6 (we are at 4.5RC right now).
Comment #23
clemens.tolboomThe fix introduces #1332778: drush @drupal.d7 site-install is broken when using alias
Comment #24
moshe weitzman CreditAttribution: moshe weitzman commentedI guess backport isn't really necessary. Lets call this fixed and work on the #23 bug elsewhere.