Critical Skill 1.6 Learn How to Use the Command Line


You may have heard arguments about working on the command line versus using a graphical user interface (GUI) client. These arguments tend to be all for using one or the other. The truth is that both have their strong and weak points.

The main argument you hear for GUIs is that they are faster and easier to use. That assertion is both true and false. GUIs do tend to have a shorter learning curve, since they follow the user-friendly principles we all have come to know and understand. So, in that sense, they are faster to use, especially at the beginning of your learning process. On the other hand, GUIs are programs that take a certain amount of time to start up and get ready to function. If you need to send only one command to MySQL, no matter how bad of a typist you are, it is often quicker and easier to do it from the command line than to open your GUI to execute it.

Our consideration here is which interface works as the better tool for learning how to use MySQL. It s nearly always true that if you need to type a command to get something done, you will have less difficulty remembering it later. This is usually not the case when you are using a point-and-click interface. The GUI seems simple and clear at the moment you are using it, but you ll often experience a complete memory blank when faced with the same task later. You can only make (and find later) so many notes with hurriedly scribbled syntax on them.

As you learn the basics of MySQL, this guide will focus solely on using the command line to communicate with MySQL through the MySQL Client. This is not because we re sadists, but because in the end, it will help you learn MySQL quicker and more effectively. Also, the same commands and responses are seen, whether you re operating in a Linux- or Windows-generated environment. It should make the overall concepts easier to grasp and remember, while reinforcing the underlying syntax and language patterns that make up MySQL administration, definition, and reporting tasks .

Once you can define a new database and its tables, edit their contents, and distill basic and more complex knowledge out of their contents using queries, then (in Module 6) you will return to the GUI. Then you will be armed with the foundation of knowledge that will allow you to use the GUI even more effectively. There will probably be moments when working on the projects ahead that you will be tempted to avoid the more time-consuming command-line typing, but repetition and practice are what turn bare-bones knowledge into instinctive skills, and none of the projects will require horrendous amounts of typing.

By the time you have reintroduced GUIs into your repertoire , you will not have to decide whether the GUI or the command-line method for using the MySQL Client will be faster or easier to accomplish a given task. At that point, it will be instinctive, because you will have developed the underlying experience ”the muscles so to speak ”that enable you to use the GUI to its fullest potential, instead of merely as an intellectual crutch. So, for all you GUI devotees, be patient; there is method in this command-line madness. For those of you used to a command-line approach, it s still the best way for you to acquire the basics you want, but for some things, the GUI will win out in the end, even with you.

Now let s take a look at running commands from the command line, so you ll be prepared for your command-line work in the following modules. Read either the section about using the command prompt in Windows or using it in Linux, depending on the OS on which you ve installed MySQL.

Using the Command Prompt in Windows

To use the MySQL command line, you must first open a DOS window. An easy way to do this is by selecting Start Run from the desktop, entering cmd , and clicking the OK button. You can also use the Command Prompt command from the Start Programs menu. You may find it convenient to right-click the Command Prompt icon on the menu and make a shortcut, which you can then drag to your desktop for easy access.

When the Command Prompt window opens, type cd \mysql\bin and press ENTER . You are now in the directory with the MySQL executables. Type mysql and press ENTER to get to the command line mysql prompt.

Now that you are at the MySQL command line prompt, let s look at a few commands that are essential. Type help and press ENTER . As shown in Figure 1-4, a list of all the MySQL commands appears, along with a backslash (\) shortcut for each. A backslash shortcut is an abbreviated way of typing a command using a backslash and a single letter. While it is not necessary to memorize them, learning the ones that correspond to the commands you use most often will save time by eliminating typing.


Figure 1-4: The help listing of MYSQL commands and shortcuts in Windows

Notice that the help listing also includes a syntax reminder, which says that the command words must come first in the line and must end with a semicolon. In practice, only queries require the ending semicolon. You can enter other commands ( help , for instance) without a semicolon, and they will still function properly. However, getting into the habit of using the semicolon, whether or not is required, will help you avoid problems.

If you enter a command that requires a semicolon, such as show tables , without the semicolon and press the ENTER key, instead of executing the command, the MySQL Client displays an arrow-shaped prompt instead of the mysql prompt. The system will wait for the closing semicolon indefinitely.

Once the concluding semicolon is entered, the command executes.

To return to the standard C:\ prompt, type either EXIT or QUIT . The MySQL Client will display bye , and then you ll exit the client.

Using the Command Prompt in Linux

At the end of Project 1-3, you entered a password and then ended up at the mysql prompt. To see some of the essential commands, type help and press ENTER . As shown in Figure 1-5, a list of all the MySQL commands appears, along with a backslash (\) shortcut for each.


Figure 1-5: The help listing of MySQL commands and shortcuts in Linux

The help screen also shows a syntax reminder, stating that the command words must come first in the line and must end with a semicolon. In practice, only queries require the ending semicolon. You can enter other commands ( help , for instance) without a semicolon, and they will still function properly. However, it s a good idea to get into the habit of using the semicolon.

If you enter a command that requires a semicolon, such as show tables , without a semicolon, when you press ENTER , the command won t execute. Instead, you ll see an arrow-shaped prompt instead of the mysql prompt.

The system will wait for the closing semicolon indefinitely. Once the concluding semicolon is entered, the command executes.

You can return to the standard prompt by typing either EXIT or quit . The MySQL Client will display bye and exit.




MySQL(c) Essential Skills
MySQL: Essential Skills
ISBN: 0072255137
EAN: 2147483647
Year: 2006
Pages: 109

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net