0% found this document useful (0 votes)
8 views

The Definitive Guide to MySQL 2nd Edition Michael Kofler instant download

The Definitive Guide to MySQL, Second Edition by Michael Kofler is a comprehensive resource for both new and experienced users of MySQL, covering installation, configuration, SQL programming, and administration. The book includes practical examples and a wide range of topics, making it a valuable reference for programmers and database administrators. It is highly recommended for anyone interested in learning or enhancing their MySQL skills.

Uploaded by

werekomiddow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

The Definitive Guide to MySQL 2nd Edition Michael Kofler instant download

The Definitive Guide to MySQL, Second Edition by Michael Kofler is a comprehensive resource for both new and experienced users of MySQL, covering installation, configuration, SQL programming, and administration. The book includes practical examples and a wide range of topics, making it a valuable reference for programmers and database administrators. It is highly recommended for anyone interested in learning or enhancing their MySQL skills.

Uploaded by

werekomiddow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

The Definitive Guide to MySQL 2nd Edition

Michael Kofler pdf download

https://ebookname.com/product/the-definitive-guide-to-mysql-2nd-
edition-michael-kofler/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

The Definitive Guide to SQLite Definitive Guide 1st


Edition Mike Owens

https://ebookname.com/product/the-definitive-guide-to-sqlite-
definitive-guide-1st-edition-mike-owens/

The Definitive Guide to SOA Oracle Service Bus Second


Edition The Definitive Guide Jeff Davies

https://ebookname.com/product/the-definitive-guide-to-soa-oracle-
service-bus-second-edition-the-definitive-guide-jeff-davies/

The definitive guide to SOA Oracle Service Bus 2nd ed


Edition Jeff Davies

https://ebookname.com/product/the-definitive-guide-to-soa-oracle-
service-bus-2nd-ed-edition-jeff-davies/

Professional Outlook 2007 Programming Programmer to


Programmer 1st Edition Ken Slovak

https://ebookname.com/product/professional-
outlook-2007-programming-programmer-to-programmer-1st-edition-
ken-slovak/
On Macedonian Matters from the Partition and Annexation
of Macedonia in 1913 to the Present A Collection of
Essays on Language Culture and History Victor Friedman
(Editor)
https://ebookname.com/product/on-macedonian-matters-from-the-
partition-and-annexation-of-macedonia-in-1913-to-the-present-a-
collection-of-essays-on-language-culture-and-history-victor-
friedman-editor/

Persisting speech difficulties in children 1st Edition


Michelle Pascoe

https://ebookname.com/product/persisting-speech-difficulties-in-
children-1st-edition-michelle-pascoe/

Biomarkers of Kidney Disease 1st Edition Charles L.


Edelstein

https://ebookname.com/product/biomarkers-of-kidney-disease-1st-
edition-charles-l-edelstein/

Canada in the Frame 1st Edition Philip J. Hatfield

https://ebookname.com/product/canada-in-the-frame-1st-edition-
philip-j-hatfield/

Programming in Visual C 2008 3rd Edition Julia Case


Bradley

https://ebookname.com/product/programming-in-visual-c-2008-3rd-
edition-julia-case-bradley-2/
DNA Methylation Methods and Protocols 2nd Edition Jörg
Tost (Auth.)

https://ebookname.com/product/dna-methylation-methods-and-
protocols-2nd-edition-jorg-tost-auth/
Praise for The Definitive Guide to MySQL, Second Edition:
"In short, it is one of the most exhaustive books on the subject and provides every-
thingfor a new user as well as complete reference coverage for an experienced user,
programmer, or administrator. The Definitive Guide to MySQL, Second Edition is
highly recommended for anyone interested in learning, administering, or program-
ming MySQL."
-Harold McFarland, The Midwest Book Review (www.midwestbookreview.com)

Praise for the first edition of The Definitive Guide to MySQL:


"There are a number ofbooks written on the subject ofMySQL databases. I have had
the opportunity to read some and have found many of them lacking and confusing.
I happened to get a glimpse of a book simply called MySQL, it seemed quite inter-
esting and as I was about to build a dynamically driven website for a client I felt I
should get this book as the others I have seen were not up to the job. As I suspected
from my chancery glimpse, it was what I needed.

"MySQL by Michael Kofler is a comprehensive guide to MySQL. The book explains


