When I try to install a site using drush site-install, I end up with an error
ERROR 1044 (42000) at line 1: Access denied for user 'kenji'@'localhost' to database 'drupaltest'
but when I install the site through the standard http://mysite.com/install.php with the same db_url value set in settings.php, everything is working fine.
I have no idea where this could come from and i'd really appreciate help since drush is really a great tool i'd like to continue to use.
Thanks !

Just in case you wonder, 'kenji'@'localhost' has been grant the following on mysql SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES

Comments

trickpatty’s picture

I had the same problem. I looked forever, but forgot to check the most obvious thing... spelling errors.
(dupal != drupal)

Good luck!

jonhattan’s picture

That access denied is to drop-create the database. I think drush should continue and empty the database by dropping table by table.

msonnabaum’s picture

I get this too.

Is there any reason we need to drop? Seems like we could truncate all tables instead and avoid this error.

greg.1.anderson’s picture

This is related to #716412: add a --delete-all-tables-first option for sql-sync ? -- I thought there was a duplicate issue somewhere specifically related to drop table vs drop db, but could not find it. Anyway, drush is supposed to try to drop all tables first, then fall back to dropping and creating the database. The create database code path is important in cases where the database does not exist at all yet.

Supposedly on my plate to fix this, but I've been busy and not had much time in the drush queue lately. Wouldn't mind if someone else came up with a patch.

moshe weitzman’s picture

We do try to drop all tables if the DROP/CREATE fails. If both fail, we error with a message that could be clearer.

if (!_drush_sql_query($sql, $create_db_spec)) {
      // If we could not drop the database, try instead to drop all
      // of the tables in the database (presuming it exists...).
      // If we cannot do either operation, then fail with an error.
      if (!_drush_sql_drop($db_spec)) {
        return drush_set_error(dt('Could not drop and create database: @name', array('@name' => $db_name)));
      }
    }
greg.1.anderson’s picture

That's why I couldn't find the dup issue -- already committed. :)

coredumperror’s picture

I'm having this same problem, but the error message I get is slightly different, which I'm hoping will shed some light on this to the devs:

sudo drush site-install -y --db-url=mysql://drupal_prod:
@our-amazon-cloud-DB-server/drupal_prod1 --account-name=administrator --account-pass=
--account-mail="name@place.edu" --site-name="Our School"
You are about to create a sites/default/files directory and create a sites/default/settings.php file and DROP your 'drupal_prod1' database and then CREATE a new one. Do you want to continue? (y/n): y
ERROR 1044 (42000) at line 1: Access denied for user 'drupal_prod'@'%' to database 'drupal_prod1'
No tables to drop. [ok]

I don't actually get an error message from drush (just the one mysql is spitting out), but the site-install command seems to be failing anyway. When I subsequently try to access the site, nothing happens. The page loads, but there's nothing there.

I know that the db-url string is correct, because logging in directly using the mysql client (or phpMyAdmin) with the same credentials works, and I can drop and create the database just fine.

moshe weitzman’s picture

Status: Active » Closed (duplicate)
holtzermann17’s picture

Status: Closed (duplicate) » Active

Hi Moshe, I'm seeing the "no tables to drop" version of this issue; since I didn't find the duplicate issue, I'm reopening the ticket.

holtzermann17’s picture

