MySQL in a Nutshell [23]
mysql --user='paola' --password='caporale1017' \
-e "SELECT vendor, telephone FROM vendors \
WHERE state='LA'" bookstore
We’re still using the mysql client, but we’re not entering the interface. As shown earlier, we provide the username paola and her password caporale1017 as arguments to the command. This line ends with a backslash to let the Unix shell know that there are more parameters to come. Otherwise, we would need to put all of the information shown on one line.
On the second line, we use the -e option to indicate that what follows it in double quotes is to be executed by the mysql client. Notice that what’s in double quotes is the same SQL statement with the same syntax as what we would enter if we were logged in to the interface. The syntax doesn’t change because we’re entering the SQL statement from the command line. We don’t need a terminating semicolon, though, because the mysql client knows where the SQL statement ends.
Finally, after the SQL statement, we provide the name of the database to be used. We could eliminate this argument by adding the database name before the table name, separated by a dot (i.e., bookstore.vendors).
There are other command-line options with the mysql client. There are also other command-line utilities available for accessing and manipulating data in MySQL. You can use some of these utilities for backing up the database or for performing server maintenance and tuning. They are covered in Chapters 15 and 16.
Conclusion
Obviously, you can do plenty more with MySQL. This tutorial was designed to give you an idea of how to create a database and manage the data in some very basic ways. The remaining sections of this book provide details on MySQL statements, clauses, arguments, options, and functions. If you’re new to MySQL, you can begin with the statements and clauses highlighted in this chapter, and refer to the chapters that follow for more options and to learn about other functions and features as needed.
Part II. SQL Statements and Functions
This part of the book is a complete reference for the version of the SQL language used by MySQL. It divides the SQL statements and functions by the basic functions (scheme design, data manipulation, replication, etc.). Examples use the mysql command-line client, but they are equally valid when issued from the programming APIs discussed in Part IV.
Some of the chapters in this part start with a list of statements grouped by type, as a quick reference. The statements are then listed in alphabetical order. For the more complex statements, to simplify their presentation, I’ve broken the syntax into several sections according to the different uses of the statement.
Here are some general elements of MySQL’s SQL syntax:
SQL statements may span multiple lines, but they must end with either a semicolon or \G, unless another character is specified with DELIMITER.
When values are enclosed in parentheses, multiple values can usually be specified, separated by commas.
Strings and dates must be specified within single or double quotes, unless a date is given as a numeric and is part of a date calculation.
Elements of a statement’s syntax are case-insensitive. However, on Unix-type systems, database and table names, as well as filenames, are case-sensitive.
The MySQL statements, clauses, and functions explained in Chapters 4 through 14 are grouped in each chapter, first by statements and clauses, then by functions. They are listed alphabetically within each group. Each statement is given with its syntax and an explanation. Optional clauses and flags are shown in square brackets. Particular components, such as a database or table name, are shown in italics. The vertical bar is used to separate alternative choices and is not part of the statement syntax.
Some statements have alternative syntax structures. These alternatives are usually shown in complete