. how to install and configure MySQL on both Linux/UNIX and also on MS
Windows NTI200019x environments. Kofler presents some of the issues one should
consider when using MySQL. The books guides you through SQL programming
and MySQL administration."
-M. Williams, Kemputing (http://kemputing.net)

"Whatever the secret formula that goes into Apress books, the result produced is
clear, thorough, useful, powerful books that are easy to read, grasp, and apply. The
titles are focused on explodingly popular computer topics. MySQL by Michael
Kofler lives up to the high Apress standard."
-International News Agency (www.inewsagency.com)
The Definitive Guide
to MySQl
Second Edition
MICHAEL KOFLER
Translated by DAVID KRAMER

APress Media, LLC


The Definitive Guide to MySQL, Second Edition
Copyright ©2004 by Michael Kofler
Originally published by Apress in 2004

All rights reserved. No part of this work may be reproduced or transmitted in any fonn or by
any means, elecuonic or mechanical, including photocopying. recording. or by any infonnation
storage or retrieval system, without the prior written pennission of the copyright owner and the
publisher.

ISBN 978-1-59059-144-4 ISBN 978-1-4302-0669-9 (eBook)


DOI 10. 1007/978-1-4302-0669-9

Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.

Translator, Editor, and Compositor: David Kramer

Editorial Board: Steve Anglin, Dan Appleman, Craig Berry, Gary Cornell, Tony Davis, Jason
Gilmore, Steven Rycroft, Julian Skinner, Martin Streicher, Jim Sumser, Karen Watterson, Gavin
Wray, John Zukowski

Assistant Publisher: Grace Wong

Production Manager: Kart Brooks

Proofreader: Elizabeth Berry

Cover Designer: Kurt Krames

Manufacturing Manager: Tom Debolski

In the United States: phone 1-800-SPRINGER, email orders~pringer-ny.cOln, or visit


http://_.springer-ny.com. Outside the United States: fax +49 6221 345229, email
orderstlspringer. de, or visit http: //_.springer .de.

For infonnation on translations, please contact Apress directly at 2560 Ninth Street, SUite 219,
BerkeJey, CA 94710. Phone 510-549-5930, fax 510-549-5939, email info{lapress ,COlI, or visit
http: //_ ... press .COlLt

The infonnation in this book is distributed on an ~as is» basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author nor Apress 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 infonnation contained in this work.
Contents at a Glance

About the Author xi


About the Translator xii
Preface xiii
I Introduction 1
1 What Is MySQU 3
2 The Test Environment 21
3 Introductory Example (An Opinion Poll) 67
4 User Interfaces 85
II Fundamentals 83
5 Database Design 121
6 An Introduction to SQL 177
7 SQLRecipes 199
8 InnoDB Tables and Transactions 239
9 Security 261
10 Administration and Server Configuration 305
III Programming 373
11 PUP: Fundamentals and Programming Techniques 375
12 PUP: Library Management 413
13 PUP: Discussion Forum 467
14 Perl 495
15 Java, JSP' JDBC 523
16 CandC++ 555
17 Visual Basic, C#, ODBC 577
IV Reference 639
18 SQL Reference 641
19 MySQLToois 703
20 API Reference 733
V Appendices 759
A Glossary 761
B MySQL4.1 767
C Example Files 781
D Bibliography 783
Index 785

ill
Contents

About the Author xi

About the Translator xii

Preface xiii
What Does This Book Offer? . xiii
What Is New in the Second Edition? xiv
What Does This Book Not Offer? xv
Example Programs, Source Code xv
Versions .. xvi
Notation . . . xvii
Commands xviii
Abbreviations xviii

I Introduction 1
1 WhatIsMySQU 3
What Is a Database? . 4
MySQL . . . . . . . . 6
Features of MySQL 7
Limitations ofMySQL . 9
MySQL Version Numbers 11
MySQL Licensing . . . 14
Alternatives to MySQL . 18
Summary . . . . . . . 19

2 The Test Environment 21


Wmdows or Unix/Linux? 22
MySQL (Server Installation) . 23
MySQL (Client Installation) 37
Apache . . . . 38
PHP . . . . . 46
phpMyAdmin 53
Perl . . . . . . 55
Connector/ODBC 62
Editors . . . . . . 63
Using MySQL with an ISP 64

v
Contents

3 Introductory Example (An Opinion Poll) 67


Overview . . . . . . . . 68
Database Development . . . . . . . . . . 69
The Questionnaire. . . . . . . . . . . . . 75
Questionnaire Evaluation and Displaying Results 76
Ideas for Improvements . . . . . . . . . . . . . . 80

II Fundamentals 83
4 User Interfaces 85
Overview . . . . . . . . . . . . 86
mysql . . . . . . . . . . . . . . 87
WinMySQLadmin (Windows) . 93
MySQL Control Center (Windows, Linux) 97
phpMyAdmin (HTML) . . . . . . . . . . 101

5 Database Design 121


Introduction . . . 122
Database Theory 123
MySQL Data Types 137
Indexes . . . . . . 146
MySQL Table Types 151
Creating Databases, Tables, and Indexes 155
Example mylibrary (Library) . . . . . 158
Example myforum (Discussion Group) 170
Example exceptions (Special Cases) . 174

6 An Introduction to SQL 177


Introduction . . . . . . . 178
Simple Queries (SELECT) 179
Queries with Related Tables . 184
Uniting Query Results . . . . 188
Grouped Queries, Aggregate Functions . 189
Altering Data (INSERT, UPDATE, and DELETE) 191

7 SQL Recipes 199


Character Strings . . . . . . . . . . . 200
Date and Time . . . . . . . . . . . . . 204
Variables and Conditionals (IF, CASE) 207
Copying Data from One Table to Another. 210
Pivot Tables . . . . . . . . . . 212
SubSELECTs . . . . . . . . . . 216
Ensuring the Integrity of Data. 219
Tracking Down Duplicates .. 224
Bringing a Table into Normal Form . 225
Processing the First or Last n Records 227
Selecting Random Records 229
Full-Text Search . . . . . . . . . . . . 231

vi
Contents

8 InnoDB Tables and 1ransactlons 239


Introduction . . . . . . . . . . . . . . . . . ...... 240
First Experiments with InnoDB Tables 244
'Ii'ansactions . . . . . . . . . . . . . . 245
Integrity'Rules (Foreign Key Constraints) . 255
9 Security 261
Introduction . 262
FirstAid . . . 267
The Internal Workings of the Access System 274
Tools for Setting Access Privileges. . . . . 290
Problems with Establishing a Connection . 296
System Security . . . . . . . . . . . . . . . 301

10 Administration and Server Configuration 305


Basic Administration 306
Backups . . . . . . . . . . . . . . . 310
Database Migration . . . . . . . . . 316
Importing and Exporting Text Files . 320
International Customization, Character Sets . 331
Logging . . . . . . . . . . . . . 335
Replication . . . . . . . . . . . . . 342
Maintenance ofMyISAM Tables . 353
Administration ofInnoDB Tables . 357
Server 1\ming . . . . . . . . 365
ISP Database Administration 369

III Programming 373


11 PHP: Fundamentals and Programming Techniques 375
Introduction . . . . . . . . . . . . . . . . . . . . . 376
Establishing a Connection to the Database . . . . 378
Executing SQL Commands . . . . . . . . . . 383
SELECT Queries . . . . . . . . . . . . . . . . . . 385
Changes to Data (INSERT, UPDATE, DELETE) . . 390
Character Strings, BWBs, DATEs, SETs, ENUMs,
andNULL. . . . . . .. . .... 391
Error Checking . . . . . . . . 403
Storing and Displaying Images 404

12 PHP: UbraryManagement 413


Introduction . . . . . . . . . . . . . . . . . . . 414
Auxiliary Functions (mylibraryconnect.inc.php) 414
Book Search (jind.php) . . . . . . . . . . . . . 416
Simple Input of New Books (simpleinput.php) . 430
Convenient Input of New Book Data (input. php) . 433
Managing the Book Categories (categories.php) 455
Ideas for Improvements and Extensions . . . . . 465

vii
Contents

13 PUP: Discussion Forum 467


How to Run It . . . . . . 468
Overview of the Program Code 471
Registration (forumlogin. php) . 473
Defining a New User (forumnewlogin. php) 475
Display list of All Discussion Groups (forumlist. php) 477
Message List of a Discussion Group (forumread. php) . 478
Representation of Message Text (forummessage. php) 484
Displaying a Thread (forumthread. php) . . . . . . . 486
Contributing to a Discussion (forumwrite •php) . 487
Leaving the Forum (forumlogout. php) 492
Possibilities for Extension . . . . . . . . . . . . 492

14 Perl 495
Programming Techniques . . . . . . . . . . . . . . . 496
Example: Deleting Invalid Data Records (mylibrary) . 512
CGI Example: Library Management (mylibrary) 514

15 Java, JSP' JDBC 523


Introduction . . . . . . . . 524
Programming Techniques . 528
Java Server Pages OSP) .. 548

16 C and C++ 555


The C Application Programming Interface 556
Connector/C++ (MySQL++) . . .... 567
17 Visual Basic, C#, ODBC 577
Fundamentals . . . . . . 578
Access . . . . . . . . . . 584
Data Analysis with Excel. 590
ADO Programming and Visual Basic/VBA 592
MyVbQL (Visual Basic Programming Without ADO/ODBC) . 612
ADO.NET (Visual Basic .NET, C#) . . . . . . . . . 616
Converter: Microsoft SQL Server - t MySQL . . . . . . . . . 635

IV Reference 639
18 SQL Reference 641
Syntax . . . . . . . . . . 642
Operators . . . . . . . . 647
Variables and Constants . 651
MySQL Data Types . . . 653
Command Overview (Thematic) . 655
Command Reference (Alphabetical) 657
Function Reference . . . . . . . . . . 692

viii
Contents

19 MySQL Tools 703


Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704
Common Options and Configuration Files . . . . . . . . . . . . . . . . . . 705
mysqld(Server) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711
mysqld_safe(Server Start) . . . . . . . . . . . . . . . . . . . . . . . . . . . 718
mysql_install_db(New Installation of mysql Database) . . . . . . . . . . . 719
mysql_fix _privilegesCUpdating the mysql Database) . . . . . . . . . . . . 719
mysql_fix _extension 5 (Renaming MylSAM Files) . . . . . . . . . . . . . . 720
mysql(SQL Command Interpreter) . . . . . . . . . . . . . . . . . . . . . . 720
mysqladmin(Administration) . . . . . . . . . . . . . . . . . . . . . . . . . . 723
mysqldump(Backup/Export) . . . . . . . . . . . . . . . . . . . . . . . . . . 724
mysqlimport(Text Import, Bulk Import) . . . . . . . . . . . . . . . . . . . . 727
mysqlshow(Displaying Information) . . . . . . . . . . . . . . . . . . . . . . 728
mysqlbug(Sending Error Notification) . . . . . . . . . . . . . . . . . . . . . 728
myisarrichk(Repairing MylSAM Files) . . . . . . . . . . . . . . . . . . . . . 729
myisampack(Compressing MyISAM Files) . . . . . . . . . . . . . . . . . . . 731

20 API Reference 733


PHPAPI . . . . . . . . . . 734
PerlDBI . . . . . . . . . . 738
JDBC (Connector/J) . . . . . . 745
CAPI . . . . . . . . . . . . . . . . 752

V Appendices 759
A Glossary 761

B MySQL4.1 767

C Example Files 781


D Bibliography 783

Index 785

ix
About the Author

MICHAEL KOFLER EARNED HIS PH.D. in computer science at Graz Technical University.
He has written a number of successful computer books on topics such as Visual Basic,
Linux, Mathematica, and Maple. Kofler is also the author of Definitive Guide to Excel
VBA, Second Edition, published by Apress.

xi
About the Translator

DAVID KRAMER EARNED HIS PH.D. in mathematics at the University of Maryland,


and his MA. in music at Smith College. For many years he worked in academia,
first as a professor of mathematics and computer science, and later as a director of
academic computing. Over the past eight years he has edited hundreds of books in
mathematics and the sciences, and has translated a number of books in a variety of
fields, including Definitive Guide to Excel VBA, by Michael Kofler; Enterprise JavaBeans
2.1, by Stefan Denninger and Ingo Peters; and Cryptography in C and C++, by Michael
Welschenbach, all published by Apress. Other translations include The Game's Afoot!
Game Theory in Myth and Paradox, by Alexander Mehlmann; the children's musical
Red Riding! Red Riding!, by Ernst Ekker with music by Sergei Dreznin; In Quest of
Tomorrow's Medicines, by Jiirgen Drews; and the novel To Err Is Divine, by Agota Bozai,
which will be published by Counterpoint Press in April 2004.

xii
Preface

MYSQL IS THE MOST WIDELY used database system in the Open Source sector. There
are many reasons why this is so:

• MySQL is fast.
• MySQL is stable.
• MySQL is easy to learn.
• MySQL runs on popular operating systems (Wmdows, Linux, Mac OS X, various
flavors of Unix).
• MySQL applications can be created in a great variety of programming languages
(such as C, C++, CD, Java, Perl, PHp, Python, VB, and VB.NET).
• MySQL is extensively documented on the Internet, and there are many books
on the subject available.
• MySQL is available for many applications free of charge (GPL license).
• Since the licensing restrictions of GPL are unacceptable for many commercial
applications, there are reasonably priced commercial licenses and optional
support contracts.
MySQL is on the verge of repeating in the database market the success achieved
by Linux in the operating system sector. In combination with PHP or Perl, MySQL is
prOviding the database system for more and more web sites. (A favorite combination
is Linux + Apache + MySQL + Perl or PHP. Such systems are called "LAMP systems"
for short.) MySQL is not just for small web sites; it is used by large firms with huge
amounts of data, such as Yahoo!, Slashdot, and Google.

What Does This Book Offer?


This book provides a complete application- and example-oriented introduction to the
database sys~m MySQL. No previous knowledge, either of SQL or database design, is
assumed.
The introductory Part I of the book begins with an extensive introduction
on installation under Wmdows and Linux. We also consider the installation of
components that are used in combination with MySQL (Apache, PHP, phpMyAdmin,
Perl, Connector/MyODBC). Building on this, our first example will show the basic use
of MySQL and PHP.
Part II, "Fundamentals," provides a large amount of background material on the
use of various user interfaces, on the database language SQL, on the proper design of
databases, on the use of InnoDB tables, on the access system ofMySQL, and on many
other topics on administration (such as backups, logging, and replication).

xiii
Preface

In Part III, "Programming," we emphasize the language PHP: Three chapters cover
basic techniques of programming and show how to construct two extensive examples
(bookkeeping, a discussion forum). Most of the PHP examples can be tried out live on
my web site. We deal with other programming languages, too, with chapters devoted
to Perl, Java, C/C++, and VB/VB.NET/C#.
We end the main text with a reference section (Part IV) that provides an overview
of the SQL commands of MySQL, the commands and options of the administrative
tools, and the functions of important programming interfaces (PHP, Perl, C, Java).
Finally, there are several appendices, comprising (A) a glossary of terms,
(B) breaking news on the forthcoming MySQL version 4.1, (C) information on the
example files for this book (available at www.apress.com) , and (D) a bibliography with
suggestions for further reading.
In combination with the example databases and programs, this book should
provide a good foundation for the development of your own database applications. In
this I wish you much fun and success.
Michael Kofler, August 2003
<mysql@kofler.cc>
http://www.kofler.cc/mysql

What Is New in the Second Edition?


There is much that is new. This book has been completely revised, from the first page
to the last. (It took as long to produce this second edition as to write the first edition
from scratch!) The following list indicates the most important changes:
• MySQL: The book now covers MySQL 4.0 and to some extent MySQL 4.1. These
changes appear throughout the entire book, from installation to the reference
section to the appendixes.
• User interface: This book describes the new user interface MySQL Control
Center and the latest version of phpMyAdmin.
• SQL recipes: There is a new chapter in the introduction on SQL that provides
answers to frequently asked SQL questions: How can I process the first/last
n data records? How can duplicate records be located? How are subSELECT
commands formed in MySQL 4.0 and 4.11 How can a full-text search be
accomplished efficiently?
• InnoDB tables, transactions, rules for integrity: A new chapter is devoted to
the InnoDB table format. InnoDB tables enable the execution of transactions
with row level locking and the protection of the integrity of relations between
tables (foreign key constraints).
• Security, access rights: Chapter 9 deals with all the innovations dealing with
access rights (MySQL privileges). A new section gives a number of practical tips
on solving problems with establishing connections.
• Administration: Everything related to administration is contained in a single
clearly structured chapter. New sections deal with the administration of InnoDB
tables and server tuning (including Query Cache).

xiv
Preface

• PUP: All PHP examples have been reworked in PHP 4.3. The HTML code
generated from the PHP examples is now largely XHMTL compatible. The PHP
text has been divided over four chapters and is now more clearly structured. In
Chapter 11, on techniques ofPHP programming, we now also deal with storing
images (file uploadl download).
• Java: A new chapter describes programming of Java and JSP applications on the
basis of JDBC and Connector IJDBC.
• C/C++: A new chapter discusses the development of C and C++ programs.
• VB6: A new example program demonstrates the use of BWBs.
• VB.NET, C#: A new section in Chapter 17 deals with the development of
ADO.NET applications with the programming languages VB.NET and C#.
• Reference: The three reference chapters have been thoroughly brought up to
date and expanded with new sections (C functions, JDBC classes).

• MySQL 4.1: Appendix B brings together all known changes in MySQL 4.1:
improved character set support (including Unicode), the use of subSELECTs,
the management of geometric and geographic data (GIS), the use of
precompiled commands (prepared statements), etc.

What Does This Book Not Offer?


Several chapters in this book deal with the programming of MySQL applications in a
variety of programming languages, such as PHp, Perl, C, C++, Java, and Visual Basic.
These chapters assume that the reader is familiar with the specific programming
language. (There is simply no room in this book to offer an introduction to a number
of programming languages.) In other words, you will profit from, say, the PHP chapter
in this book only if you are already familiar with the programming language PHP.

Example Programs, Source Code


To the extent that we are dealing with web applications, almost all of the applications
in this book can be tried out directly on my website (www.kofler.cc) . The source code
for all the examples is available at www.apress.comin the downloads section.
In the longer program listings in this book you will find at the beginning of the
example a comment line that specifies the file name appearing in the example files on
the web site, for example,

<!-- php-programming/simp1einput.php --)