Status: Active » Closed (won't fix)

I found that GRANT ALL ... gives enough permission to make the drush command run to completion. The home page looks OK, but clicking around leads to 404 not found errors. But this seems like a different issue from the one described here!

jcuzella’s picture

Status: Closed (won't fix) » Active

I am encountering this issue when running a drush site-upgrade without the --db-su and --db-su-pw flags. I also am seeing #1135588: 'drush cli' results in 'sh: /dev/pts/1: Permission denied' error as well.

This is using a fresh install of Drupal 6.22, and trying to upgrade to 7.8. I am re-opening this issue because it does not appear to be fixed correctly.

Running drush as non-root user with the following site.aliases:

<?php
$aliases['old'] = array (
  'root' => '/path/to/drupal/htdocs',
  'uri' => 'http://example.com/',
  'db-url' => 'mysqli://dbuser:dbpass@localhost/drupal',
);
$aliases['new'] = array (
  'root' => '/tmp/drush-backup_12345/drupal-new',
  'uri' => 'http://example.com',
  'db-url' => 'mysqli://dbuser:dbpass@localhost/drupal',
);

I run drush like so:

siteuser=someuser

su --login $siteuser --command="drush @old site-upgrade @new"
Project drupal (7.8) downloaded to /tmp/drush-backup_VrVJcZqa/drupal-new.                                                                                                                                                          [success]
Project drupal contains:                                                                                                                                                                                                           [success]
 - 3 profiles: minimal, testing, standard
 - 4 themes: seven, garland, stark, bartik
 - 47 modules: drupal_system_listing_compatible_test, drupal_system_listing_incompatible_test, system, update, aggregator, path, node, field_ui, menu, color, filter, comment, syslog, toolbar, simpletest, block, user, image,
tracker, help, openid, locale, poll, translation, profile, blog, taxonomy, dashboard, text, options, list, field_sql_storage, number, field, dblog, trigger, statistics, overlay, book, rdf, php, file, shortcut, forum,
contextual, search, contact


You will destroy data from drupal and replace with data from drupal.

You might want to make a backup first, using the sql-dump command.

Do you really want to continue? (y/n): y
ERROR 1044 (42000) at line 1: Access denied for user 'drupal'@'localhost' to database 'drupal'
About to perform updatedb for Drupal core on @new                                                                                                                                                                                  [ok]
sh: cannot create /dev/pts/0: Permission denied
The call to updatedb failed for Drupal core.  This may be caused by a contrib module that is not yet ready for upgrade.  Try running site-upgrade again with '--uninstall={module list}' to remove all contrib extensions prior to [error]
upgrade.  Add modules back in until the problematic one is isolated.  Please report problems in the issue queue of the module that is causing problems.
jcuzella’s picture

Just ran the site-upgrade using the above site aliases file, no --db-su or --db-su-pw flags, and the --debug flag, and got the following output:

( Scrubbed for db passwords ):

su --login drupal --command="drush --debug    @old site-upgrade @new"

[...SNIP...]

Local sql cache file does not exist. [2.72 sec, 10.85 MB]                                                                                                                                                                             [notice]

You will destroy data from drupal and replace with data from drupal.

You might want to make a backup first, using the sql-dump command.

Do you really want to continue? (y/n): y
Calling system(mysqldump --result-file /tmp/drupal.sql.AjhMug --single-transaction --opt -Q  drupal --host=localhost --user=drupal --password=__SCRUBBED_DBPASS__ --skip-extended-insert --order-by-primary );
Calling system(echo "DROP DATABASE IF EXISTS drupal;  CREATE DATABASE drupal /*!40100 DEFAULT CHARACTER SET utf8 */; GRANT ALL PRIVILEGES ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY '__SCRUBBED_DBPASS__'; FLUSH PRIVILEGES;" | mysql --database=information_schema --host=localhost --user=drupal --password=__SCRUBBED_DBPASS__; mysql --database=drupal --host=localhost --user=drupal --password=__SCRUBBED_DBPASS__ --silent < /tmp/drupal.sql.AjhMug);
ERROR 1044 (42000) at line 1: Access denied for user 'drupal'@'localhost' to database 'drupal'
About to perform updatedb for Drupal core on @new [3.23 sec, 10.82 MB]                                                                                                                                                             [ok]
Running: /usr/bin/php /home/drupal/drupal/local/share/drush/drush.php --php='/usr/bin/php'  --yes --root='/tmp/drush-backup_OKbTjSLN/drupal-new' --uri='http://172.27.0.126'                                       [command]
--db-url='mysqli://drupal:__SCRUBBED_DBPASS__@localhost/drupal' updatedb  > `tty` 2>&1 [3.23 sec, 10.83 MB]
executing /usr/bin/php /home/drupal/drupal/local/share/drush/drush.php --php='/usr/bin/php'  --yes --root='/tmp/drush-backup_OKbTjSLN/drupal-new' --uri='http://172.27.0.126'                                       [notice]
--db-url='mysqli://drupal:__SCRUBBED_DBPASS__@localhost/drupal' updatedb  > `tty` 2>&1 [3.23 sec, 10.83 MB]
Calling system(/usr/bin/php /home/drupal/drupal/local/share/drush/drush.php --php='/usr/bin/php'  --yes --root='/tmp/drush-backup_OKbTjSLN/drupal-new' --uri='http://172.27.0.126' --db-url='mysqli://drupal:__SCRUBBED_DBPASS__@localhost/drupal' updatedb  > `tty` 2>&1);
sh: cannot create /dev/pts/0: Permission denied

It still is running the DROP DATABASE sql command, which fails as non-root without the drop permission:

Calling system(echo "DROP DATABASE IF EXISTS drupal;  CREATE DATABASE drupal /*!40100 DEFAULT CHARACTER SET utf8 */; GRANT ALL PRIVILEGES ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY '__SCRUBBED_DBPASS__'; FLUSH PRIVILEGES;" | mysql --database=information_schema --host=localhost --user=drupal --password=__SCRUBBED_DBPASS__; mysql --database=drupal --host=localhost --user=drupal --password=__SCRUBBED_DBPASS__ --silent < /tmp/drupal.sql.AjhMug);
greg.1.anderson’s picture

Status: Active » Closed (duplicate)

Please do not open old unrelated issues with vaguely similar error messages to post new support requests. Please use drush-5.x to reproduce, and follow the instructions here: http://drupal.org/node/add/project-issue/drush

svrl’s picture

Issue summary: View changes

Hello Dru-Com,
I solved this problem using another DB user, root actually.
In order to cause this bug I used none existing user, after I used root who is existing by default i had not problem.

Have a nice day"

prasanna_drupal’s picture

But using root user for site creation is not a good idea, we need have a different data base user.

I am also facing the same issue.

with root user, site is being created.

Is there any other solution to create the site with the user other than root.

Please help

Details are:
I am installing drupal 8.7.10
and using drush 8.0.3 (Installed through composer)
OS : Linux Centios 7