Download ebooks file MySQL Learn MySQL the Quick and Easy Way 2nd edition Edition Ullman all chapters
Download ebooks file MySQL Learn MySQL the Quick and Easy Way 2nd edition Edition Ullman all chapters
com
https://ebookgate.com/product/mysql-learn-mysql-the-quick-
and-easy-way-2nd-edition-edition-ullman/
OR CLICK HERE
DOWLOAD NOW
https://ebookgate.com/product/teach-yourself-visually-digital-video-
the-fast-easy-way-to-learn-2nd-edition-lonzell-watson/
ebookgate.com
https://ebookgate.com/product/mysql-4th-edition-paul-dubois/
ebookgate.com
https://ebookgate.com/product/php5-and-mysql-bible-tim-converse/
ebookgate.com
https://ebookgate.com/product/mysql-php-database-applications-2nd-ed-
edition-brad-bulger/
ebookgate.com
Beginning PHP and MySQL E Commerce 2nd Edition Edition
Cristian Darie
https://ebookgate.com/product/beginning-php-and-mysql-e-commerce-2nd-
edition-edition-cristian-darie/
ebookgate.com
https://ebookgate.com/product/mysql-phrasebook-1st-edition-edition-
greant/
ebookgate.com
https://ebookgate.com/product/php-and-mysql-web-development-luke-
welling/
ebookgate.com
https://ebookgate.com/product/mysql-reference-manual-1st-edition-
michael-widenius/
ebookgate.com
https://ebookgate.com/product/mysql-in-a-nutshell-1st-edition-dyer/
ebookgate.com
VISUAL QUICKSTART GUIDE
MySQL
Second Edition
Larry Ullman
Peachpit Press
Visual QuickStart Guide
MySQL, Second Edition
Larry Ullman
Peachpit Press
1249 Eighth Street
Berkeley, CA 94710
510/524-2178
510/524-2221 (fax)
Notice of Rights
All rights reserved. No part of this book may be reproduced or transmitted in any form by any means,
electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of
the publisher. For information on getting permission for reprints and excerpts, contact
permissions@peachpit.com.
Notice of Liability
The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has
been taken in the preparation of the book, neither the author nor Peachpit Press shall have any liability to any
person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the
instructions contained in this book or by the computer software and hardware products described in it.
Trademarks
Visual QuickStart Guide is a registered trademark of Peachpit Press, a division of Pearson Education.
MySQL is a registered trademark of MySQL AB in the United States and in other countries. Macintosh and
Mac OS X are registered trademarks of Apple Computer, Inc. Java is a registered trademark of Sun Microsystems,
Inc. Microsoft, Windows, Windows 95, Windows 98, Windows Me, Windows NT, and Windows XP are registered
trademarks of Microsoft Corp. Screenshots of Web sites in this book are copyrighted by the original holders.
All other trademarks are the property of their respective owners.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and Peachpit was aware of a trademark claim, the
designations appear as requested by the owner of the trademark. All other product names and services identified
throughout this book are used in editorial fashion only and for the benefit of such companies with no intention
of infringement of the trademark. No such use, or the use of any trade name, is intended to convey endorsement
or other affiliation with this book.
ISBN 0-321-37573-4
987654321
Table of Contents
Upgrading MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
v
Table of Contents
vi
Table of Contents
Table of Contents
Stored Routines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Using OUT Parameters . . . . . . . . . . . . . . . . . . . . . . 330
Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
vii
Table of Contents
Other . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
Index 449
viii
Introduction
i
In the midst of the Information Age, where
more and more data is being stored on
computers, the need for high-speed, reliable
databases has increased dramatically. For years,
large companies, such as Oracle, Microsoft,
and IBM, have been providing high-end data
Introduction
warehousing applications for mission-critical
work. These programs were used primarily
by Fortune 500 companies, which can afford
their extreme cost and personnel demands.
Meanwhile, within the open-source community,
a new wave of small, reliable, and inexpensive
database applications came to the market. Such
software, of which MySQL and PostgreSQL
are the best examples, gave common users
and developers on a budget a practical data-
base choice.
MySQL, fortunately, has left its modest begin-
nings in the dust, turning into a robust, reliable,
and easy-to-manage database application.
More astounding, MySQL has managed to
retain its open-source roots, continuing to be
available for some uses at no expense (although
check the licensing for your particular situa-
tion). MySQL’s capabilities and low cost explain
why major operations such as Yahoo!, the
United States Census Bureau, and NASA use
it within their organizations. But you, too,
can incorporate MySQL into your projects.
With MySQL: Visual QuickStart Guide, you
will be doing just that in no time!
ix
Introduction
What Is MySQL?
MySQL is the world’s most popular, and
some might argue best, open-source data-
base. In fact, more and more, MySQL is a
viable competitor to the pricey goliaths such
as Oracle and Microsoft’s SQL Server.
MySQL was created and is supported
by MySQL AB, a company based in Sweden
(www.mysql.com, Figure i.1). MySQL is a
database management system (DBMS) for Figure i.1 The MySQL home page, located at
relational databases (therefore, MySQL is an www.mysql.com, is where you can obtain the software,
view the manual, get support, and more.
RDBMS). A database is simply a collection
of (often interrelated) data, be it text, num-
bers, or binary files, that are stored and kept
organized by the DBMS. Technically, MySQL
is an application that manages files called
databases, but you will commonly hear the
term “database” applied equally to both the
What Is MySQL?
Pronunciation Guide
MySQL is technically pronounced “My
Ess Que Ell,” just as SQL should be said
“Ess Que Ell.” You will also hear people,
although never this author, pronounce it
as “My Sequel” and “Sequel.” This is tech-
nically incorrect. It’s a trivial issue, of
course, but a common question.
x
Introduction
What Is MySQL?
MySQL can work with tables as large as
eight million terabytes (since version 3.23)
on some operating systems and generally a
healthy 4 GB otherwise.
In the next section of this Introduction,
I discuss the very important topic of the
available MySQL versions. Which version
of MySQL you use will greatly impact your
experience, particularly what you can and
cannot do (as new features are added).
xi
Introduction
MySQL Versions Table i.1 Some of the significant new features, and in
which version of MySQL they were added.
MySQL, at the time of this writing, is on version MySQL Feature Introductions
5.0.19, with the significant upgrade version 5.1
Fe at u r e M y S Q L Ve r s i o n
due out later in 2006. Since the first edition
Full-Text Binary Mode Searches 4.0
of this book was written (in 2002), there have
Unions 4.0
been several important releases of MySQL:
Subqueries 4.1
4.0, 4.1, and 5.0. Each has added new features
Stored Procedures 5.0
to the software (Table i.1), while changing
Views 5.0
some functionality in the process. For this
Cursors 5.0
reason, I cannot stress this enough: it is
Triggers 5.0 and 5.1
vitally important that you know and remem-
ber what version of MySQL you are using.
In this book I will highlight features that are
new to, or have changed in, later versions of
MySQL. Paying attention to this will help
minimize problems and frustrations.
MySQL Versions
SQL Versions
SQL, which stands for Structured Query Language (depending upon whom you ask), is the
language used to interact with practically every database application. It is a standardized lan-
guage, meaning that the terms and syntax it supports depend upon the regulated standard.
The current SQL standard was released in 2003.
MySQL, like most database applications, adheres to the standards for the most part. MySQL
does not support a few features of standardized SQL and has its own particular terminology
as well. This is true for most database applications. In this book I focus only on MySQL’s
implementation of SQL. Almost every SQL command you learn here will be applicable to all
database applications, but there may be some minor distinctions. If you ever go from using
MySQL to using PostgreSQL or Oracle or SQL Server, you should be fine, but you’ll need to do
a little research to smooth the transition.
xii
Introduction
xiii
Introduction
Technical Requirements
In order to follow the discussions in this
book, there are a few, though not too
restricting, technical requirements. The
first, naturally, would be the MySQL software
itself. Fortunately, this is freely available and
runs on most operating systems (Figure i.6).
Chapter 1, “Installing MySQL,” will cover the
fundamentals of installing MySQL on three
popular operating systems: Windows, Linux,
and Mac OS X.
The bulk of the chapters involve administer-
Figure i.6 MySQL is available in versions designed to
ing and interacting with the database from run on almost every operating system, including
a command-line perspective. Whichever various types of Unix and Windows.
application on your operating system gives
you this access is acceptable, be it a DOS
Technical Requirements
xiv
Introduction
xv
Introduction
xvi
Installing MySQL
1
Obviously the first thing you’ll need to do to
begin using MySQL is install the software.
But because MySQL is an open-source data-
base application, you have more options when
it comes to installation than you would with
a commercial application. These choices
range from the very simple execution of an
installer to customizing and compiling your
own installation using MySQL’s source files
Installing MySQL
(the actual code MySQL is written in).
In this chapter I will cover basic installation
on the Windows, Macintosh, and Linux
operating systems. These three platforms
cover a large portion of the MySQL audience,
but the database is available on many other
platforms as well. Between the Windows
binary and the Linux source installation
instructions, you should have a good sense
of the various issues regardless of the oper-
ating system you are using.
This chapter covers downloading the software,
installing the server, and running the initial
setup and configuration. If you have problems
with any of the installation steps described
here, see Appendix A, “Troubleshooting,” or
the relevant sections of the MySQL manual.
1
Chapter 1
2
Installing MySQL
Figure 1.1 MySQL runs on the vast majority of available operating systems.
3
Chapter 1
4
Installing MySQL
5
Chapter 1
6
Installing MySQL
7
Chapter 1
Configuring MySQL
on Windows
Somewhat new to MySQL is the MySQL
Server Instance configuration wizard, a
graphical tool for customizing how MySQL
runs. It’s available starting with MySQL 5.0
and only on Windows.
The wizard is fairly simple to use, but it’s
pretty important, so I’ll run through it with
you. The end result will be the creation of a
my.ini file, which the MySQL server and Figure 1.6 Choose a configuration type: Detailed or
Standard.
utilities will use for their settings.
To configure MySQL on Windows:
1. Launch the configuration wizard.
You can access this immediately after
Configuring MySQL on Windows
8
Installing MySQL
If you have a firewall installed and run- ■ The MySQL configuration wizard can be
ning on your machine, you’ll most likely used to configure a new installation or to
need to tweak it in order for MySQL to reconfigure an existing MySQL installa-
run. This is necessary because a firewall, tion. After you’ve used it once, the next
by definition, limits access to your com- time it runs, you’ll be given the option
puter. MySQL, by default, uses the port to reconfigure the current instance or
3306, which may be blocked by the firewall. remove it entirely. Removing the configu-
ration only stops the MySQL service and
If you have problems, which may appear deletes the my.ini file; it does not delete
when the configuration wizard attempts the installed files or your databases.
to finish doing its thing, try temporarily
turning off your firewall to confirm that
is the source of the problem. If MySQL
works with the firewall disabled, you know
the firewall is the issue. The solution then
is to adjust the firewall’s settings to allow
communications through port 3306. How
you do this differs from one operating
system or firewall program to the next,
but a quick search through the applicable
firewall help files or Google will turn up
useful answers.
9
Chapter 1
Installing MySQL Table 1.2 After installing MySQL, you’ll have these
folders (all found within the main MySQL folder).
on Macintosh MySQL Layout on Mac OS X
Mac OS X uses a FreeBSD (Unix) foundation Subfolder Contains
10
Installing MySQL
11
Chapter 1
12
Installing MySQL
13
Chapter 1
14
Installing MySQL
15
Chapter 1
10. Move to the installation directory. Figure 1.18 After installing the databases, you will
cd /usr/local/mysql see these lines, telling you what steps to take to run
the server.
The next couple of steps will take place
from within the installed MySQL folder.
11. Install the default databases.
sudo bin/mysql_install_db
→ --user=mysql
This step will create the database MySQL
needs to function properly (called mysql)
along with an appropriately named test
database (called test). Once the script has
run, you will see a number of messages
regarding the software (Figure 1.18).
16
Installing MySQL
17
Chapter 1
Basic Configuration
Options
Because MySQL is open source and very
flexible in how it runs, there are numerous
ways you can configure the software. By
installing MySQL from the source files, as
I did on Linux, you can establish certain Figure 1.20 The MySQL manual details the most
parameters at the time of installation that common configuration options, while ./configure
affect how the software functions. For starters, --help gives the entire list.
18
Installing MySQL
19
Chapter 1
20
Installing MySQL
Upgrading MySQL
Eventually you might have the need to
upgrade your MySQL installation. When
doing so, it’s important to consider what
type of upgrade you’ll be making. If you are
staying within the same release series, going
from, say, 4.1.12 to 4.1.17 or from 5.0.3 to
5.0.4, that’s a relatively safe upgrade. If you
are changing the release series, 4.0.9 to 4.1.12
or 4.1.17 to 5.0.18, there’s a bit more to it.
The first type of upgrade is best if you want
the latest, most stable and secure version,
without any hassle. The second type of
upgrade is normally for the benefit of adding
features but has a higher potential for prob-
lems. MySQL recommends jumping only a
single release at a time (3.23 to 4.0, 4.0 to 4.1,
4.1 to 5.0, and so on).
The MySQL manual covers the specifics of
upgrading from one version of MySQL to
Upgrading MySQL
another in great detail so that you can be best
prepared as to what you might encounter.
The directions I give next are more general-
ized recommendations.
To upgrade MySQL:
1. Back up your existing MySQL data.
See Chapter 13, “MySQL Administration,”
for information about how to do this.
2. Stop the currently running MySQL server
daemon.
Technically, this isn’t required, especially
when upgrading within the same release
series (e.g., from 5.0.15 to 5.0.18), but I
do think it is a good idea. I will discuss
stopping the MySQL application more
specifically in Chapter 2.
continues on next page
21
Chapter 1
22
Running MySQL
2
Now that the MySQL software has been suc-
cessfully installed (presumably), it’s time to
learn how to start, stop, and basically admin-
ister your database server. Assuming that
you did not install just the client software
(e.g., as a Linux RPM), you now have a data-
base server as well as several different utilities
that will aid you in running and maintaining
your databases.
In this chapter I will first cover starting and
stopping MySQL on different operating sys-
Running MySQL
tems (Windows XP, Mac OS X, and Ubuntu
Linux). After that, I will go into important
administrative knowledge that you’ll need,
regardless of the platform in use. This includes
the introduction of two important applica-
tions: mysqladmin and the mysql client. During
these discussions you will set a root user pass-
word, which is vital to security, and learn how
to control user access to databases.
23
Chapter 2
Running MySQL on
Windows and Windows NT
Unfortunately, you cannot truly know that
MySQL has been successfully installed until
you’ve been able to actually start the database
server. Starting MySQL is a frequent place of
problems and confusion, especially for the
beginning or intermediate user. On the bright
side, MySQL is very stable and reliable once
you have it running, and it can remain up for
months at a time without incident. If you run Figure 2.1 You may have the option of installing
into difficulties in these steps, check the MySQL as a service when you configure the software.
“Starting MySQL” section of Appendix A,
“Troubleshooting.” Or, as always, search the
version of the MySQL manual that corresponds
to the version of MySQL that you installed.
When it comes to running MySQL on
Running MySQL on Windows and Windows NT
24
Running MySQL
25
Chapter 2
26
Running MySQL
27
Chapter 2
28
Running MySQL
✔ Tips
■ If, while running the MySQL Server
Instance Configuration Wizard (Figure 2.1),
you opted to include the bin directory in
the Windows PATH, then you can start
MySQL by just using mysqld --console.
This will be true no matter what directory
you are currently in (within the console
window).
■ Technically, on Windows, you could go
straight into the bin directory and run
your commands from there. The syntax
demonstrated in the preceding steps is
common on other operating systems, so
I’ve used it for consistency’s sake.
■ If you don’t use the --console option
when starting MySQL, all output will be
29
Chapter 2
30
Running MySQL
31
Chapter 2
32
Running MySQL
Running MySQL on
Mac OS X
On Mac OS X, there are a handful of ways
to get MySQL running. For starters, there
is an optional System Preferences panel
(Figure 2.15) that handles the task nicely.
There is also the choice of having MySQL
automatically start when you turn on your
Figure 2.15 MySQL on Mac OS X comes with a System computer. You can enable this feature by
Preferences panel that can be used to stop and start
the database server.
checking the box in the System Preferences
panel or by installing the MySQL Startup
Item when you installed MySQL (see the
instructions in Chapter 1). With the Startup
Item, you can use the information presented
in the sidebar to also control MySQL.
◆ /System/Library/MySQLCOM/MySQLCOM
◆ /Library/MySQL/MySQL
◆ /Library/MySQLCOM/MySQLCOM
Once you confirm its location (just use the Finder to hunt around), you can start and stop
MySQL using the proper commands within a Terminal window. These would be simply
sudo /path/to/script start
and
sudo /path/to/script stop
(You have to run them using sudo; you will then be prompted for your Mac OS X administra-
tive password.)
For example, in two test environments I have—MySQL 4.1.13 on Mac OS X 10.4 Server and
MySQL 5.0.18 on Mac OS X 10.3 Server—I use
sudo /System/Library/StartupItems/MySQL/MySQL start
If there’s a problem, an error message will be displayed, and the Terminal will seem to sit
there. In that case, press Enter to get a prompt again. Voilà! That’s all there is to it!
33
Discovering Diverse Content Through
Random Scribd Documents
55 The Romans compel the Parthians to evacuate Armenia.
58 Vologases again attacks Armenia and brings on war with
Rome. Revolt of Hyrcania. Corbulo destroys Artaxarta
and occupies Tigranocerta (59).
61 Peace restored in Hyrcania.
62 War with Rome resumed. The Romans are repulsed.
63 Corbulo crosses the Euphrates, and the Parthians sue for
peace.
72 The Alani drive Pacorus of Media from his throne.
75 The Alani enter Parthia. Vologases appeals in vain to
Vespasian.
78 About this date Vologases dies. He seems to have been
succeeded by two kings, Vologases II and Pacorus
II, probably brothers, and reigning together.
81 Artabanus IV appears to be the king in this year. He
protects Terentius Maximus, who pretends to be Nero.
Parthia is torn with civil wars.
93 Pacorus II is sole king.
110 Pacorus sells the crown of Edessa to Abgar VII. Death of
Pacorus. His brother (or perhaps son) Chosroes or
Osroes succeeds. Vologases II reappears as a rival
king, also a Mithridates or Meherdates VI. Parthia is
completely upset with civil war which goes on until
113 Chosroes wrests Armenia from King Exedares and gives
it to Parthamariris, both sons of Pacorus.
114 The emperor Trajan, indignant at Chosroes’ act, seizes
Armenia and makes it a Roman province.
115 Trajan takes Ctesiphon and Seleucia.
116 Revolt in Parthia with Mithridates VI at its head. Death
of Mithridates, and his son Sinatruces takes his place.
Chosroes regains Nisibis, Seleucia, and Edessa.
117 Trajan crowns Parthamaspates king of Parthia,
deposing Chosroes. Death of Trajan. Hadrian withdraws
Roman soldiers and Chosroes recovers throne.
Parthamaspates expelled.
130 About this date Chosroes dies and Vologases II rules as
sole king. The influence of Rome preserves peace in the
kingdom.
148 Death of Vologases, aged ninety-six, having reigned
seventy-one years. Vologases III succeeds. He
continues the peace with Rome until,
162 when, after death of Antoninus Pius, Vologases enters
Armenia and expels the king. The greatest war between
Rome and Parthia ensues.
164 Aridius Cassius drives Vologases from Syria, enters
Babylonia, and burns Seleucia, the most important city
of the East.
165 Great plague, originating in Parthia, spreads over the
whole world.
166 Peace with Rome. Mesopotamia becomes a Roman
province. Parthia begins steadily to decline.
191 Death of Vologases III. Vologases IV succeeds.
194 Vologases permits the Medes to assist Orrhœne in revolt
against the Romans.
196 The Parthians ravage Mesopotamia.
199 Severus surprises the Parthians and takes Seleucia,
Coche, and Ctesiphon.
201 Siege of Atra by Severus, who is compelled to raise it.
209 Vologases succeeded by his son, Vologases V.
213 His brother, Artabanus (IV), appears as a claimant of
the throne. Civil war.
215 Caracalla demands the surrender of Tiridates, brother of
Vologases IV, who has taken refuge with Vologases V.
The latter refuses to give him up. Caracalla declares
war, and the exile is delivered up. Artabanus gains the
upper hand and holds Ctesiphon. Caracalla declares war
on Artabanus on the latter’s refusal to give his daughter
to the Roman emperor.
216 The Romans penetrate to Arbela.
217 On death of Caracalla an immense Parthian force
invades Mesopotamia. Macrinus defeated and purchases
peace.
222 Artabanus replaces his brother over the whole of
Parthia.
224 Ardashir, the Sassanian king of Persis (or Persia),
invades Parthia, taking several cities.
227 Battle of Hormizdjan. Victory of Ardashir and death of
Artabanus.
228 Ardashir completes his conquest. End of the Parthian
empire.
THE ARABS
ebookgate.com