To save space, sometimes only the most interesting passages in the program code are
printed.

xv
Pre/ace

Versions
The functionality of MySQL and of the programs, programming languages, and
libraries placed in its environment changes with every new version-which
sometimes appear weekly. The following overview indicates which versions I have
worked with (explanations of the various names will appear at appropriate places in
the book):
• Apache: Versions 1.3.n and 2.0.n.
• Connector/J: Version 3.0.6.
• Connector/ODBC (fonnerlyMyODBC): Version 3.51.06.

• gee: Version 3.2


• Java: Version 1.4.1 (Wmdows) and 1.3.1 (Linux).
• JSP: see Tomcat.
• Unux: MySQL and other programs were tested for this book under Linux and
Wmdows. Under Linux, the distributions Red Hat 8.0 and 9.0 (beta 3) and SuSE
8.1 and 8.2 (beta 5) were used.
• MySQL: Version 4.0.14. In most of the example programs, however, compatibil-
itywith MySQL 3.23.n was taken into account, since this version is still in use by
many Internet service providers. On the other hand, the latest developments of
MySQL 4.1 were tested with a development version (alpha version, from end of
July 2003), as described in Appendix B.
• Connector/C++: Version 1. 7.9.
• Perl: Versions 5.6 and 5.8.
• PUP: Versions 4.2 and 4.3. As file identifier, the suffix *. php is generally used.
• pbpMyAdmin: Version 2.4.
• Tomcat: Version 4.0.4 (Java Servlet 2.2, Java Server 1.1).

• Visual Basic, VBA, ADO: Visual Basic programs were developed and tested with
VB6 and VBA6 and ADO versions 2.1 and 2.7.
• Visual Basic .NET, C#, ADO.NET, ASRNET: All of these are based on Visual
Studio .NET 2002 (.NET Framework 1.0).

• Windows: All tests under Wmdows were carried out with Wmdows 2000. In
principle, everything should be valid for Wmdows NT 4, Wmdows XP, and future
versions ofWmdows.

xvi
Preface

