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

(singke) #1

Using MySQL—the Command Line


Now that that you have MySQL up and running, it is time to take your database engine for a spin. The
command line interface of MySQL can be daunting the first time, especially if you're used to the GUIs that
the other databases in the same class of MySQL offer.
To start the command line interface in Linux or in Windows, make sure you are in the /mysql directory.
In Windows, you must use a DOS prompt. At the command line, type the following:
bin/mysql –p


You should see the following:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version : 3.22.
Type help for help.
After the output is displayed, you are left with an empty prompt (see Figure 2.4). This is where it can get
a little scary for the first time MySQL user. For the most part, all commands to manipulate your data are
entered here. A good command of the Structured Query Language (SQL) is a must to get around. This
can be a bane or a blessing, depending on how you look at it.

Figure 2.4 The MySQL monitor.


With the command line prompt, you don't need a GUI. You may argue that it is nice to have a GUI; it
makes things easier. You can, with a few clicks of the mouse, see all your tables and how they relate to
each other. With a GUI, you can see permissions and active connections. You can do a lot with a GUI,
but what you can't do is remotely administer your database quickly and efficiently. Most Windows
administrators use PC AnyWhere or some other similar product to administer the servers under their
control. Though these programs are nice, they leave a lot to be desired, especially over slow dial-up
connections. With the command prompt, these inefficiencies are no longer a problem. With a simple
Telnet session, you can remotely administer you database quickly and efficiently. With a command
prompt, you can create, drop, and populate a database as if you were there. It only takes a few late
night calls to fix a problem to fully realize and understand the power that is afforded with this simple
feature.
Assuming that you logged in as root, take a look at the existing databases in the default installation.
To see what databases exist on this server, type the following:
show databases;
You should see output similar to that shown in Figure 2.5.
Free download pdf