01-06-2013, 04:15 PM
MySQL Tutorial
Tutorial.pdf (Size: 379.39 KB / Downloads: 18)
Tutorial
This chapter provides a tutorial introduction to MySQL by showing how to use the mysql client program
to create and use a simple database. mysql (sometimes referred to as the “terminal monitor” or just
“monitor”) is an interactive program that enables you to connect to a MySQL server, run queries, and view
the results. mysql may also be used in batch mode: you place your queries in a file beforehand, then tell
mysql to execute the contents of the file. Both ways of using mysql are covered here.
Connecting to and Disconnecting from the Server
To connect to the server, you will usually need to provide a MySQL user name when you invoke mysql
and, most likely, a password. If the server runs on a machine other than the one where you log in, you will
also need to specify a host name. Contact your administrator to find out what connection parameters you
should use to connect (that is, what host, user name, and password to use).
Date Calculations
MySQL provides several functions that you can use to perform calculations on dates, for example, to
calculate ages or extract parts of dates.
To determine how many years old each of your pets is, compute the difference in the year part of the
current date and the birth date, then subtract one if the current date occurs earlier in the calendar year
than the birth date. The following query shows, for each pet, the birth date, the current date, and the age in
years.