Notation
• SQL commands and functions, as well as methods, classes, and key words
in SQL, C, Java, PRp, Perl, VB, etc., generally appear in italic (e.g., SELECT,
mysqLquery). (Note, however, that when the background text is italic, as in
the gray "Remark," "Tip," "Caution," and "Pointer" boxes and some section
headings, such commands and functions will appear in a roman font; e.g.,
SELECT.)
• Unix/Linux user names also appear in italic (e.g., root, mysql).
• MENU COMMANDS USE CAPS AND SMALL CAPS (e.g., FILE I OPEN).
• Keyboard shortcuts use a monospace font (e.g., Shift+Delete).
• File and directory names also use the monospace font (e.g., /usrllocal or
(: \Windows).
• Programs and programming commands are in the monospace font as well (e.g.,
mysql or cmd. exe).
• MySQL options and configuration parameters appear in regular roman type
(e.g., default-charset).
• Program listings and command line input appear in a sans serif font.
SQL commands are generally written in UPPERCASE letters. This is not a syntactic
necessity, but merely a convention. MySQL does not distinguish between uppercase
and lowercase in interpreting SQL commands.
In specifying Wmdows directories, we will often not write out the absolute path,
since it depends in any case on the particular installation. We observe the following
conventions:
• \Windows \ means the Wmdows directory (e.g., c: \Windows or D: \WinNT4).
• Programs \ means the directory under Wmdows for program installation (e.g.,
(:\Programs orD:\Program Files).
• Mysql \ means the MySQL installation directory (e.g., (: \Mysql or D: \Program
Files \Mysql).

xvii
Preface

Commands
Many commands will be presented in this book. We will be moving back and forth
between the Unix/Linux and Wmdows conventions. The following two commands are
equivalent:

root# mysqladmin -u root -h localhost password xxx


> mysqladmin -u root -h localhost password xxx

In each case we have given the system prompt (root# for Unix/Linux and > for
Wmdows). You type in only what follows the prompt (here in boldface type). Under
Unix/Linux it is possible to divide long inputs over several lines. The lines are
separated by means of the backslash symbol \. We shall often use this convention in
this book. The follOwing command thus corresponds to the command above:

root# mysqladmin -u root -h localhost \


password xxx

In each case, xxx is to be replaced by the relevant text (in this example by your
password). We have indicated that xxx is dummy text by the use of a slant font.

Abbreviations
I have attempted in this book to make as little use of abbreviations as possible.
However, there are several abbreviations that will be used repeatedly without being
introduced anew in each chapter:

ADO Active Data Objects (Microsoft database library)


BLOB Binary Large Object (binary data block)
GPL GNU Public License (important license for Open Source software)
HTML HyperText Markup Language (format for describing web documents)
InnoDB Not an abbreviation, but the name of a company that has developed a
special table format for MySQL (InnoDB tables)
ISP Internet Service Provider
JSP Java Server Pages
MySQL The name of the company that developed the database system MySQL
ODBC Open Database Connectivity (interface for database access, particularly
popular under Wmdows)
PHP PHP Hypertext Preprocessor (a scripting programming language for HTML
pages)
RPM Red Hat Packet Manager (a format for Linux software packages)
SQL Structured Query Language (database programming language)
URL Uniform Resource Locator (Internet address of the form
http://www.company.com/page.html)
VB Visual Basic (programming language)
VBA Visual Basic for Applications (programming language within the Microsoft
Office package)

xviii
Part I

Introduction
CHAPTER 1

What Is MySQL?

THIS CHAPTER BEGINS WITH AN overview of the most important concepts from the
world of databases and then delves into the possibilities and limitations of MySQL.
What is MySQL? What can it do, and what is it unable to do?
In addition to describing the central functions of MySQL, we shall also discuss
fully the issue of licensing MySQL. When is one permitted to use MySQL without
payment, and when is a license required?

Chapter Overview
What Is a Database? 4
MySQL 6
Features of MySQL 7
Limitations of MySQL 9
MySQL Version Numbers 11
MySQL Licensing 14
Alternatives to MySQL 18
Summary 19

3
Chapter 1

What Is a Database?
Before we can answer the central question of this chapter, namely, What is MySQL?you
and I must find a common language. Therefore, this section presents a rudimentary
database glossary, without going into great detail. (If you have already had significant
dealings with relational databases, you can sldp the next couple of pages in good
conscience.)
There is scarcely to be found a term that is less precise than database. A database
can be a list of addresses residing in a spreadsheet program (such as Excel), or it can
be the administration files of a telecommunications firm in which several million
calls are registered daily, their charges accurately calculated, monthly bills computed,
and warning letters sent to those who are in arrears. A simple database can be a
stand-alone operation (residing locally on a computer for a single user), while others
may be used simultaneously by thousands of users, with the data parceled out among
several computers and dozens of hard drives. The size of a database can range from a
few kilobytes into the terabytes. l
In ordinary usage, the word "database" is used to refer to the actual data, the
resulting database files, the database system (such as MySQL or Oracle), or a database
client (such as a PHP script or a program written in C++). Thus there arises a great
potential for confusion as soon as two people begin to converse on the subject of
databases.

Relations, Database Systems, Servers, and Clients


A database is an ordered collection of data, which is normally stored in one or more
associated files. The data are structured as tables, where cross references among tables
are possible. The existence of such relations among the tables leads to the database
being called a relational database.
Let us clarify matters with an example. A database might consist of a table with
data on a firm's customers (name, address, etc.), a table with data on the products the
firm offers, and finally, a table containing the firm's orders. Through the table of orders
it is possible to access the data in the other two tables (for example, via customer and
product numbers).
MySQL, Oracle, the Microsoft SQL server, and IBM DB2 are examples of relational
database systems. Such a system includes the programs for managing relational
databases. Among the tasks of a relational database system are not only the secure
storage of data, but also such jobs as the processing of commands for querying,
analyzing, and sorting existing data and for storing new data. All of this should be able
to take place not only on a single computer, but over a network as well. Instead of a
database system we shall often speak of a database server.
Where there are servers, there are clients. Every program that is connected to
the database system is called a database client. Database clients have the job of

1 It all started with the megabyte, which is about one million bytes. A terabyte is 1024 gigabytes,
which in turn is approximately one thousand megabytes. The prefix "mega-" comes from the
Greek for "great," or "large," while "giga-" is derived from the Greek word for "giant." In turn,
"tera-" is from the Greek word for "monster." It would appear that numbers once regarded as
large, gigantic, or even monstrously huge have become part of our everyday vocabulary.

4
What Is MySQL?

simplifying the use of the database for the end user. No user of a database system in
his or her right mind would wish to communicate directly with the database server.
That is much too abstract and inconvenient. (Let programmers worry about such
direct communication!) Instead, the user has a right to expect convenient tables,
listboxes, and so on to enable the location of data or to input new data.
Database clients can assume a variety of forms, and indeed, they are often not
recognized by the user as database programs at all. Some examples of this type of
client are HTML pages for the display and input of messages in an on-line discussion
group, a traditional program with several windows for managing addresses and
appointments, and a Perl script for executing administrative tasks. There is thus wide
scope for database programming.

Relational Versus Object-Oriented Database Systems


Relational databases have dominated the database world for decades, and they are
particularly well suited for business data, which usually lend themselves to structuring
in the form of tables. Except for the following two paragraphs, this entire book
discusses only relational databases (though we shall not always stress this point).
Another kind of database is the object-oriented database. Such databases can
store free-standing objects (without having to arrange them in tables). Although in
recent years there has been a trend in the direction of object-oriented programming
languages (such as Object-Store, 02, CacM), object-oriented databases have found
only a small market niche.
Note that relational databases can be accessed by means of object-oriented
programming languages. However, that does not turn a relational database into an
object-oriented one. Object-oriented database systems enable direct access to objects
defined in the programming language in question and the storage of such objects in
the database without conversion (persistency) . It is precisely this that is not possible
with relational database systems, in which everything must be structured in tables.

Tables, Records, Fields, Queries, SQL, Index, Keys


We have already mentioned tables, which are the structures in which the actual data
are located. Every line in such a table is called a data record, or simply record, where
the structure of each record is determined by the definition of the table. For example,
in a table of addresses every record might contain fields for family name, given name,
street, and so on. For every field there are precise conditions on the type of information
that can be stored (such as a number in a particular format, or a character string with
a predetermined maximum number of characters).

NOTE Sometimes, instead ofdata records with ji£1ds, we speak of rows and columns.
The meaning is the same.

5
Chapter 1

The description of a database consisting of several tables with all of its fields,
relations, and indexes (see below) is called a database modeL This model defines the
construction of the data structures and at the same time provides the format in which
the actual data are to be stored.
Tables usually contain their data in no particular order (more precisely, the order
is usually that in which the data have been entered or modified). However, for efficient
use of the data it is necessary that from these unordered data a list can be created that
is ordered according to one or more criteria. It is frequently useful for such a list to
contain only a selection of the data in the table. For example, one could obtain a list of
all of one's customers, ordered by ZIP code, who have ordered a rubber ducky within
the past twelve months.
To create such a list, one formulates queries. The result of the query is again a
table; however, it is one that exists in active memory (RAM) and not on the hard drive.
To formulate a query one uses SQL instructions, which are commands for
selecting and extracting data. The abbreviation SQL stands for Structured Query
Language, which has become a standard in the formulation of database queries.
Needless to say, every producer of a database system offers certain extensions to this
standard, which dilutes the goal of compatibility among various database systems.
When tables get large, the speed at which a query can be answered depends
significantly on whether there is a suitable index giving the order of the data fields.
An index is an auxiliary table that contains only information about the order of the
records. An index is also called a key.
An index speeds up access to data, but it has disadvantages as well. First, every
index increases the amount of storage on the hard drive necessary for the database file,
and second, the index must be updated each time the data are altered, and this costs
time. (Thus an index saves time in the reading of data, but it costs time in entering
and altering data. It thus depends on the use to which the data are to be put whether
an index is on the whole a net plus or minus in the quest for efficiency.)
A special case of an index is a primary index, or primary key, which is distinguished
in that the primary index must ensure a unique reference to a record. Often, for this
purpose one simply uses a running index number (lD number). Primary indexes
playa significant role in relational databases, and they can speed up access to data
considerably.

MySQL
MySQL is a relational database system. If you can believe many diehard MySQL fans,
MySQL is faster, more reliable, and cheaper-or, simply put, better-than any other
database system (including commercial systems such as Oracle and DB2). Many
MySQL opponents continue to challenge this viewpoint, going even so far as to assert
that MySQL is not even a relational database system. We can safely say that there is a
large bandwidth of opinion.
• The fact is that there is an ever increasing number of MySQL users, and the
overwhelming majority of them are quite satisfied with MySQL. Thus for these
users we may say that MySQL is good enough.

6
What Is MySQL?

• It is also the fact, however, that MySQL lacks a number of features that are taken
for granted with other database systems. If you require such features, then
MySQL is (at least for the present) not the database system for you. MySQL is
not a panacea.
In this chapter we shall examine some of the possibilities and limitations of
MySQL.

REMARK In this book we are considering MySQL Do not confuse MySQL with mSQL
(MiniSQL). To be sure, MySQL and mSQL have similar programming interfaces
(APIs), which merely facilitates the confusion between the two. However, the
underlying database systems are completely different. More information on mSQL
can be found at http://WtM.hughes.com.au/

Features of MySQL
The following list shows the most important properties of MySQL. This section is
directed to the reader who already has some knowledge of relational databases.
We will use some terminology from the relational database world without defining
our terms exactly. On the other hand, the explanations should make it possible for
database novices to understand to some extent what we are talking about.
• Relational Database System: Like almost all other database systems on the
market, MySQL is a relational database system.
• Client/Server Architecture: MySQL is a client/server system. There is a
database server (MySQL) and arbitrarily many clients (application programs),
which communicate with the server; that is, they query data, save changes, etc.
The clients can run on the same computer as the server or on another computer
(communication via a local network or the Internet).
Almost all of the familiar large database systems (Oracle, Microsoft SQL Server,
etc.) are client/ server systems. These are in contrast to the file-server systems,
which include Microsoft Access, dBase, and FoxPro. The decisive drawback to
file-server systems is that when run over a network, they become extremely
inefficient as the number of users grows.
• SQL compatibility: MySQL supports as its database language-as its name
suggests-SQL (Structured Query Language). SQL is a standardized language
for querying and updating data and for the administration of a database.
There are several SQL dialects (about as many as there are database systems).
MySQL adheres to the ANSI-SQLl92 standard, although with significant
restrictions and many a number of extensions.
This topic will be dealt with more extensively later. Beyond the ANSI-SQLl92
standard, MySQL supports, among other things, several additional data types,
full-text indexes, and replication.
• User Interface: There are a number of convenient user interfaces for
administering a MySQL server.

7
Chapter 1

• Full-text search: Full-text search simplifies and accelerates the search for words
that are located within a text field. If you employ MySQL for storing text (such
as in an Internet discussion group), you can use full-text search to implement
simply an efficient search function.

• RepUcation: Replication allows the contents of a database to be copied


(replicated) onto a number of computers. In practice, this is done for two
reasons: to increase protection against system failure (so that if one computer
goes down, another can be put into service) and to improve the speed of
database queries.

• Tnmsact1ons: In the context of a database system, a transaction means the


execution of several database operations as a block. The database system
ensures that either all of the operations are correctly executed or none of
them. This holds even if in the middle of a transaction there is a power failure,
the computer crashes, or some other disaster occurs. Thus, for example, it
cannot occur that a sum of money is withdrawn from account A but fails to be
deposited in account B due to some type of system error.
Transactions also give programmers the possibility of interrupting a series of
already executed commands (a sort of revocation). In many situations this leads
to a considerable simplification of the programming process.
In spite of popular opinion, MySQL has supported transactions for a long time.
One should note here that MySQL can store tables in a variety of formats.
The default table format is called MyISAM, and this format does not support
transactions. But there are a number of additional formats that do support
transactions. The most popular of these is InnoDB, which will be described in
its own chapter.
• Foreign key constraints: These are rules that ensure that there are no cross
references in linked tables that lead to nowhere. MySQL supports foreign key
constraints for InnoDB tables.
• Programming languages: There are quite a number of APIs (application
programming interfaces) and libraries for the development of MySQL
applications. For client programming you can use, among others, the languages
C, C++, Java, Perl, PHp, Python, and Tel.

• OnBC: MySQL supports the ODBC interface Connector/ODBC. This allows


MySQL to be addressed by all the usual programming languages. that run under
Microsoft Wmdows (Delphi, Visual Basic, etc.). The ODBC interface can also be
implemented under Unix, though that is seldom necessary.
Wmdows programmers who have migrated to Microsoft's new .NET platform
can, if they wish, use the ODBC provider or special MySQL providers for .NET.
• Platform independence: It is not only client applications that run under a
variety of operating systems; MySQL itself (that is, the server) can be executed
under a number of operating systems. The most important are Apple Macintosh
OS X, Linux, Microsoft Wmdows, and the countless Unix variants, such as AIX,
BSm, FreeBSD, HP- ux, OpenBSD, Net BSD, SGI Iris, and Sun Solaris.

8
Exploring the Variety of Random
Documents with Different Content
MONG the early Christians the sincerest
respect for the memory of their dead was
paid; for most of them, in the first centuries
of the Church, were either martyrs or near
connections of such as had suffered for the
faith. The Catacombs are covered with
inscriptions recording the deaths of martyrs;
and many of these memorials are
exceedingly pathetic, testifying to the fortitude with which the first
Christians endured any manner of torture rather than deny the new
faith which had been imparted to them by Divine revelation. The
remains of the martyrs, however mangled they might be, were
gathered together with the greatest reverence, and their blood
placed in little phials of glass, which were considered relics of a most
precious nature. The Catacombs, which served the first Christians as
churches as well as places of burial, are called after the most
distinguished martyrs who were buried therein. In that of St.
Calixtus, for instance—where that early and martyred Pope was
interred—about two centuries ago was found the body of Saint
Cecilia, "the sweet patroness of music." With such precaution had
her remains been transported to their place of interment, that
Bernini, the most eminent sculptor of the 17th Century, was able to
take a cast of them, which he subsequently worked into a lovely
statue, representing the saint in the graceful and modest attitude in
which it is said her body was found after the lapse of a thousand
years. This exquisite work of art is to be seen in the church which
bears Saint Cecilia's name, in the Trastevere; and a fine replica of it
is in the chapel of St. Cecilia, in the Oratory, Brompton.
Fig. 8.—Divine Service in the Catacombs of St. Calixtus, A.D. 50.

The Catacombs are subterraneous chambers and passages usually


formed in the rock, which is soft and easily excavated, and are to be
found in almost every country in which such rocks exist. In most
cases, probably, they originated in mere quarries, which afterwards
came to be used either as places of sepulchre for the dead, or as
hiding-places for the persecuted living. The most celebrated
Catacombs in existence are those on the Via Appia, at a short
distance from Rome. To these dreary crypts the early Christians were
in the habit of retiring, in order to celebrate Divine worship in times
of persecution, and in them were buried many of the saints, the
early Popes, and martyrs. They consist of long narrow galleries,
usually about eight feet high and five wide, which twist and turn in
all directions. The graves were constructed by hollowing out a
portion of the rock, at the side of the gallery, large enough to
contain the body. The entrance was then built up with stones, on
which usually the letters D. M. (Deo Maximo), or ΧΡ, the first two
letters of the Greek name of Christ, were inscribed. Though latterly
devoted to purposes of Christian interment exclusively, it is believed
that the Catacombs were at one time used as burying-places for
Pagans also, and there are one or two which were evidently entirely
devoted to the Jews. At irregular intervals, these galleries expand
into wide and lofty vaulted chambers, in which the service of the
Church was no doubt celebrated, and which still have the
appearance of chapels. The original extent of the Catacombs is
uncertain, the guides maintaining that they have a length of twenty
miles, whereas about six only can now be ascertained to exist, and
of these, many portions have either fallen in or become dangerous.
When Rome was besieged by the Lombards in the 8th Century,
several of the Catacombs were destroyed, and the Popes afterwards
caused the remains of many of the saints and martyrs to be
removed and buried in the churches. The Catacombs at Naples, cut
into the Capo di Monte, resemble those at Rome, and evidently were
used for the same purposes, being partially covered with remarkable
Christian symbols. At Palermo and Syracuse, there are similar
Catacombs, and they are also to be found in Greece, Asia Minor,
Syria, Persia, and Egypt. At Milo, one of the Cyclades, there is a hill
which is honeycombed with a labyrinth of tombs running in every
direction. In these, bassorilievi and figures in terra-cotta have been
found, which prove them to be long anterior to the Christian era. In
Peru and other parts of South America, ancient Catacombs still exist.
The Catacombs of Paris are a species of charnel-house, into which
the contents of such burying-places as were found to be pestilential,
and the bodies of some of the victims of the Revolution, were cast
by a decree of the Government. The skulls are arranged in curious
forms, and a visit to these weird galleries is one of the sights of
Paris, which few strangers, however, are privileged to study. The
Capuchin monks have frequently attached to their monasteries, a
cloister filled with earth brought from the Holy Land. In this the
monks are buried for a time, until their bones are quite fleshless,
when they are arranged in surprising groups in the long corridors of
a series of galleries, and produce sometimes the reverse of a solemn
effect.

Fig. 9.—Crypt of a Chapel in the Catacomb of St. Agnes, without the walls of Rome
(restored), showing the manner in which the bodies of the early Christians were arranged
one above the other. The front of each tomb was of course walled up.—From the work on
the Catacombs of Rome, by M. Perret.
Fig. 10.—An Anglo-Saxon Widow Lady. The upper garment is of black cloth, edged with fur,
and a veil of black gauze hangs from the head.—9th Century MS., National Library, Paris.
S the Church emerged from the Catacombs, and was
enabled to take her position in the world, her funereal
ceremonies became more elaborate and costly. Masses
for the dead were offered up in the churches, to the
accompaniment of music and singing; and the funereal
ceremonies which attended the burial of the Empress Theodolinda,
A.D. 595, the friend and correspondent of Pope St. Gregory the Great,
lasted for over a week. The Cathedral of Monza, where she was
buried, was hung with costly black stuff, and the body of the
Empress was exhibited under a magnificent catafalque, surrounded
with lights, and was visited by pilgrims from all parts of Lombardy.
Many hundreds of masses were said for her in all the churches, and
all day the great bells of the cathedral and of the various monastic
establishments tolled dolefully. At the end of the week the body of
the illustrious Empress was placed in the vault under the high altar,
where it remains to this day; and above it was a shrine filled with
extraordinary relics, many of which still subsist, as, for instance, her
celebrated "Hen and Chickens"—a plateau or tray of silver gilt with
some gold chickens with ruby eyes upon it—and the famous iron
crown, which is, indeed, of gold, having one of the nails said to have
been used at the Crucifixion beaten in a single band round the
inside. Napoleon I. crowned himself, at Milan, King of Italy, with this
singular relic.
Fig. 11.—An Anglo-Saxon Priest wearing a black Dalmatic, edged with fur, ready to say a
Requiem Mass.—From an early MS., 10th Century.

Our Catholic ancestors spent large sums of money upon their


funerals. The pious practice of praying for the dead, which they
doubtless derived from the Hebrews, induced them to secure the
future exertions of their friends, by building chanteries and special
chapels in the churches, with a view of reminding the survivors of
their demise. Guilds, which by the way, still exist, were created for
the purpose of binding people together in a holy league of prayer for
the souls of the faithful departed. We find in the laws established for
the Guild of Abbotsbury, the following regulations:—"If any one
belonging to the association chance to die, each member shall pay a
penny for the good of the soul, before the body be laid in the grave.
If he die in the neighbourhood, the steward (secretary) shall enquire
when he is to be interred, and shall summon as many members as
he can, to assemble and carry the corpse in as honourable a manner
as possible to the grave or minster, and there pray devoutly for his
soul's rest." With the same view, our ancestors were ever anxious to
obtain a place of sepulchre in the most frequented churches. The
monuments raised over their remains, whilst keeping them safe from
profanation, recalled them to memory, and solicited on their behalf
the charity of the faithful. The usual inscription on the earlier
Christian tombs in this country was the pathetic "Of your charity,
pray for me." In the Guild of All Souls, in London, when any member
died, it was the custom of the survivors to give the poor a loaf for
the good of the soul; and the writer can perfectly remember, that
some thirty years since, in remote parts of Norfolk, when anybody
died, it was the fashion to distribute loaves of bread in the church
porch as a dole. The funeral of an Anglo-Saxon was thus conducted:
—The body of the deceased was placed on a bier or in a hearse. On
it lay the book of the gospels, the code of his or her belief, and the
cross, the signal of hope. A pall of silk or linen was thrown over it till
it reached the place of interment. The friends were summoned, and
strangers deemed it a duty to join the funeral procession. The clergy
walked before or on each side, bearing lighted tapers in their hands,
and chanting a portion of the psalter. If it were in the evening, the
night was passed in exercises of devotion. In the morning, mass was
sung and the body deposited with solemnity in the grave, the
sawlshot paid, and a liberal donation distributed to the poor. Before
the Reformation, it was the excellent custom for all persons who met
a funeral to uncover and stand reverentially still until it had passed.
The pious turned back, and accompanied the mourners a part of the
way to the grave. It is pleasant to notice that this essentially
humane habit of taking off the hat and behaving gravely as a funeral
goes by, which is universal upon the Continent, is at last becoming
more and more general here. The homage of the living to the mortal
remains of even the humblest is excellent, and one which should be
earnestly encouraged, being far more beneficial in its results than
the heaping of costly flowers upon a hearse, which no one notices as
it passes, laden with its ephemeral offerings, to the cemetery.

Fig. 12.—Funeral of St. Edward the Confessor, January 5th, 1066. The body, covered with a
silken pall adorned with crosses, is carried by eight men, and followed by many priests,
to Westminster Abbey, which he had founded. Under the bier are seen two small figures
ringing bells.—From the Bayeux Tapestry, worked by Matilda of Flanders, Queen of
William the Conqueror, and preserved in the Cathedral at Bayeux—11th Century.

The funeral of Edward the Confessor was exceedingly magnificent,


and the shrine built over his relics, behind the high altar of the
glorious abbey which he founded, is still an object of reverence with
our Roman Catholic fellow-citizens, who, on St. Edward's Day, are
permitted by a tolerant age to offer their devotions before the
resting-place of the last of our Saxon Kings. But our first Norman
King was buried with scant ceremony. He died 1087, at
Hermentrude, a village near Rouen, having been taken suddenly ill
on his way to England. No sooner was the illustrious king deceased,
than his servants plundered the house and even the corpse, flinging
it naked upon the floor. Herleadin, a peasant, undertook at last to
convey the body to Caen, where it was to be buried in the Abbey of
St. Stephen, Prince Henry and the monks being present. Scarcely,
however, was the mass of requiem begun, when the church took
fire, and everybody fled, leaving William the Conqueror's hearse
neglected in the centre of the transept. At last the flames were
extinguished, the interrupted service finished, and the funeral
sermon preached. Just, however, as the coffin was about to be
lowered into the vault, Anselm Fitz-Arthur, a Norman gentleman,
stood forth and forbade the interment. "This spot," cried he, "is the
site of my father's house, which this dead man burnt to ashes. On
the ground it occupied I built this church, and William's body shall
not desecrate it." After much ado, however, Fitz-Arthur was prevailed
upon by Prince Henry to allow the body to be buried, on the
payment of sixty shillings as the price of the grave. In the 17th
Century the Calvinists ravaged the tomb and broke the monument.
It was restored in 1642, but finally swept away, together with that of
Queen Matilda, in the Revolution of 1793.
Fig. 13.—The Shrine of the Confessor, in Westminster Abbey.
Fig. 14.—Funeral of an Abbess—10th Century.—From a MS.

ERHAPS the most curious funeral on record occurred


just at the dawn of the Renaissance—that of the ill-fated
Inez de Castro—"the Queen crowned after death"—who
was murdered in the 14th Century by three assassins in
her own apartment at Coimbra. "Being conveyed," says
the Chronicle of Fray Jao das Reglas, "to the chapel of the
neighbouring convent, her body was arrayed in spotless white and
decked with roses. The nuns surrounded the bier, and the Queen-
mother of Portugal, Brittes, sat in state—her crown upon her head
and her royal robes flowing around her—as chief mourner, having
given an order that the body should not be buried until after the
return of her son Don Pedro. When he did come back, he was
transported with grief and anger at the foul murder of his consort;
and, throwing himself upon the corpse, clasped it to his heart,
covered its pale lips, its hands, its feet with kisses, and, refusing all
consolation, remained for thirty hours with the body clasped in his
embrace! At last, being overcome with fatigue, the unhappy Prince
was carried away senseless from the piteous remains of his most
dear Inez, and they were consigned to the grave. It was his father
who had instigated the murderers to commit their foul deed, and
this determined Pedro to take up arms against him; and Portugal
was desolated by civil war. Eventually the reasoning of the Queen
(Brittes) prevailed, and peace was restored. Pedro, however, never
spoke to his father again until the hour of his death, when he
forgave the great wrong he had done him. He now ascended the
throne, and his first act was to hunt down the three murderers, two
of whom were put to death, with tortures too awful to describe, and
the other escaped into France, where he died a beggar. After this
retributive act, Don Pedro assembled the Cortes at Cantandes, and,
in the presence of the Pope's Nuncio, solemnly swore that he had
secretly married Inez de Castro at Braganza, in the presence of the
bishop and of other witnesses." "Then occurred an event unique in
history," continues this naive contemporary chronicle. "The body of
Inez was lifted from the grave, placed on a magnificent throne, and
crowned Queen of Portugal. The clergy, the nobility, and the people
did homage to her corpse, and kissed the bones of her hands. There
sat the dead Queen, with her yellow hair hanging like a veil round
her ghastly form. One fleshless hand held the sceptre, and the other
the orb of royalty. At night, after the coronation ceremony, a
procession was formed of all the clergy and nobility, the religious
orders and confraternities—which extended over many miles—each
person holding a flaring torch in his hand, and thus walked from
Coimbra to Alcobaça, escorting the crowned corpse to that royal
abbey for interment. The dead Queen lay in her rich robes upon a
chariot drawn by black mules and lighted up by hundreds of lights."
Fig. 15.—Bird's-eye view of the Monument (restored) of the Queen Inez of Castro, Abbey of
Alcobaça, Portugal.

The scene must indeed have been a weird one. The sable costumes
of the bishops and priests, the incense issuing from innumerable
censers, the friars in their quaint garments, and the fantastically-
attired members of the various hermandades, or brotherhoods—
some of whom were dressed from head to foot entirely in scarlet, or
blue, or black, or in white—with their countenances masked and
their eyes glittering through small openings in their cowls; but above
all, the spectre-like corpse of the Queen, on its car, and the grief-
stricken King, who led the train—when seen by the flickering light of
countless torches, with its solemn dirge music, passing through
many a mile of open country in the midnight hours—was a vision so
unreal that the chronicler describes it as "rather a phantasmagoria
than a reality." In the magnificent abbey of Alcobaça the requiem
mass was sung, and the corpse finally laid to rest.
The monument still exists, with the statue, with its royal diadem and
mantle, lying thereon. The tomb of Don Pedro is placed foot to foot
with that of Inez, so—the legend runs—that at the Judgment Day
they may rise together and stand face to face.
In 1810 the bodies of Don Pedro I. and Dona Inez de Castro were
disturbed by the French, at the sack of Alcobaça. The skeleton of
Inez was discovered to be in a singular state of preservation—the
hair exceedingly long and glossy, and the head bound with a golden
crown set with jewels of price. Singularly enough, this crown,
although very valuable, was kicked about by the men as a toy and
thrown behind the high altar, whence, as soon as the troops
evacuated the monastery, it was carefully taken and laid aside by the
Abbot. Shortly afterwards it again encircled the unhappy Queen's
head, when, by order of the Duke of Wellington, the remains were
once more replaced in the tomb, with military honours.
Fig. 16.—Funeral Service, in which are shown the Candelabra and Incense Vessels which
were deposited in the coffin.—Drawing of the 14th Century—Collection of the Rev. Father
Cochet.
Fig. 17.—Angels praying over a Skull.—Bas-relief of 16th Century.

UNERAL services of great magnificence entered largely


into the customs of this pageantic epoch; and to this
day, in Catholic countries, no religious ceremonies are
conducted with more pomp than those intended to
commemorate the departed. Besides the religious
orders, there were numerous confraternities, guilds, and
brotherhoods devoted to the burying and praying for the deceased.
As no newspapers existed in those days, when a person of
distinction died, the "Death Crier,"—in some parts of England called
the "Death Watch,"—dressed in black, with a death's-head and
cross-bones painted on the back and front of his gown, and armed
with a bell, went the round of the town or village, as the case might
be, shouting "Of your charity, good people, pray for the soul of our
dear brother, [or sister] who departed this life at such and such an
hour." Upon this the windows and doors of the houses were opened,
and the "good people" said an ave or a pater for the "rest" of the
dead, and at the same time the passing bell was tolled. In London,
when the King or Queen died, the crier, or "Death Watch," who
paraded our principal thoroughfares was, of course, a very important
personage. Attended by the whole brotherhood, or guild, of the Holy
Souls, with cross-bearer, each carrying a lighted candle, he
proceeded processionally through the streets, notably up and down
Cheapside and the Strand, solemnly ringing his bell, and crying out
in a lugubrious voice his sad news. These criers, both in England and
France, were paid, as officials, by the civic corporation so much per
day, and were obliged, in addition to their usual mournful
occupation, to inspect and report on the condition of low taverns
and places of ill-fame. In the course of time they added to their "cry"
news of a more miscellaneous character, and after the Reformation,
became, we may well imagine, those rather musty folks the "Watch,"
who only disappeared from our midst as late as the early half of this
century.
Figs. 18 & 19.—Death Criers—French costumes of 17th Century. The English dress was
almost identical.—From a rare print in the collection of Mr. Richard Davey. Engraved
expressly for this publication.
Fig. 20.—Pall from the Church of Folleville, France, now in the Museum at Amiens. It is of
black velvet, with stripes of white silk let in, embroidered with black and gold thread. It
was placed over the coffin. Similar palls existed in England, and one or two are still
preserved in our national collections.
Fig. 21.—Scene from Richard III.—The body of Henry VI. being by chance met by Richard
on its way to Chertsey, he orders the bearers to set it down, and then pleads his cause to
the Lady Anne.

Shakespeare, whose knowledge of Catholicism of course came to


him from immediate tradition, possibly remembered a very ancient
custom when, in Richard III., he makes the Duke of Glo'ster
command the attendants who follow the body of Henry VI. to set it
down,—an order which they obey reluctantly enough,—thereby
giving him an opportunity to make love to Lady Anne in the presence
of her murdered father-in-law's remains. In Catholic times the
streets were adorned not only by many fine crosses, such as those
at Charing and Cheapside, but also by numerous chapels and
wayside shrines. Funerals, when they passed these, were in the
habit of stopping, and the assistants, kneeling, prayed for the dead
person whom they were carrying to the grave. They likewise
stopped, also, and very frequently too, at certain well-known public-
houses or taverns, the members of the family of the deceased being
obliged by custom to "wet the lips" of the "thirsty souls" who carried
the corpse. Sometimes very disorderly scenes ensued. The hired
mourners and more unruly members of the guilds got drunk; and it
is on record that on more than one occasion the body was pulled out
of its coffin by these rascals and outraged, to the horror and
indignation of honest people. It has frequently occurred to the
writer, that if the attendants in the curious scene in the tragedy just
mentioned, were to convey the body of the dead King to the side or
back of the stage, in front of some shrine or cross, and occupy
themselves with prayer, they would render the astonishing dialogue
between Glo'ster and Lady Anne much more intelligible than when
we hear it spoken, as is usually the case, before a number of
persons for whose ears it was certainly never intended.
Fig. 22.—Funeral of King Richard II., showing his waxen effigy.—From an early MS. of
Froissart.

MPORTANT personages in olden times in this country


were usually embalmed. The poor, on the contrary, were
rarely furnished even with a decent coffin, but were
carried to the grave in a hired one, which, in villages,
often did duty for many successive years. Once the brief
service was said, the pauper's body, in its winding-
sheet, was placed reverently enough in the earth, and
covered up—a fact which doubtless accounts for the
numerous village legends of ghosts wandering about in
winding-sheets. Charitable people paid for masses to be said by the
friars for their poorer brethren, and the guilds paid all expenses of
the funeral, which were naturally not very considerable. On the other
hand, the funeral of great personages, from king to squire, was a
function which sometimes lasted a week. The bell tolled—as it still
does—the moment the death became known to the bell-ringer. Then
the body was washed, embalmed with spices and sweet herbs,
wrapped in a winding-sheet of fine linen,—which, by the way, was
often included among the wedding presents—and taken down into
the hall of the palace or manor, which was hung with black, and
lighted by many tapers, and even by waxen torches—sometimes as
many as 300 and 400 of them—an immense expense, considering
the cost of wax in those days. After three days' exposition—if the
body remained incorrupt so long—the corpse was sealed up in a
leaden coffin, and taken to the church, where solemn masses were
sung. The clothes—we may presume the old and well-worn ones
only—were then formally distributed to the poor of the parish. Finally
came the funeral banquet of "baked meats," to which all those,
including the clergy, who had taken part in the funeral service and
procession were invited.
When the Sovereign or any person of royal rank deceased, a waxen
presentment was immediately made of him as he was seen in life
under the influence of sleep. This figure, dressed in the regal robes,
was exposed upon the catafalque in the church, instead of the real
body—a custom doubtless inspired originally by hygienic motives, for
frequently the funeral rites of a king or prince of the blood were
prolonged for many days. In Westminster Abbey there are still
several of these grim ancient waxen effigies to be seen, by special
permission of the Dean, very faded and ghastly, but interesting as
likenesses, and for the fragments which time has spared of their
once gorgeous attire. This custom lasted with us until the time of
William and Mary. In France it disappeared in the middle of the 17th
Century, the last mention of it being on the occasion of the death of
Anne of Austria; for we read in a curious letter from Guy Patin to his
friend Falconet, "The Queen-Mother died to-day [Jan. 21, 1666]. She
was immediately embalmed, and by noon her waxen effigy was on
view at the Louvre. Thousands are pressing in to see it."
Fig. 23.—Funeral Procession of King Henry V., A.D. 1422.
In France, so long as the wax effigy was exposed in the church or
palace, sometimes for three weeks, the service of the royal person's
table took place as usual. His or her chair of state was drawn up to
the table, the napkin, knife and fork, spoon and glass, were in their
usual places, and at the appointed time the dinner was served to the
household, and "the meats, drinks, and all other goodly things" were
offered before the dead prince's chair, as if he were still seated
therein. When, however, the coffin took the place in the church of
the wax figure, and the body was put into the grave, then the
banqueting-hall was hung with black, and for eight days no meals
were served in it of any kind.
Fig. 24.—Queen Katherine de Valois in her Widow's Dress, A.D. 1422. The costume is of
black brocade elaborately trimmed with black glass beads, and trimmed with white fur.—
MS. of the period.

We still possess some curious details concerning the funeral of Henry


V., who died at Vincennes in 1422. Juvenal des Usines tells us that
the body was boiled, so as to be converted into a perfect skeleton,
for better transportation into England. The bones were first taken to
Notre Dame, where a superb funeral service was said over them.
Just above the body they placed a figure made of boiled leather,
representing the king's person "as well as might be desired," clad in
purple, with the imperial diadem on its brow and the sceptre in its
hand. Thus adorned, the coffin and the effigy were placed on a
gorgeous chariot, covered with a "coverture" of red velvet beaten
with gold. In this manner, followed by the King of Scots, as chief
mourner, and by all the princes, lords, and knights of his house, was
the body of the illustrious hero of Agincourt conveyed from town to
town, until it reached Calais and was embarked for England, where it
was finally laid at rest in Westminster Abbey, under a new
monument erected by Queen Katherine de Valois, who eventually
caused a silver-plated effigy of her husband, with a solid silver gilt
head, to be placed on the tomb, which was unfortunately destroyed
at the time of the Reformation.
The funeral of Eleanor of Castile, the adored consort of Edward I.,
was exceptionally sumptuous. This amiable Queen died at Hardbey,
near Grantham, of "autumnal" fever, on November 29, 1290. The
pressing affairs of Scotland were obliterated for the time from the
mind of the great Edward, and he refused to attend to any state
duty until his "loved ladye" was laid at rest at Westminster. The
procession, followed by the King in the bitterest woe, took thirteen
days to reach London from Grantham. At the end of every stage the
royal bier surrounded by its attendants, rested in some central place
of a great town, till the neighbouring ecclesiastics came to meet it in
solemn procession, and to place it upon the high altar of the
principal church. A cross was erected in memory of King Edward's
chère reine at every one of these resting-places. Thirteen of these
monuments once existed; now only two of the originals remain, the
crosses of Northampton and Waltham. The fac-simile at Charing
Cross, opposite the Railway Station, though excellent, is of course
modern, and does not occupy the right spot, which was, it is said on
good authority, exactly where now stands the statue of Charles II.
The Chronicler of Dunstable thus describes the ceremony of marking
the sites for these crosses: "Her body passed through Dunstable and
rested one night, and two precious cloths were given us, and eighty
pounds of wax. And when the body of Queen Eleanor was departing
from Dunstable, her bier rested in the centre of the market-place till
the King's Chancellor and the great men there present had marked a
fitting place where they might afterwards erect, at the royal
expense, a cross of wonderful size,—our prior being present, who
sprinkled the spot with holy water."
Perhaps the most magnificent funeral which took place before the
Reformation was that of Elizabeth of York, consort of Henry VII. It
was one of the last great Roman Catholic state funerals in England,
for the obsequies of Henry VII. himself were conducted on a much
diminished scale; and those of the wives of Henry VIII., and of that
monster himself, were not accompanied by so much pomp, owing to
the religious troubles of the time. Queen Elizabeth of York was the
last English Queen who died at the Tower. Her obsequies took place
in the chapel of St. Mary, which was, until quite lately, the Rolls
Office, and which was magnificently hung on this occasion with black
brocade. The windows were veiled with crape. The Queen's body
rested on a bed of state, in a chapelle ardente, surrounded by over
5,000 wax candles. High Mass was said during the earlier hours of
the morning, and in the afternoon solemn Vespers were sung. When
the Queen's body was nailed up in its coffin, the usual waxen effigy
took its place. The procession left St. Mary's, in the Tower, at noon,
for Westminster Abbey, and was of exceeding length. At every
hundred yards it was met by the religious corporations, fraternities,
and guilds, and by the children attached to sundry monastic and
charitable foundations, some of them dressed as angels, with golden
wings, and all of them singing psalms. There were over 8,000 wax
tapers burning between Mark Lane and the Temple; and the fronts
of all the churches were hung with black, and brilliantly illuminated.
The people in the streets held candles, and repeated prayers. At
Temple Bar the body was received by the municipal officers of the
City of Westminster, who accompanied it to the Abbey, where the
Queen's effigy was exhibited with great state for two days, and on
the morning of the third she was buried in what is since known as
"Henry VII.'s Chapel."
Fig. 25.—Gentleman in Mourning, time of Henry VII. The costume is entirely black, edged
with black fur.—From a contemporary MS.

The funeral of the unfortunate Katherine of Arragon took place, as


all the world knows, in Peterborough Cathedral.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like