Logo Your Web Hosting Solution
Line
MySQL Manual
Introduction
Connecting
Queries
Databases
Import & Export
Tutorials Index
Home Page
MySQL Tutorial - Queries

Before you can send queries to the server, you must be connected and logged in.

Ensure you have used supportbot to create a username and database for your hosting account first.

1. Our first query

Let's start with a simple example by asking the MySQL server to output the current date.

mysql> SELECT CURRENT_DATE;
+------------------+
| CURRENT_DATE |
+------------------+
|   2002-10-17    |
+------------------+
1 row in set (0.00 sec)

mysql>

This simple example teaches us several things. MySQL commands usually end with a semicolon (;). There are some exceptions to this rule (QUIT being one).

When MySQL is done executing your command, it returs a new mysql> prompt, indicating it is ready.

Output includes the number of rows returned and the amount of time required to execute the query.

2. Multiple queries

The below example illustrates how you can request two queries on the same line.

mysql> SELECT VERSION(), CURRENT_DATE;
+--------------+------------------+
| VERSION()   | CURRENT_DATE |
+--------------+------------------+
| 3.23.40-log  | 2002-10-17     |
+--------------+------------------+
1 row in set (0.00 sec)

mysql>

This simply outputs the software version and the current date. The below example shows the same queries, expressed in a multiple-line statement.

mysql> SELECT
    -> VERSION()
    -> ,
    -> CURRENT_DATE;
+--------------+------------------+
| VERSION()   | CURRENT_DATE |
+--------------+------------------+
| 3.23.40-log  | 2002-10-17     |
+--------------+------------------+
1 row in set (0.00 sec)

mysql>

As you can see, the output is the same, only the formatting of the query is different (multiple lines).

Top Of Page 
Line
Copyright© 1996 - 2024 Clockwatchers, Inc.