Using MySQL

These initial steps come from Devshed:

After installing MySQL, the server part (MySQL) should be running; if in doubt, enter services.msc in DOS environment and look for it.

There is a client program, mysql, which is a command-line tool. Type "mysql" in DOS environment, and get the "mysql>" prompt.

Initial commands: help

provides info including that you end each command with a semi-colon (;).

More useful initial commands:

SQL Statements

Create a database table:

CREATE TABLE books (
  title char(50),
  author char(50),
  ISBN char(50) NOT NULL,
  PRIMARY KEY (ISBN)
);

Then, you can add books to the database using statements such as:

INSERT INTO books ("Web Database Apps", "Hugh and Dave", "123-456-N");

Once you’ve added data, you can retrieve facts about the books using queries such as the following that finds the author and title of a book with a specific ISBN:

SELECT author, title FROM books WHERE ISBN = "456-789-Q";

"Entering Queries" section of MySQL tutorial, from MySQL Manual

mysql> SELECT VERSION(), CURRENT_DATE;
mysql> SELECT VERSION(); SELECT NOW();
mysql> SELECT
    -> USER()
    -> ,
    -> CURRENT_DATE;
mysql> SELECT SIN(PI()/4), (4+1)*5;
On a multi-line query, the "->" prompt informs you that all is well with the query so far, just need a terminating ";".
if the query is "'>", MySQL is saying the query has an unterminated string, as in
mysql> SELECT * FROM my_table WHERE name = 'Smith AND age < 30;
    '>
At this point, you need to maybe terminate the string, but you may also want to just clear out the command and start again. The critical token to do this is "\c". You may otherwise not get the prompt back!
mysql> SELECT * FROM my_table WHERE name = 'Smith AND age < 30;
    '> '\c
mysql>

"Using MySQL in Batch Mode"
Manual says

mysql> source filename;
mysql> \. filename
Not "/." ???

More MySQL links

download MySQL Query Browser

MySQL Reference Manual on loading tables from a text file.

Very Powerful!

a text file pet.txt  containing one record per line, with values separated by tabs, 
and given in the order in which the columns were listed in the CREATE TABLE statement. 
For missing values (such as unknown sexes or death dates for animals that are still living), 
you can use NULL values. To represent these in your text file, use \N  (backslash, capital-N). 
For example, the record for Whistler the bird would look like this 
(where the whitespace between values is a single tab character):

Whistler        Gwen    bird    \N      1997-12-09      \N

To load the text file pet.txt into the pet table, use this command:

mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet;

Note that if you created the file on Windows with an editor that uses \r\n as a line terminator, 
you should use:

mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet
    -> LINES TERMINATED BY '\r\n';

(On an Apple machine running OS X, you would likely want to use LINES TERMINATED BY '\r'.)

You can specify the column value separator and end of line marker explicitly in the 
LOAD DATA statement if you wish, but the defaults are tab and linefeed. 
These are sufficient for the statement to read the file pet.txt properly. 

MySQL Reference Manual on selecting columns

MySQL Reference Manual on sorting rows

MySQL Reference Manual date calculations

MySQL++ is a C++ wrapper for MySQL in the style of STL. You need a C++ environment which fully supports STL - which rules out Microsoft Visual Studio 7.0 and earlier (7.1 is the first in which Microsoft supports STL)

More info about SQL

sqlzoo.net