Is is possible to automate clearing the database when I run site install? e.g. here is my drush command:

drush si geoslate --db-url='mysql://root:root@localhost/geo_test' --site-name=Geoslate

But the db has to be cleared first. Can I automate this process?


Chapabu is correct, but if you're using drush 5.7, this is unnecessary with site-install. If there's an existing db, drush will warn you it will drop all tables in the existing database.

For example:

drush dl drupal --drupal-project-rename=test
cd test
% drush site-install standard --db-url=mysql://root:root@ --site-name=test
You are about to create a sites/default/files directory and create a sites/default/settings.php file and DROP all tables in your 'test' database. Do you want to continue? (y/n): y
No tables to drop.                                                                          [ok]
Starting Drupal installation. This takes a few seconds ...                                  [ok]
Installation complete.  User name: admin  User password: 6SkT989sPX

So let's rerun the site-install command over the now existing "test" directory

% drush site-install standard --db-url=mysql://root:root@ --site-name=test         130 ↵
You are about to DROP all tables in your 'test' database. Do you want to continue? (y/n):
  • 1
    Neat - I didn't realise it did this (It's been a while since I've used site-install) :-)
    – Chapabu
    Apr 19 '13 at 13:24
  • this is true but I am getting the error anyway, sh: mysql: command not found which is a separate problem due to the location of mysql Apr 22 '13 at 15:26
  • That should be something we can address. Can you describe how your hosting your drupal installation? Is it on a shared Hosting like HotDrupal.com, a local development stack, or…?
    – Screenack
    Apr 22 '13 at 19:24

If by cleared, you mean drop all tables, then you can use drush sql-drop

Drop all tables in a given database.

Official documentation for sql-drop

  • Thanks, I'm getting an error: sh: mysql: command not found . Any idea what might be causing this... Apr 19 '13 at 11:22
  • Try look over here :)
    – Chapabu
    Apr 19 '13 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.