create new db using drush

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
marcus_gbs's picture

I'm using Drupal 6.x.

While I have my own shell script that will create a new database to use with a new drupal install, I would like to do this with drush.

Drush has some sql commands, but they seem to be for post creation.

I've looked inside the drush 3 beta and found the drush_core_pre_site_install() function, but I don't see where it is exposed. I tried to guess at a command name (pre-site-install), but those attempts failed. Another function in that same file, drush_core_site_install gave me an error message that it requires Drupal 7.

Does drush provide the capability to create a database for a new site installation? If so, how is this done?

Comments

Drush doesn't have any

christefano's picture

Drush doesn't have any commands that will do this. Take a look at drubuntu.drush.inc in the Drubuntu project. There's a drush_drubuntu_db_query() function that you can copy to your own Drush command.

drush site install

emi_bcn's picture

Hi all,
You have the possibility to do execute drush site-install or drush si from a Drupal directory with a created database and valid settings.php configured. It has the ability to install from profiles, so you can pre-install all the modules and themes you know you'll use, along with other configurations you may have declared in that profile (as multisite configs, language/s, etc.). I have never used this, but I think this is what you are looking for.

My drush version is 3.0.

See you,
emi

I didn't think so, but

marcus_gbs's picture

I didn't think so, but thought I'd ask. This brings me to further questions.

Currently, I can create my new DB and DB admin user via (unix) shell script. I would like to create a drush command for it.

First, I would need to move it from shell script into PHP. There any number of issues to handle, but the one I have the biggest problem with is password security. With the shell script, I can prompt for and read passwords using:

echo -n "Enter the Password for the DB privileged user $mysql_db_priv_user (it won't display): "
stty -echo
read mysql_db_priv_pw
stty echo

The thing I like about this is that they do not display.

I've done a bit of searching on PHP, but it does not appear that PHP has the direct capability to enter a password with no echoing or echoing only stars. I found some pseudo-solutions but they were pretty ugly.

I can see that the drush shell script does not do any processing of the command line and just passes it off to the php. I can also see where drush does the 'y/n' prompt management. I could not find where drush currently handles any cases of prompting for information where the user response is not echoed to the screen. I know this is further complicated by the fact that drush needs to support windows in addition to *nix/mac (in other words, I am guessing that doing it using php 'system' calls would be highly frowned upon).

--re-read above post--
I see that drubuntu uses its own shell script that wraps around drush. drush_drubuntu_db_query pulls a password from the parameters, but I don't want it to be visible. My script also wraps around drush, but was hoping to integrate it into drush.

sql-sync command has

moshe weitzman's picture

sql-sync command has create-db option. you might want to borrow code from there.

see drush_prompt() in drush3. thats for accepting arbitrary text input interactively. not used by core drush at this time. its used by aegir at least.

I've done so and borrowed the

fago's picture

I've done so and borrowed the code from there. Anyone interested can find a working command file over at http://drupal.org/node/1627252

jonhattan's picture

drush site-install --db-su= --db-su-pw=. A patch to improve security by using .my.cnf or .pgpass is welcome.

drush

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: