Using Sql and devel-generate commands for Drush

Ready for review -- AWAITING PEER REVIEW
Description: 
You would learn to use Sql and devel-generate module's commands
Overview: 

If you have used devel-generate then you would be knowing that it can be used to generate random content to your development website. We would be doing that using Drush. Also along that we would be looking at how to use some sql commands from Drush Command line interface.

Steps: 

1) So let us first install the devel and devel-generate modules. Open command prompt and go to your site directory. Here use drush dl commands to download the devel module. Now enable the devel and devel-generate modules from Drush using the 'drush en' commands. See the below image as reference.

Download and enable drush

2) Now we can generate content. We will be using the 'drush generate-content' which has an alias name as 'drush genc'.

Read more about generate-content here.

Use: drush genc 15 5

The above command would generate 15 nodes with maximum number of 5 comments.

3) If you have read the above link, you would know that genc command has few options too. Let us use them:

drush genc 15 5 --kill

The above command would delete all the existing content before generating new one.

You can also mention the content type with genc command as follows:

drush genc 15 --types=[ENTER CONTENT TYPE]

The above code would generate 15 nodes of the specified content type.

You can also generate menus, terms, users and vocabs using the similar techniques as discussed above. Visit this link to read more about Devel Generate commands.

4) Now we would have a look at Drush Sql commands.

drush sql-cli

The above code would open a SQL command-line interface. Now you can run SQL queries right in that window. NICE!
Let us try that, type in

SELECT * FROM users WHERE uid=1;

The above command would display that tuple from the users table which has uid equal to 1. Use the below image as reference

You may now try your own SQL queries there.

NOTE: Use 'exit' in SQL prompt to return back to command prompt.

5) Let us now try to import database. Drush makes it very easy for us to do that.

We'll first have to dump the current database to a sql file which would be imported on another site:

drush sql-dump --result-file=..backd7dev/mybackupfile.sql

Now it is time to go to another site and drop its database so that new one can be imported.

drush sql-drop

Let us see if the database has been deleted or not. We can use sql-query command to make a query.

drush sql-query "SELECT * FROM users WHERE uid=1"

Okay so the database has been deleted. Now let us import the database. Use:

drush sqlc < path/to/filename_here.sql

We can test it using a SQL query. Try:

drush sql-query "SELECT * FROM users WHERE uid=1"

VOILA! The database has been imported. See the below image if you are stuck. (In the below example the database of the current site is being deleted and then imported.)

Importing Database