Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1
After your database has been successfully created, you can begin to use it. If you recall from Day 1,
"What Is MySQL?," the command to do this is USE. To use the sample_db, type the following from the
MySQL monitor prompt:
USE sample_db;
The results of your command should resemble Figure 4.2.

Figure 4.2 Using the new database.
An important point to remember is that MySQL does not automatically make the database you just
created the active database. You must implicitly state which database to activate with a USE statement.


The DROP Command


The DROP command is similar to the CREATE command. Where the latter creates a database, the former
deletes one. A word of caution, the SQL DROP command is very unforgiving. There are no confirmation
boxes asking if you are sure. The DROP command just deletes the database and all the data contained in it.
This shows some of the power of SQL commands. Once a command has been committed, there is no going
back. (This is not entirely true—you can get your data back from a log file.) Use extreme caution when using
the DROP command.
To use the DROP command, complete the following steps:



  1. Make sure that the mysqld daemon is running and that you are in the mysql
    directory.

  2. From the command prompt, type

  3. bin/mysql


This will start the MySQL monitor.


  1. From the monitor prompt, enter the following:

  2. DROP DATABASE sample_db;
    This will delete the sample_db database and ALL the data within it.
    The output from the previous steps should look similar to Figure 4.3.

Free download pdf