Entering Queries
Make sure you are connected to the server, as discussed in the previous section. Doing so will not in itself select any database to work with, but that’s okay. At this point, it’s more important to find out a little about how to issue queries than to jump right in creating tables, loading data into them, and retrieving data from them. This section describes the basic principles of entering commands, using several queries you can try out to familiarise yourself with how mysql works.
Here’s a simple command that asks the server to tell you its version number and the current date. Type it in as shown here following the mysql> prompt and press Enter:
mysql> SELECT VERSION( ), CURRENT_DATE; +--------------+--------------+ | VERSION( ) | CURRENT_DATE | +--------------+--------------+ | 3.22.20a-log | 1999-03-19 | +--------------+--------------+ 1 row in set (0.01 sec) mysql>
This query illustrates several things about mysql:
A command normally consists of a SQL statement followed by a semicolon. (There are some exceptions where a semicolon is not needed. QUIT, mentioned earlier, is one of them. We’ll get to others later.)
When you issue a command, mysql sends it to the server for execution and displays the results, then prints another mysql> to indicate that it is ready for another command.
mysql displays query output as a table (rows and columns). The first row contains labels for the columns. The rows following are the query results. Normally, column labels are the names ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access