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

MySQL Learn MySQL the Quick and Easy Way 2nd edition Edition Ullman - Download the ebook today and own the complete content

The document provides information about various MySQL-related ebooks available for instant download at ebookgate.com. It includes titles such as 'Learn MySQL the Quick and Easy Way' and 'PHP and MySQL Web Development', along with links to each ebook. Additionally, it contains details about the Visual QuickStart Guide for MySQL by Larry Ullman, including its contents and publishing information.

Uploaded by

tamzokpaulla96
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)
13 views

MySQL Learn MySQL the Quick and Easy Way 2nd edition Edition Ullman - Download the ebook today and own the complete content

The document provides information about various MySQL-related ebooks available for instant download at ebookgate.com. It includes titles such as 'Learn MySQL the Quick and Easy Way' and 'PHP and MySQL Web Development', along with links to each ebook. Additionally, it contains details about the Visual QuickStart Guide for MySQL by Larry Ullman, including its contents and publishing information.

Uploaded by

tamzokpaulla96
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/ 76

Instant Ebook Access, One Click Away – Begin at ebookgate.

com

MySQL Learn MySQL the Quick and Easy Way 2nd


edition Edition Ullman

https://ebookgate.com/product/mysql-learn-mysql-the-quick-
and-easy-way-2nd-edition-edition-ullman/

OR CLICK BUTTON

DOWLOAD EBOOK

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


Click here to visit ebookgate.com and download ebook now
Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Teach Yourself VISUALLY Digital Video The Fast Easy Way To


Learn 2nd Edition Lonzell Watson

https://ebookgate.com/product/teach-yourself-visually-digital-video-
the-fast-easy-way-to-learn-2nd-edition-lonzell-watson/

ebookgate.com

MySQL 4th Edition Paul Dubois

https://ebookgate.com/product/mysql-4th-edition-paul-dubois/

ebookgate.com

PHP5 and MySQL bible Tim Converse

https://ebookgate.com/product/php5-and-mysql-bible-tim-converse/

ebookgate.com

MySQL PHP Database Applications 2nd ed Edition Brad Bulger

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

MySQL Phrasebook 1st edition Edition Greant

https://ebookgate.com/product/mysql-phrasebook-1st-edition-edition-
greant/

ebookgate.com

PHP and MySQL Web Development Luke Welling

https://ebookgate.com/product/php-and-mysql-web-development-luke-
welling/

ebookgate.com

MySQL Reference Manual 1st Edition Michael Widenius

https://ebookgate.com/product/mysql-reference-manual-1st-edition-
michael-widenius/

ebookgate.com

MySQL in a Nutshell 1st Edition Dyer

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)

Find us on the Web at: www.peachpit.com


To report errors, please send a note to: errata@peachpit.com
Peachpit Press is a division of Pearson Education.
Copyright © 2006 by Larry Ullman

Editor: Rebecca Gulick


Copy Editor: Robert Campbell
Technical Reviewer: Alexander Keremidarski
Proofreaders: Liz Welch and Alison Kelley
Production Coordinators: Pat Christenson and Becky Winter
Compositor: Owen Wolfson
Indexer: Karin Arrigoni
Cover Production: George Mattingly/GMD Design

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

Printed and bound in the United States of America


For Jessica, my one and only.
A lifetime supply of thanks to:
The wonderful people at Peachpit Press.
My sincerest thanks to everyone there (and
at Pearson) for their dedication to putting
out quality books, for giving me these oppor-
tunities to publish, and for everything else
they do. Specifically, I would like to thank
Nancy Aldrich-Ruenzel, Marjorie Baer, Kim
Lombardi, Gary-Paul Prince, and the other
two dozen people whose names and jobs I
may not know but should.
This book’s editor, Rebecca Gulick. My job
is easier and the book is better when I have
the pleasure of working with you. I am very
fortunate to have had that opportunity
once again.
Bob Campbell, for his spot-on copy editing
and attention to detail.
Pat Christenson, Production Coordinator
Extraordinaire, for turning a disparate
collection of text files and images into a
usable, physical book.
Owen Wolfson, Compositor, and Karin
Arrigoni, Indexer, for the work they do,
which I almost understand (but not quite).
The readers of my other books who took the
time to let me know how much they appre-
ciated them (even if they followed that up
with a support question) and for requesting
that I write a MySQL book. I hope it’s every-
thing you were looking for.
Finally (whew!), thanks to everyone in the
MySQL community—from those at MySQL
AB to the participants of the various mailing
lists. MySQL is yet another example of how
great open source technology can be! Special
thanks goes to Alexander Keremidarski, for
his time and excellent technical review. I feel
so much better having a person of your
knowledge review everything!
Table of Contents
Introduction ix
Chapter 1: Installing MySQL 1
General Installation Steps. . . . . . . . . . . . . . . . . . . . . . 2
Installing MySQL on Windows . . . . . . . . . . . . . . . . . 5
Configuring MySQL on Windows . . . . . . . . . . . . . . . 8
Installing MySQL on Macintosh . . . . . . . . . . . . . . . 10
Installing MySQL on Linux . . . . . . . . . . . . . . . . . . . 13
Basic Configuration Options . . . . . . . . . . . . . . . . . . 18

Table of Contents
Upgrading MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

Chapter 2: Running MySQL 23


Running MySQL on Windows and
Windows NT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Running MySQL on Mac OS X . . . . . . . . . . . . . . . . 33
Running MySQL on Linux and Unix . . . . . . . . . . . 36
Using mysqladmin . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Setting the Root User Password . . . . . . . . . . . . . . . 42
Using the mysql Client . . . . . . . . . . . . . . . . . . . . . . . 44
Users and Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . 48

Chapter 3: Database Design 57


Normalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Understanding Keys . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Understanding Relationships. . . . . . . . . . . . . . . . . . 61
First Normal Form . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Second Normal Form. . . . . . . . . . . . . . . . . . . . . . . . . 65
Third Normal Form . . . . . . . . . . . . . . . . . . . . . . . . . . 68

Chapter 4: Creating a MySQL Database 71


MySQL Data Types. . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Extra Column Characteristics . . . . . . . . . . . . . . . . . 77
Introduction to Indexes . . . . . . . . . . . . . . . . . . . . . . 80
Finalizing a Table’s Design . . . . . . . . . . . . . . . . . . . . 82
Choosing a Storage Engine. . . . . . . . . . . . . . . . . . . . 85
Character Sets and Collations . . . . . . . . . . . . . . . . . 88
Creating Databases. . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Creating Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Modifying Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98

v
Table of Contents

Chapter 5: Basic SQL 101


Using Values in Queries. . . . . . . . . . . . . . . . . . . . . . 102
Inserting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Selecting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Using Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Using LIKE and NOT LIKE . . . . . . . . . . . . . . . . . . 114
Performing Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Sorting Query Results . . . . . . . . . . . . . . . . . . . . . . . 123
Limiting Query Results . . . . . . . . . . . . . . . . . . . . . . 125
Updating Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Deleting Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

Chapter 6: MySQL Functions 133


Text Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Concatenation and Aliases. . . . . . . . . . . . . . . . . . . 137
Numeric Functions . . . . . . . . . . . . . . . . . . . . . . . . . 142
Table of Contents

Date and Time Functions . . . . . . . . . . . . . . . . . . . . 145


Formatting the Date and Time . . . . . . . . . . . . . . . 149
Encryption Functions . . . . . . . . . . . . . . . . . . . . . . . 151
Grouping Functions . . . . . . . . . . . . . . . . . . . . . . . . . 154
Other Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

Chapter 7: MySQL and PHP 161


Connecting to MySQL and Selecting
a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Executing Simple Queries. . . . . . . . . . . . . . . . . . . . 166
Retrieving Query Results . . . . . . . . . . . . . . . . . . . . 174
Using mysqli_insert_id(). . . . . . . . . . . . . . . . . . . . . 182
Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Security Considerations . . . . . . . . . . . . . . . . . . . . . 192

Chapter 8: MySQL and Perl 205


Installing Perl with MySQL Support
on Windows. . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Installing Perl Support for MySQL on
Unix and Mac OS X . . . . . . . . . . . . . . . . . . . . . 209
Testing Perl and MySQL . . . . . . . . . . . . . . . . . . . . . 211
Connecting to MySQL . . . . . . . . . . . . . . . . . . . . . . . 215
Retrieving Query Results . . . . . . . . . . . . . . . . . . . . 218
Executing Simple Queries. . . . . . . . . . . . . . . . . . . . 222
Retrieving the Insert ID. . . . . . . . . . . . . . . . . . . . . . 227
Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Security Considerations . . . . . . . . . . . . . . . . . . . . . 234
Using Prepared Statements . . . . . . . . . . . . . . . . . . 237

vi
Table of Contents

Chapter 9: MySQL and Java 243


Installing Java Support for MySQL . . . . . . . . . . . . 244
Connecting to the Database . . . . . . . . . . . . . . . . . 247
Executing Simple Queries. . . . . . . . . . . . . . . . . . . . 254
Retrieving Query Results . . . . . . . . . . . . . . . . . . . . 261
Retrieving the Insert ID. . . . . . . . . . . . . . . . . . . . . . 268
Using Prepared Statements . . . . . . . . . . . . . . . . . . 274

Chapter 10: Advanced SQL and MySQL 279


Performing Transactions. . . . . . . . . . . . . . . . . . . . . 280
Full-Text Searching. . . . . . . . . . . . . . . . . . . . . . . . . . 287
Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . 297
User-Defined Variables . . . . . . . . . . . . . . . . . . . . . . 300
Introducing Unions . . . . . . . . . . . . . . . . . . . . . . . . . 303

Chapter 11: MySQL 5 Features 309

Table of Contents
Stored Routines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Using OUT Parameters . . . . . . . . . . . . . . . . . . . . . . 330
Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338

Chapter 12: Techniques for Programming 345


Storing and Retrieving Binary Data . . . . . . . . . . . 346
Making Query Result Pages . . . . . . . . . . . . . . . . . . 364
Using Transactions with Perl . . . . . . . . . . . . . . . . . 378

Chapter 13: MySQL Administration 387


The MySQL Administrator. . . . . . . . . . . . . . . . . . . 388
Backing Up Databases. . . . . . . . . . . . . . . . . . . . . . . 392
Importing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
MySQL Logging. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
Database Maintenance . . . . . . . . . . . . . . . . . . . . . . 401
Improving Performance. . . . . . . . . . . . . . . . . . . . . . 405
Using Batch Files . . . . . . . . . . . . . . . . . . . . . . . . . . . 409

Appendix A: Troubleshooting 413


Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
Starting MySQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Accessing MySQL . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
mysql.sock Problems . . . . . . . . . . . . . . . . . . . . . . . . 418
Queries That Return Strange Results. . . . . . . . . . 420
Authentication Protocol Problems. . . . . . . . . . . . 421
Resetting the Root Password . . . . . . . . . . . . . . . . . 422

vii
Table of Contents

Appendix B: SQL and MySQL References 425


Basic SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
ALTER Commands . . . . . . . . . . . . . . . . . . . . . . . . . 428
SQL Clauses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
MySQL Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
MySQL Data Types. . . . . . . . . . . . . . . . . . . . . . . . . . 431
MySQL Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . 433
Other References. . . . . . . . . . . . . . . . . . . . . . . . . . . . 437

Appendix C: Resources 439


MySQL-Specific. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
Third-Party MySQL Applications . . . . . . . . . . . . . 442
SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
PHP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
Perl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
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?

files of data and the program itself.


MySQL is an open-source application, like PHP
and some variants of Unix, meaning that it
is free to run or even modify (the source code
itself is downloadable). There are occasions on
which you should pay for a MySQL license,
though, especially if you are making money
from the sales or incorporation of the MySQL
product. Check MySQL’s licensing policy for
more information on this. Any MySQL user
may also want to consider subscribing to
one of MySQL’s Network tiers.

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

The MySQL software consists of several


pieces, including the MySQL server (mysqld,
which runs and manages the databases), the
MySQL client (mysql, which gives you an inter-
face to the server, Figure i.2), and numerous
Figure i.2 You’ll commonly use the mysql client to
communicate with the MySQL server. utilities for maintenance and other purposes.
You can interface with MySQL using most
popular programming languages, including
PHP, Perl, and Java, all of which will be demon-
strated in this book. You can also use C#, C,
Ruby, C++, and others. Along with all of these
options, there are dozens of third-party appli-
cations for interacting with the MySQL
server such as phpMyAdmin (Figure i.3).
MySQL was written in C and C++, and it
functions equally well on several different
Figure i.3 The free, Web-based phpMyAdmin is one of operating systems. MySQL has been known
the best tools for working with your MySQL databases.
to handle databases as large as 60,000 tables
with more than five billion rows (yes, billion).

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

Primary MySQL Resources


Because MySQL is a free application, most
of your questions will need to be answered by
members of the MySQL mailing lists rather
than by MySQL AB itself. The company is,
however, available for contractual support,
consulting, and training, which you might
want to consider if you are using MySQL on
a larger scale or in a corporate environment.
MySQL has a solid online manual (Figure i.4),
which includes the occasional user-submitted
Figure i.4 The online version of the MySQL manual is comment. It’s searchable, thorough, and able
highly detailed and well organized. You can also to answer most of the questions you’ll come
download other versions for immediate access from
your computer. across. Also note that the MySQL manual is
available in several different versions, each

Primary MySQL Resources


matching a significant MySQL release. As you
look there for help, make sure that you’re
using the correct corresponding manual.
The MySQL mailing lists (http://lists.
mysql.com) are populated by users and the
MySQL people themselves, who are very
informative and responsive. You’ll also find
specific mailing lists dedicated to the data-
base on Windows and interacting with MySQL
from Java, among other topics. Because of
the popularity of the mailing lists, there are
currently no strong MySQL newsgroups
such as you might encounter with other
Figure i.5 MySQL’s forums are available for technologies.
troubleshooting or for extending your knowledge.
Finally, there are also the MySQL forums
(http://forums.mysql.com, Figure i.5). The
forums cover MySQL usage, third-party
applications, SQL, specific programming
languages, and so on.
For links to these and other MySQL refer-
ences, see Appendix C, “Resources.”

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

prompt on Windows (Figure i.7), a Linux


shell, or the Mac OS X Terminal (Figure i.8).
Lastly, the programming chapters covering
PHP, Perl, and Java—Chapters 7, 8, 9, and
12—will require a text editor, a Web browser,
and so forth. The specific requirements will Figure i.7 Windows has a command prompt (or DOS
prompt), which will be used in this book.
be discussed in the pertinent chapter.

Figure i.8 Mac OS X comes with the Terminal


application, which allows you to interact with the
computer on a command-line level.

xiv
Introduction

About This Book Is This Book for You?


In this book I explain the fundamentals This book was written for a wide range of
of MySQL, teaching the information that people within the beginner to intermediate
most MySQL users will require. In keeping range. Obviously, this book is for anyone
with the format of the Visual QuickStart wanting to use MySQL in some capacity,
series, the information is taught using a but I specifically had in mind three general
step-by-step approach with corresponding types of readers:
images. The demonstrations in the book
◆ Those who have never used any
will be geared toward specific knowledge as
database before
opposed to developing in-depth MySQL-
based applications (such as a programming ◆ Those who have used other databases
text might have). and want to know how MySQL specifi-
cally operates
Many of the examples in the book will

About This Book/Is This Book for You?


be executed from a command-line inter- ◆ Those who are currently using MySQL
face, although the three programming in a limited capacity and would like
chapters plus Chapter 12, “Techniques for to elevate their skills to a more profes-
Programming,” will function differently. In sional level
those chapters, I will go through writing the
I should note that I will not teach any
scripts in detail and then test them using
programming languages here but rather
the most applicable technique (be it a Web
demonstrate how to use those languages
browser or whatever).
with MySQL.
The structure of the book is fairly linear.
It begins with basic installation and admin-
istration of the software. After that, database
design and SQL—elements common to most
database applications—will be covered, fol-
lowed by some MySQL-specific functions.
The three programming chapters will come
next. The book concludes with newer and
more advanced features, some specific
database-application techniques, and how to
administer the MySQL server and databases.
The appendices discuss troubleshooting tech-
niques and provide a reference section along
with where to turn for more information.

xv
Introduction

Companion Web Site Questions, Comments, or


I have developed a companion Web site Suggestions?
specifically for this book, which you may
If you have any MySQL-specific questions,
reach at www.DMCinsights.com/mysql2.
you can turn to one of the many Web sites,
There you will find every script from this
mailing lists, and FAQ repositories already
book (for the programming chapters), text
in existence. Appendix C, “Resources,” lists
files containing lengthy SQL commands,
the most popular of these options. You can
and a list of errata that occurred during
also direct your questions, comments, and
publication. (If you have a problem with a
suggestions to me directly, via email, at:
command or script and are following the
mysql2@DMCinsights.com. I do try to
book exactly, check the errata to ensure
answer every email I receive, although there
there is not a printing error before driving
is no guarantee as to how quickly I will be
Web Site/Questions, Comments, Suggestions

yourself absolutely mad.) At this Web site you


able to do so. (Preference and more detailed
will also find useful Web links, a forum where
responses will be given to emails pertaining
readers can ask and answer each others’
to the content of this book; more prompt
questions (related to the material herein
and thoughtful replies with other issues are
or not), and more!
best sought through the mailing lists or the
book’s online reader forum.)

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

General Installation Steps


Before going through the actual installation
steps, there are some decisions to be made.
The first, and most important, two are:
◆ What version of MySQL to install
◆ What installation method to use
At the time of this writing, there are stable
releases available of MySQL 4.1 and 5.0,
while 5.1 is in its alpha stage (there are also
old releases still available of Versions 3.23
and 4.0). Generally I would recommend that
you download the current stable version,
which is marked as GA (Generally Available).
The latest version will have the most features
available (see the Introduction for a discus-
sion of this). The main reason to install an
older version of MySQL would be if you were
General Installation Steps

currently using a different version of MySQL


on another computer and wanted to ensure
cross-computer consistency with the least
amount of effort.
As for the installation method, MySQL is
available in a precompiled binary format or MySQL Naming Scheme
as the raw source code. If a binary is avail- When you go to download MySQL, you’ll
able for your platform, you’ll want to go with notice that files have their own naming
that unless you need to configure the instal- conventions. For example, a release may
lation (if, for instance, you need to change be called mysql-5.0.18. The first number
the default location or add support for other indicates the major version. The second
features). The binaries are also available in number is the release level. The combina-
two formats: Standard (also called Windows tion of these two numbers is the release
Essentials as a Windows download) and Max series, which is the most important thing
(or just plain Windows as a Windows down- to remember (4.0, 4.1, 5.0, 5.1, etc.). The
load). The former is smaller and should run third number is the version number within
faster. The latter has extra features enabled. the release series.
Non-production versions will be followed
with -alpha, -beta, or -rc (for release can-
didate, which is almost production caliber).
I would advise that you avoid these. Finally,
if you download the complete binary pack-
age, it may also have the word max added
to the name.

2
Installing MySQL

Before going into the operating-system-


specific installation instructions, here is a
preview of the general installation steps.
To install MySQL:
1. Confirm that your operating system is
supported.
MySQL is available for a long list of plat-
forms, so it’s a safe bet that you can use
it. That being said, it’s always best to
check prior to going through all of the
effort. MySQL will run on Windows 9.x,
Me, NT, 2000, 2003, and XP; Mac OS X;
and several variants of Unix and Linux.
The full list of supported operating
systems appears in the MySQL manual;
see section 2.1.1, “Operating Systems
Supported by MySQL” (Figure 1.1).
2. Select the release series of MySQL

General Installation Steps


you’ll want.
This is where you’ll most likely decide
to install the most current Generally
Available release. MySQL still updates
older releases as warranted by bug or
security fixes, but you should probably
install the current, stable version.
continues on next page

Figure 1.1 MySQL runs on the vast majority of available operating systems.

3
Chapter 1

3. Select the distribution format. ✔ Tips


Unless you know you need to create a
■ Use only the latest Generally Available
custom installation, opt for a binary ver-
release for mission-critical tasks. The
sion, if one is available for your operating
non-stable releases are for the curious,
system. As to the choice between the
the bug testers, and those with nothing
Standard and Max versions, I leave that
serious to lose.
up to you. It’s really a matter of whether
you want a smaller size and faster speed ■ The MySQL manual is available in differ-
or all of the enabled features. ent versions, each corresponding to a
MySQL release series. When using the
4. Download the software.
manual, check that it corresponds to
Just click the link and follow the prompts the version of MySQL you have.
to get MySQL. There is a form you can
optionally fill out to give the MySQL
company some information, or you can
click the No thanks… message to just get
the software. You’ll probably have to
download the software from a mirror site
at the end.
General Installation Steps

5. Make sure you do not have an existing


version of MySQL running.
If you already have a version of MySQL Verifying the Checksum
installed and running, see the “Upgrading
For the truly security-conscious, an
MySQL” section later in this chapter prior
optional step you can take is to verify the
to doing anything else.
downloaded software to make sure you
6. Install the downloaded software. don’t have a Trojan horse (a malicious
This step will vary the most, as it depends piece of code disguised as something
upon what operating system you are using else). There are a couple of ways to do
and whether you selected a precompiled this, starting by verifying the checksum.
binary version or the source code version A checksum is an MD5 representation of
in Step 3. The following sections of this data. So the checksum for the download-
chapter will focus on this part of the able file should be unique to that down-
overall process. load. If what you actually download has a
different checksum, it’s probably been
7. Set up and start MySQL. tampered with.
Some of the setup will be covered in this
chapter, and then Chapter 2, “Running Alternatively, you can use GnuPG, the
MySQL,” will take over from there. GNU Privacy Guard, or (on Linux) RPM’s
built-in verification mechanism. I don’t
show or discuss any of these here, but the
MySQL manual has instructions for using
these tools, as well as where they can be
obtained. See the “Installing MySQL” sec-
tion for specifics.

4
Installing MySQL

Table 1.1 After installing MySQL, you’ll have these


folders (all found within the main MySQL folder). Installing MySQL
MySQL Layout on Windows on Windows
Subfolder Contains MySQL will run on most Windows operating
bin All applications systems (specifically those that are at least
data Databases and logs 32-bit, such as Windows 95, 98, Me, NT, 2000,
docs Documentation and XP). If you’re using an NT OS such as
examples Sample programs and scripts Windows NT, 2000, or XP (either the Home
include Header files or Professional version), you can run MySQL
lib Code libraries as a service, as I’ll demonstrate in the next
scripts Useful scripts chapter. For my example here, I’ll be installing
share Error message files the latest stable release of MySQL on Windows
sql-bench Benchmark utilities XP Professional.
There are two primary ways of installing the
MySQL software on a Windows operating
system: using a precompiled distribution or
compiling your own binary from the MySQL
source files. The former approach is signifi-

Installing MySQL on Windows


cantly easier than the latter and will be the
technique I use here. When you get to the
MySQL downloads page, you’ll see three items
listed for Windows: Windows Essentials, which
is the Standard binary; just Windows, which is
the Max version; and, Without Installer, which
is the source code. The first is the smallest
and will work for most people. The second
has all the extra bells and whistles.
Once complete, MySQL will be installed in
C:\Program Files\MySQL\MySQL Server x.x,
where x.x represents the release series
installed. This is true as of MySQL 5.0. Prior
to that, MySQL was installed in C:\mysql, by
default. In either case, Table 1.1 indicates
the resulting layout of folders.
Finally, I’ll point out that these instructions
are correct as of the writing of this book.
MySQL has frequently changed the installa-
tion process over the years. One release may
have an entirely different installation process
and result from the next. If you have a prob-
lem with these instructions, check the version
of the manual that matches the MySQL ver-
sion you are installing.

5
Chapter 1

To install MySQL on Windows:


1. Download the Zip file from the MySQL
Web site.
Start by pointing your browser to
http://dev.mysql.com/downloads. Then
Figure 1.2 Choose between the Essentials or the
complete version of MySQL.
click the name of the version you’ll want.
As of the time of this writing, the most
current stable release of MySQL is ver-
sion 5.0.18.
On the next page, you’ll be able to choose
which distribution you want (Figure 1.2).
MySQL recommends the Windows
Essentials, but I’d recommend the full
version (called just Windows) if you want
to learn it all.
2. Unzip the downloaded file, if necessary.
The complete MySQL package comes as
Installing MySQL on Windows

a Zip file that must be unzipped (if you


don’t already have a Zip application,
there are free ones available—just search
Google or www.download.com). It doesn’t
really matter where you choose to unzip
the files in this step.
At the time of this writing, the Essentials
version of the installer is downloaded as
a Microsoft Windows Installer (.msi) file
that does not require unzipping.
3. Run the setup.exe or .msi application by
double-clicking the file.
Depending upon which file you download,
you should now have either an executable
(called setup.exe) in the unzipped folder
or a Microsoft Windows Installer (.msi).
In either case, just double-click the file to
begin the installation process.
If you are using a version of Windows NT,
you must be logged in as an administrator-
level user with the permission to install
software.

6
Installing MySQL

4. On the second installation page, select


the installation type: Typical, Complete,
or Custom (Figure 1.3).
Naturally, the Typical installation should
be fine for most users. If you opt for the
Custom Setup, click an item and view
the description in the right-hand panel
(Figure 1.4) to determine if you need
that particular item. You absolutely
must install the MySQL Server, and you
should install the Client Programs.
Figure 1.3 Choose an installation type, based upon 5. Click your way through the rest of the
what best suits your situation and knowledge. installation process and, if you want,
sign up for a MySQL.com account
when prompted.
You don’t have to sign up, but doing so
has its benefits. For starters, an account
lets you post at http://forums.mysql.com

Installing MySQL on Windows


(a community support forum), subscribe
to MySQL newsletters, and the like.
6. Opt for configuring the MySQL Server
now when prompted (Figure 1.5) and
click Finish.
The installation process is now complete,
which means you should set up how the
MySQL server runs. The installer will
Figure 1.4 You can customize what all is installed, take you over to the configuration wizard
including extra scripts and examples.
for this purpose. This topic is discussed
in the next section of the chapter, so
please read on.
✔ Tips
■ The recommendation is that MySQL
be run on Windows using the NTFS file
system (not FAT or FAT32).
■ MySQL suggests a minimum of 200 MB
of available disk space, but how much
disk space is actually required will depend
upon how many databases you have, how
much you use indexes, and how much
data you store. If space is an issue, down-
Figure 1.5 After installing MySQL, choose to jump load and install the Essentials version of
straight into the MySQL configuration wizard. MySQL, not the complete.

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

installing MySQL for the first time (see


Figure 1.5) or at any point in time later
through the Start Menu shortcut (under
the MySQL folder, added to the Start
menu during installation).
2. Select whether you want to perform a
Detailed or Standard configuration
(Figure 1.6).
Most users will probably want to go with
Figure 1.7 I would advise that you go with these
Standard here (although Detailed is the settings, for a more trouble-free operation.
default). The following steps will go
through the Standard configuration.
3. Set the basic MySQL settings (Figure 1.7).
With the Standard configuration, there
are just a few choices. You should opt for
installing MySQL as a Windows service,
and have it launch the server automati-
cally so that it’s always running. You
should also choose to include MySQL’s
bin directory in the Windows PATH,
which will make it easier to run MySQL
applications from the command line.

8
Installing MySQL

4. Define the security settings (Figure 1.8).


The choices you make here are very
important. For starters, enter a good root
user’s password. The root user has unlim-
ited access to MySQL, so this password
should be secure and one you won’t forget.
Besides that, I would recommend that
you not enable root access from remote
machines or create an anonymous
account. Both are security risks.
5. Click your way through the rest of the
Figure 1.8 Definitely create a secure root user configuration process.
password and do not enable remote root access!
✔ Tips
■ When you install MySQL as a service, it
can automatically be started when your
computer starts. It can also restart auto-
matically after a system crash.

Configuring MySQL on Windows


■ Once you’ve created the root MySQL user,
you can create other, day-to-day users, by
MySQL and Firewalls following the steps outlined in Chapter 2.

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

with a Macintosh graphical user interface, bin All applications


meaning that it has the usability and stability data Databases and logs
of any Unix operating system but the appear- docs Documentation
ance and interface of a Mac. The implication include Header files
of this is that, now more than ever, there is lib Code libraries
an Apple operating system that programmers man Unix man pages
and developers are actively using. Furthermore, scripts The mysql_install_db script
most software that installs and runs on a share/mysql Error message files
Unix system, such as MySQL, will also work sql-bench Benchmark utilities
with Mac OS X.
MySQL is available for Mac OS X 10.2 (aka
Jaguar) and later in a precompiled binary
package. It’s quite easy to use, but I’ll run
through it nonetheless. Note that the server
Installing MySQL on Macintosh

version of Mac OS X comes with MySQL


preinstalled, so you will need to perform an
update, not an installation, if you are run-
ning Mac OS X Server. See later in this
chapter for update-specific instructions.
MySQL will be installed in the /usr/local/
mysql-VERSION directory, where VERSION
is the full version name and number (e.g.,
max-5.0.18-osx10.4-powerpc). A symbolic link
is then created so that /usr/local/mysql
can be used as a shortcut to /usr/local/
mysql-VERSION. The folder layout within this
directory is represented in Table 1.2.

10
Installing MySQL

To install MySQL on Mac OS X:


1. Download the current package from the
MySQL Web site.
Start by pointing your browser to
http://dev.mysql.com/downloads. Then
click the name of the version you’ll want.
As of the time of this writing, the most
current stable release of MySQL is ver-
Figure 1.9 Choose the MySQL package you want, sion 5.0.18.
matching your version of Mac OS X. On the next page, you’ll be able to choose
which binary you want (Figure 1.9).
MySQL recommends the Standard ver-
sion, but I’d recommend the Max version
if you want to learn it all and have the
disk space to spare. Make sure you also
are picking from the area that matches
your version of Mac OS X.

Installing MySQL on Macintosh


2. Mount the .dmg file.
The downloaded file is of type .dmg, a
common disk image. Just double-click it
Figure 1.10 The contents of the mounted disk image. to mount the disk so that you may begin
the installation process. The result will
be a folder of things like that shown in
Figure 1.10.
3. Install MySQL.
Double-click the MySQL package—the
thing called something like mysql-version-
os-powerpc.pkg—and follow through its
steps. Apart from choosing the destina-
tion (Figure 1.11), which applies only if
you have more than one volume, the
installation is mindless.
continues on next page
Figure 1.11 If you have multiple hard disks or
partitions, install MySQL on the one with the
operating system.

11
Chapter 1

4. Install the System Preferences pane by


double-clicking the MySQL.prefPane item
(see Figure 1.10).
The MySQL System Preferences pane
is an easy way to control MySQL
(Figure 1.12). To install it, just double-
click the item and your Mac will do
the rest.
5. If you want, run the
Figure 1.12 MySQL comes with a System Preferences
MySQLStartupItem.pkg (see Figure 1.10). pane that can be used to start and stop the database
By running this installer, a script will be server.
added that automatically starts MySQL
every time you start your Mac. This
functionality is duplicated by checking
the appropriate box in the System
Preferences panel (see Figure 1.12).
6. Start MySQL and assign a password to
Installing MySQL on Macintosh

MySQL’s root user.


You’ll learn how to do these two steps in
Chapter 2.
✔ Tips
■ The installation of MySQL on the Mac
has been greatly simplified. You no
longer need to take such steps as creat-
ing a separate MySQL user.
■ According to MySQL, there is a bug in
the Apple package installer program,
which may result in an error that states
“You cannot install this software on this
disk” on the destination disk selection
page (Figure 1.11). If you see this, click
Go Back, then click Continue to return to
the destination disk selection page, and
you should be fine.

12
Installing MySQL

Table 1.3 After installing MySQL, you’ll have these


folders (all found within the main MySQL folder, Installing MySQL on Linux
/usr/local/mysql).
According to the manual, the best way to
MySQL Layout on Linux install MySQL on Linux is to use an RPM (a
Subfolder Contains
package formatted for the Red Hat Package
bin All applications Manager, an installer which is not limited to
info Documentation just Red Hat Linux). MySQL provides RPMs
include/mysql Header files for many different versions of Linux, so if
lib/mysql Code libraries one is available for the platform you’re using,
libexec The mysqld server that’s the best and easiest way to go. There
man Unix man pages are both server and client RPMs available;
share/mysql Error message files you’ll probably want to install both.
sql-bench Benchmark utilities Installing an RPM is just a matter of typing
var Databases and logs
rpm -i MySQL-server-VERSION.i386.rpm

in a Terminal (you may need to precede this


with sudo, per the instructions in the side-
bar). The RPMs, by default, will install the
Being the Root User applications within the /usr directory with
the data stored in /var/lib/mysql. Further,

Installing MySQL on Linux


Unix-based operating systems, including
Max OS X and Linux, rely on the concept the RPM will add the requisite data to the
/etc/rc.d/ directory so that the MySQL
of users for security purposes. The ulti-
mate user, root, can do anything within server daemon will be automatically started
the operating system, including destroy when the computer is booted. The RPM also
it. For this reason the root user should be creates a user called mysql, if necessary.
handled gingerly, but it is also a necessary Installing an RPM is straightforward enough
evil when installing new software. that I will not say more about it, but see the
MySQL manual if you have problems.
If a root user account has already been
established (with a password), you can Another option, which I will cover here, is to
become root by typing su root within the compile the source code yourself. This isn’t
Terminal application. You will then be just a Linux thing, you can compile MySQL
prompted for the root user’s password. yourself on nearly any operating system. All
Alternatively, you can do everything as you need is a compiler like gcc, utilities like
gunzip and tar, plus make. Any number of
your normal user, but request root power
as needed. To do so, preface every com- problems can occur using this method, so
mand with sudo, like it’s not for the faint of heart, but if you know
what you’re doing, this is a great way to get a
sudo make install
version of MySQL that’s customized to how
The first time you do this, and after a you want it to behave. With this installation
period of inactivity, you will be prompted method, the resulting layout will be a little
for the root password. While repeatedly different (Table 1.3), with /usr/local/mysql
using sudo may seem tedious, this is less as the base directory.
heavy-handed than to temporarily act as
the root user.

13
Chapter 1

To compile MySQL on Linux:


1. Download the tarball (tar.gz) source
distribution of MySQL.
The easiest way to do so is to use your
Web browser, saving the file to your
home directory. At the time of this writ-
ing, the latest Generally Available version Figure 1.13 On Linux, use the Terminal application to
is 5.0.18, making the downloaded file install MySQL.
mysql-5.0.18.tar.gz.

2. Access the server via a command-line


interface (Figure 1.13).
In my example here, I will be installing
MySQL on Ubuntu 5.10 (Ubuntu is
based on the Debian line of Linux).
Everything will take place within the
Terminal application. Figure 1.14 Create a new user and group who will own
You will need to have permission to and run MySQL.
manipulate files and create new directo-
Installing MySQL on Linux

ries within the /usr/local directory, so


you may need to switch to the root user
or use sudo, as I’ll do in these steps. See
the sidebar “Being the Root User” for
more information.
3. Move into the same directory where the
downloaded MySQL files are located.
cd /path/to/directory
Use the preceding command to move
into the directory where the source
files were saved, changing the path
accordingly. In my case, I entered
cd ~/Desktop
as I saved the download to my desktop.
4. Create a new MySQL user and group
(Figure 1.14).
sudo groupadd mysql
sudo useradd –g mysql mysql
This step will allow you to run and man-
age MySQL as the mysql user, rather than
root. This step adds extra security to your
system (it’s best not to use root unless
you absolutely have to).

14
Installing MySQL

5. Unpack the files.


tar xzvf mysql-5.0.18.tar.gz
The tar command will unpack the
downloaded folder. The source versions
use a naming convention like mysql
-VERSION.tar.gz. In this step, and in
Figure 1.15 To create a more optimized MySQL binary,
adjust your compiler’s behavior to match your those following, be sure to change your
processor. commands appropriately if you are
using a different version than I am here.
6. Move into the new directory.
cd mysql-5.0.18
The next couple of steps will take place
within the unpacked folder of source
code files.
7. Configure gccs’ behavior ( Figure 1.15).
Figure 1.16 If you are using the source files of MySQL, CFLAGS=”-O3”
you’ll need to configure it yourself. At the very least,
be sure to specify the prefix in your configuration CXX=gcc
statement. CXXFLAGS=”-O3 -felide-constructors

Installing MySQL on Linux


-fno-exceptions -fno-rtti”
This is an optional step but may result
in a faster, more stable binary. These are
also generic settings; ones specific to
your processor may be better. Note that
those are capital versions of the vowel “o”
before each 3. See the MySQL manual or
search the Web for more information on
what gcc flags to use.
8. Configure the MySQL source files
(Figure 1.16).
./configure --prefix=/usr/local/mysql
→ --enable-assembler --with-mysqld-
→ ldflags=-all-static
For more information on configuring
MySQL, see “Basic Configuration Options”
later in this chapter or the pertinent sec-
tions of the MySQL manual. The prefix
option is very important, as it specifies
where MySQL, and therefore the actual
binary files to be executed, should be
placed. The other two options should
improve MySQL’s performance.
continues on next page

15
Chapter 1

9. After the configuration has successfully


run (Figure 1.17), make and install
the files.
make
sudo make install
These two steps will take some time,
depending upon the operating system
and processor speed of your server. If Figure 1.17 If the configuration step (Figure 1.16)
you encounter problems with make (you worked, you should see a message like this, meaning
would see error messages and the make you are ready to make and install the files.
would terminate), do not proceed to the
sudo make install step. If you continue
to have difficulties with this part of the
installation, check the MySQL manual
or Appendix A, “Troubleshooting,” for
more information or consider using a
binary version instead of the source.
Note that you must run make install as
the root user, in my case by invoking sudo.
Installing MySQL on Linux

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

12. Change the permissions on the new files


(Figure 1.19).
sudo chown –R root .
sudo chown –R mysql var
sudo chgrp –R mysql .
Figure 1.19 By giving the mysql user permissions over This final step allows the MySQL server
your files, you can avoid the security risk of running to run under the guise of the newly
MySQL as root.
created mysql user. All of the files will be
marked as owned by the root user except
for the data directory, var, which will be
owned by the same user MySQL will
run as.
13. Start MySQL and assign a password to
MySQL’s root user.
You’ll learn how to do these two steps in
Chapter 2.
✔ Tips

Installing MySQL on Linux


■ Depending upon your operating system,
you may have to add the mysql user
and group using different terminology
(like adduser and addgroup) than the
example here.
■ You can also use wget or curl to down-
load MySQL. But since you have to find
the full, correct URL of the source files,
taking into account which mirror you’ll
use, I find the browser to be easiest.
■ During my configuration, I saw a
No curses/termcap library found error.
To adjust for this, I had to add the
--with-named-curses-libs=/lib/
libncurses.so.5 argument to the
configuration command.
■ If you’ve already configured MySQL once
and need to reconfigure it, first wipe out
the previous configuration by running
make distclean
within the MySQL source code directory,
prior to reconfiguration.

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.

you can set the location of the installed files


using the prefix option (as I did in my Linux
example). You can also choose whether or
not to install the MySQL server (leaving
only the client), and select what language to
use. These are just examples; the full listing
of options is available by typing ./configure
--help at the command line from within the
MySQL source code directory (e.g., ~/Desktop/
Basic Configuration Options

mysql-5.0.18) (Figure 1.20).

Another way you can affect how MySQL runs


is to use a configuration file. On Windows,
the easiest way to create and edit such a file
is to use the MySQL Server Instance config-
uration wizard utility, introduced earlier in
this chapter. This utility will manage the
my.ini file, found within the MySQL instal-
lation directory.
On any operating system, you can also man-
ually edit a configuration file or even create
your own. The installation comes with sev-
eral configuration samples, which you can
tweak. I’ll run through how that process
would work.

18
Installing MySQL

Script 1.1 This is a sampling of what a basic To change MySQL’s configuration:


configuration file looks like.
1. Find a MySQL sample configuration file.
1 # Example MySQL config file for medium The sample configuration files will be
systems.
installed when you install MySQL; the
2 #
3 # This is for a system with little memory
only question is where. These should be
(32M - 64M) where MySQL plays in the directory where MySQL was
4 # an important part, or systems up to placed, but they may turn up somewhere
128M where MySQL is used together with
else on Mac OS X and Unix (just do a
5 # other programs (such as a web server)
6 # search in the Terminal to find them).
7 # You can copy this file to The configuration files have the names
8 # /etc/my.cnf to set global options, my-huge.cnf, my-large.cnf, my-medium.cnf,
9 # mysql-data-dir/my.cnf to set server-
specific options (in this
and my-small.cnf. Each file represents a
10 # installation this directory is sample configuration for an expected
/var/mysql) or server load. I would start with either
11 # ~/.my.cnf to set user-specific options.
my-medium.cnf or my-small.cnf.
12 #
13 # In this file, you can use all long 2. Make a copy of the file.
options that a program supports.
14 # If you want to know which options a
You’ll want to make a copy just in
program supports, run the program case you ever want to use the original

Basic Configuration Options


15 # with the "--help" option. version again.
16
17 # The following options will be passed to 3. Rename the file as my.cnf.
all MySQL clients
18 [client] 4. Move the file to the correct destination.
19 #password = your_password On Windows, this should be either the
20 port = 3306
directory where MySQL was installed
21 socket = /var/mysql/mysql.sock
22
(C:\Program Files\MySQL\MySQL Server
23 # Here follows entries for some specific x.x) or the root of the hard drive
programs (C:\my.cnf).
24
25 # The MySQL server
If you installed on Unix using the source
26 [mysqld] distribution method, you’ll want to put
27 port = 3306 the configuration file in /etc.
28 socket = /var/mysql/mysql.sock
29 skip-locking 5. Open the file in any text editor and edit
30 key_buffer = 16M the file as needed.
31 max_allowed_packet = 1M The file is pretty easy to understand and
32 table_cache = 64
contains copious notes (Script 1.1).
33 sort_buffer_size = 512K
34 net_buffer_length = 8K
Note that anything after the number
35 read_buffer_size = 256K symbol (#) is considered a comment and
36 read_rnd_buffer_size = 512K has no effect.
37 myisam_sort_buffer_size = 8M
38 continues on next page
39 # Don't listen on a TCP/IP port at all.
This can be a security enhancement,
40 # if all processes that need to connect
to mysqld run on the same host.

19
Chapter 1

6. Save the file.


7. Restart MySQL.
Any changes will take effect the next
time you start the MySQL server.
✔ Tips
■ When entering pathnames on Windows
in the configuration file, use either for-
ward slashes (/) or two backslashes (\\).
■ In this section I talk about configuration
files with respect to how the MySQL
server runs. You can also create configu-
ration files for MySQL’s client applications
and utilities. Such a file would be named
and stored as C:\WINDOWS\my.ini or
C:\WINNT\my.ini on Windows and
~/.my.cnf on Mac OS X and Unix, where
~ refers to your home directory.
Basic Configuration Options

■ You can also adjust how MySQL will run


by using configuration settings when you
start the MySQL server.

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

3. Install the new version of MySQL.


Follow the directions in this chapter,
installing MySQL as you otherwise would.
Some steps you can omit here, such as
creating a new user and running the
mysql_install_db script (part of the
Linux instructions).
4. Restart MySQL.
5. Update the grant tables, if necessary.
Sometimes new versions of MySQL will
require changes to the mysql database.
A script called mysql_fix_privilege_tables
will be installed for this purpose (check
your scripts directory).
As a rule of thumb, if upgrading from
one major version to another (like from
4.1 to 5.0), you’ll have to update the
grant tables.
On Unix and Mac OS X, you can run this
script from within the MySQL directory,
Upgrading MySQL

using this command:


./scripts/mysql_fix_privilege_tables
→ --password=rootUserPassword
On Windows, you’ll want to run the
mysql_fix_privilege_tables.sql file in
the mysql client (which will be discussed
in the next chapter). The command
would be something like:
SOURCE C:/Program Files/MySQL/ ✔ Tips
→ MySQL Server 5.0/scripts/
■ The Mac MySQL installer does not
→ mysql_fix_privilege_tables.sql
replace the old version of MySQL. Instead
On any platform, if you see error warn- it installs MySQL in a new directory
ings about duplicate column names, you and then changes the symbolic link to
can safely ignore those. point there.
After updating the grant tables, you’ll
need to stop and restart MySQL one ■ Advanced Unix users may also appreci-
more time. ate the benefits of installing MySQL into
a version-specific directory, and then
6. Test, test, test! updating the symbolic links to make the
Don’t just assume everything went association to the new installation. This
smoothly. Run some queries and check way you’ll have the old installation to fall
the results to be certain! back on, just in case.

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

Windows, the main decision is whether to


run it as a service or not. If you are using an
NT version of Windows, which includes
Windows NT, 2000, 2003, and XP (and prob-
ably future versions of Windows, too), the
recommendation is that you do run MySQL
as a service. When you do so, MySQL will
automatically start and stop when you turn
on and shut down your computer. In fact, if,
while running the MySQL Server Instance
Configuration Wizard (Figure 2.1), you opted
to install MySQL as a service and have it
launch automatically, MySQL has already
been started for you.
If you cannot, or will not, run MySQL as a
service, your instructions for controlling
MySQL are listed first. Instructions specifi-
cally for starting and stopping MySQL as a
service will be covered second.
When it comes to starting MySQL, it is very
important that the MySQL server not be
currently running. This may seem obvious,
but trying to start MySQL when it’s already
running can lead to confusing error messages
and is a common problem for MySQL newbies.

24
Running MySQL

Running MySQL on Windows


Starting MySQL on a Windows operating
system is very simple. The only real decision
you’ll need to make is which version of the
MySQL server—called mysqld—to start.
Depending upon what distribution of
MySQL you installed, you will have some
combination of the following choices (storage
engines, which are referenced in these
descriptions, are covered in Chapter 4,
“Creating a MySQL Database”):
◆ mysqld, the standard server, optimized
with support for the InnoDB storage
engine
◆ mysqld-debug, compiled with full debug-
ging enabled and support for both the
InnoDB and BDB storage engines

Running MySQL on Windows and Windows NT


◆ mysqld-nt, similar to mysqld except more
optimized for the NT family of Windows
(NT, 2000, 2003, and XP)
◆ mysqld-max, like the mysqld, but support-
ing every feature available
◆ mysqld-max-nt, a cross between mysqld-nt
and mysqld-max
As an average user, you may not see a differ-
ence when using any of these servers. As you
make your decision, I’d recommend starting
with the most basic option—mysqld or
mysqld-nt—and then making changes later
to fine-tune MySQL’s performance. Which
MySQL server you use does not affect the
reliability of the data stored, which is what
matters in the end.
The only trick to manually starting MySQL
on Windows is that you’ll use a DOS prompt
(also called a console window), which you
may not previously have encountered. Most
of these steps teach how to access a DOS
prompt and execute applications from this
command-line interface. Stopping MySQL
makes use of the mysqladmin utility, which
I’ll also demonstrate.

25
Chapter 2

To start and stop MySQL on Windows:


1. Decide which server you will use.
Review the preceding list of servers for
the possible options. You can confirm
which are available to you by looking at
the bin directory located within the
MySQL default installation folder (just
open it in Windows Explorer). You aren’t
Figure 2.2 Enter cmd in the Run window to access a
permanently tied to whatever you choose DOS prompt.
here, so don’t sweat it too much, particu-
larly as you’re just getting your bearings.
2. Make sure MySQL is not currently
running.
If MySQL is already running, the follow-
ing steps will result in errors, which may
be unintelligible. If you followed the
instructions in Chapter 1, “Installing Figure 2.3 A console window, also known as a DOS
prompt, or command-line interface.
MySQL,” MySQL is probably already run-
Running MySQL on Windows and Windows NT

ning. You can stop an active MySQL


process using the instructions later in
this sequence.
3. Access the Start menu.
4. Select Run.
The Run window can be used to run any
command or program.
5. In the Run window, type cmd (Figure 2.2),
and press Enter or click OK.
The code cmd is short for command,
which is a request for a command window
(Figure 2.3). Note that your command
window may not look quite the same
as mine (by default it’s white text on a
black background, which doesn’t look
so swell in a book), and the prompt will
likely differ.

26
Running MySQL

6. Move into the MySQL installation direc-


tory (Figure 2.4).
cd C:\”Program Files\MySQL\
→ MySQL Server 5.0”
Because you may or may not be able
Figure 2.4 Move into the MySQL directory to more
easily access its programs. to call the MySQL programs directly
(depending upon your PATH, see the first
tip), it’s best to move into the MySQL
directory and call the programs from
there. To avoid conflicts with the spaces
in the pathname (in Program Files and
MySQL Server 5.0), quotes are used as
Figure 2.5 If the MySQL server started properly, you’ll
needed. The easiest way to type all this is
see messages like those here (or the like). to type a few letters and then press Tab,
letting the autocomplete feature fill in
the rest of each directory’s name.
If you installed MySQL in a different
location, you’ll need to change the path
here accordingly.

Running MySQL on Windows and Windows NT


7. Start the server (Figure 2.5).
At the prompt, type the following and
press Enter:
bin\mysqld --console
The important part here is just the
mysqld, which is the MySQL server itself.
If you want to use a different version of
the server (see the earlier list of servers),
change that reference.
The --console option means that all
results will be displayed in the console
window, which is useful, particularly for
debugging purposes. You should leave
the console window open for the time
being (closing the window will attempt
to shut down MySQL). If you are running
a non-NT version of Windows (some-
thing other than Windows NT, 2000,
2003, or XP), mysqld will automatically
run in the background and you are free
to do whatever with the console window.
continues on next page

27
Chapter 2

8. Confirm that MySQL is running


(Figure 2.6).
Repeat Steps 3–6 to bring up a new con-
sole window (if necessary) and move into
the MySQL directory. Then, at the prompt,
type the following and press Enter:
bin\mysqlshow -u root -p
When prompted, enter the MySQL root
user password (if you have not yet estab-
lished a root user password, for instance,
Figure 2.6 The mysqlshow utility will show a list of
during server configuration, omit the
available databases and is also a way to confirm that
-p argument). MySQL is running.
9. Stop the server (Figure 2.7).
At the prompt, type the following and
press Enter:
bin\mysqladmin -u root -p shutdown
The mysqladmin utility can be used for
many things, including stopping a run-
Running MySQL on Windows and Windows NT

ning server. The -u root argument says


that mysqladmin should perform the Figure 2.7 Use mysqladmin to shut down MySQL. If the
MySQL root user does not require a password, omit
command—shutdown—as the MySQL the -p.
root user. When prompted, enter the root
user password (if you have not yet estab-
lished a root user password, for instance,
during server configuration, omit the
-p argument).

10. Start MySQL up again and begin admin-


istering your database.
See the remainder of this chapter for
information on related MySQL utilities,
creating users, and so forth.

28
Other documents randomly have
different content
combination to break through the rules, obviously tending to
insurrection and a consequent renewal of bloodshed, we think it
proper that they should immediately be removed to separate prison
ships.’
We now come to the most rabid of the Frenchmen, General Pillet.
Pillet was severely wounded and taken prisoner at Vimiero in 1808,
and—in violation, he says, of the second article of the Convention of
Cintra, which provided that no French should be considered
prisoners of war, but should be taken out of Portugal with arms, &c.,
by British ships—was brought to England, with many other officers.
He was at once allowed to be on parole at Alresford, but, not
considering himself bound by any parole terms, attempted to escape
with Paolucci, Captain of the Friedland captured in 1808 by the
Standard and Active, but was recaptured and sent to the dépôt at
Norman Cross. Here his conduct was so reprehensible that he was
sent to the Brunswick at Chatham. From the Brunswick he tried to
escape in a vegetable boat, but this attempt failed, and it is to the
subsequent rigour of his treatment that must be attributed his
vitriolic hatred of Britain.
General Pillet is of opinion that the particular branch of the Navy
told off for duty on the prison ships was composed of the most
miserable scum of English society; of men who have either been
accomplices in or guilty of great crimes, and who had been given by
the magistrates the alternative of being marines or of being hanged!
He speaks of the Chatham hulks as abominably situated near foul
marshes—which is undeniably true. The quarters of the prisoners
were in no place high enough for a man to stand upright; fourteen
little ports, unglazed but barred, of seventeen inches square, on each
side of the deck, gave all the light and air obtainable. When they were
shut they were fast shut, so that during the winter months the
prisoners breathed foul air for sixteen hours a day. Hence they went
naked, and so, when the cold air was admitted the results were fatal.
The overcrowding of the hulks, says Pillet, was part of the great
Government design of killing the prisoners, and asserts that even a
London newspaper, quoting the opinion of a medical board in
London, said that the strongest of men, after six years’ life on the
hulks, must be physically wrecked for life.
The hammock space allowed was six feet in length, but swinging
reduced them to four and a half. Newcomers were often obliged to
sleep on the bare deck, as there was no other vacant space, and there
was no distinction of ranks. However, officers were generally able to
buy spaces, upon which practice Pillet remarks:

‘C’est une misérable spéculation pour un pauvre prisonnier


affamé; il consent à vendre sa place afin de se procurer un peu plus
de vivre pendant quelques jours, et afin de ne pas mourir de faim il
accélère la destruction de sa santé, et se réduit dans cette horrible
situation à coucher sur un plancher ruisselant d’eau, l’évaporisation
des transpirations forcées qui a lieu dans ce séjour d’angoisses et de
la mort.’

He declares that the air is so foul when the decks are shut up that
the candles will not burn, and he has heard even the guards call for
help when they have opened the hatches and the air has escaped. The
food he describes as execrable, so that the two boats which had the
monopoly of coming alongside to sell butter, tea, coffee, sugar,
potatoes, candles, and tobacco at a price one-third above that on
land, did a roaring trade. The general reply to complaints was that
any food was good enough for French dogs.
If they were badly fed, says Pillet, they were worse clothed.
Nominally they received every eighteen months a coat, waistcoat,
breeches, two pairs of stockings, two shirts, a pair of shoes, and a
cap. He declares he can prove that the prisoners did not receive this
complete rig-out once in four years, and that if a prisoner had any
rags of his own, or received any money, he got no clothes! What
clothes they did get were so badly made that they generally had to be
re-made. He says that at Portsmouth, where the hulk agent Woodriff
was at any rate conscientious enough to issue the clothes on the due
dates, his secretary would buy back the shirts at one shilling each,
and so, as Government paid three shillings each for them, and there
were at Portsmouth, Forton, and Portchester some twelve thousand
prisoners on the average, his ‘pickings’ must have been considerable!
In a note he gives the instance of the reply of Commander Mansell,
who commanded the prison-ship police at Chatham in 1813, when
the fact that not one quarter of the clothing due to the prisoners had
been delivered to them, was proved clearly: ‘I am afraid it is too true,
but I have nothing to do with it. I cannot help it.’
From the Carnet d’Étapes du Sergt.-Maj. Beaudouin, 31e demi-
brigade de ligne, I take the following account of life on the hulks.

‘On October 31st, 1809, Beaudouin left Valleyfield where he had


been confined since June 10th, 1804, and came on board the Bristol
hulk at Chatham. At this time the hulks were the Glory, three decker,
Bristol, Crown Prince, Buckingham, Sampson (mauvais sujets),
Rochester, Southwick, Irresistible, Bahama (Danes), and Trusty,
hospital ship, holding in all 6,550 prisoners.’

Beaudouin says:

‘The difference between the land prisons and the hulks is very
marked. There is no space for exercise, prisoners are crowded
together, no visitors come to see them, and we are like forsaken
people. There is no work but the corvées to get our water, and to
scrape in winter and wash in summer our sleeping place. In a word,
only to see them is to be horrified. The anchorage at Chatham is
bounded by low and ill-cultured shores; the town is two miles away—
a royal dockyard where there is much ship-building. At the side of it
is a fine, new, well-armed fort, and adjoining it a little town named
Rochester, where there are two windmills, and two more in
Chatham. By the London road, three miles off, there are four
windmills. The people of this country are not so pleasant and kind as
in Scotland, in fact I believe “the sex” is not so beautiful.’

Very soon the Bristol was condemned and its prisoners transferred
to the Fyen, and at the same time the Rochester and Southwick were
replaced by the Canada and Nassau. On the Fyen were 850
prisoners, but during 1810 and 1811 a great many Chatham prisoners
were sent to Norman Cross and Scotland.
Beaudouin comments thus bitterly:

‘It is unfortunate for me that my circle of acquaintances is so


limited, and that I cannot therefore make sufficiently known the
crimes of a nation which aims at the supremacy in Europe. It poses
as an example among nations, but there are no brigands or savages
as well versed in wickedness as it is. Day by day they practise their
cruelties upon us, unhappy prisoners. That is where they are
cowardly fighters! against defenceless men! Half the time they give
us provisions which the very dogs refuse. Half the time the bread is
not baked, and is only good to bang against a wall; the meat looks as
if it had been dragged in the mud for miles. Twice a week we get
putrid salt food, that is to say, herrings on Wednesday, cod-fish on
Saturday. We have several times refused to eat it, and as a result got
nothing in its place, and at the same time are told that anything is
good enough for a Frenchman. Therein lies the motive of their
barbarity.’

A short description of the terrible Sampson affair is given


elsewhere (p. 93), but as Beaudouin was evidently close by at the
time, his more detailed account is perhaps worth quoting.

‘On the Sampson the prisoners refused to eat the food. The
English allowed them to exist two days without food. The prisoners
resolved to force the English to supply them with eatable provisions.
Rather than die of hunger they all went on deck and requested the
captain either to give them food or to summon the Commandant of
the anchorage. The brute replied that he would not summon the
Commandant, and that they should have no other provisions than
those which had been served out to them two days previously. The
prisoners refused to touch them. The “brigand” then said: “As you
refuse to have this food, I command you to return below immediately
or I will fire upon you.” The prisoners could not believe that he really
meant what he said and refused to go below.
‘Hardly had they made this declaration, when the Captain gave the
word to the guard to fire, which was at once done, the crowd being
fired upon. The poor wretches, seeing that they were being fired
upon without any means of defence, crowded hastily down, leaving
behind only the killed and wounded—fifteen killed and some twenty
wounded! Then the Captain hoisted the mutiny signal which brought
reinforcements from the other ships, and all were as jubilant as if a
great victory had been won.
‘I do not believe that any Frenchman lives who hates this nation
more than I do; and all I pray for is that I may be able to revenge
myself on it before I die.’

Beaudouin wrote a poem of 514 alexandrines, entitled:


Les Prisons d’Albion.
Ou la malheureuse situation des prisonniers en Angleterre.
Bellum nobis haec mala fecit.
I give in the original the first and last ‘chants’ of this embittered
production.
I

‘Tu veux, mon cher ami, que ranimant ma verve


Je te peigne sans fard, sans crainte, et sans réserve,
Le Tableau des tourmens et de l’affliction
Sous lesquels sont plongés les captifs d’Albion.
J’obéis à la voix, et ma muse craintive,
Entonnant à regret la trompette plaintive,
Va chanter sur des tons, hélas! bien douloureux,
Les maux, les maux cuisans de bien des malheureux.’

LXIV

‘Je t’ai dépeint sans fard l’exacte vérité,


Tels sont les maux cruels de la captivité.
O vous qui de bonheur goûtez en paix les charmes,
Si vous lisez mes vers, donnez-nous quelques larmes;
S’ils n’impriment chez vous une tendre affection,
Vous êtes, plus que nous, dignes de compassion!’

Speaking of the horrible moral effects of the bad treatment he


says:

‘The ruin of their comrades and the depravities which were daily
committed in public, impressed right thinking men with so frightful
force that this place means a double suffering to them.’
In 1812 it was reported that a batch of incurables would be sent
home to France, and Beaudouin resolved to get off with them by
making himself ill. He starved himself into such a condition that he
was sent into hospital, but the doctor would not pass him as an
incurable. He swallowed tobacco juice, and at last, in a miserable
state, turned up with the candidates. Then it was announced that no
privateersmen, but only regular seamen, would be sent. Beaudouin,
being a soldier, and being among the privateersmen, was in despair.
However, a kindly English doctor pitied him, cured him of his self-
inflicted illness, and got him leave to go.
On June 2, 1812, he was ready to sail, but was searched first for
letters. Luckily none were discovered, although he had sixty sewn
between the soles of his shoes, and 200 in a box with a double
bottom. He sailed on June 4, the king’s birthday—that day eight
years previously he had arrived at Greenock amidst the Royal salutes
—arrived at Morlaix, and so home to Boiscommun (Loiret), canton of
Beaune-la-Rolande, arrondissement of Pithiviers.
The following experiences of an American prisoner of war are from
The Journal of a Young Man of Massachusetts, (1816), who was a
surgeon, by name Benjamin Waterhouse, captured at sea in May
1813, and confined on Melville Island, Halifax, whence he was
transported to Chatham, and then to Dartmoor. The account is
interesting as showing the very marked difference between the
American and the French prisoners of war, and is otherwise
remarkable for the hatred and contempt of the writer for Britons in
general and for Scotsmen in particular, entire pages being devoted to
their vilification. Waterhouse, with a hundred of his countrymen,
was shipped to England on the Regulus, and his complaints are
bitter about the shameful treatment on board—the filth, the semi-
starvation, the vermin, the sleeping on stone ballast, the lack of air
owing to the only opening to the lower deck being a hatchway two
feet square, the brutal rule of allowing only two prisoners to go on
deck at a time, and the presence in their midst of the only latrine.
The captain, a Scotsman, would only yield to constant petitions and
remonstrances so far as to sanction the substitution of iron bars for
the hatchway.
After a miserable voyage the prisoners reached Portsmouth, and,
starved, vermin-eaten, and in rags, were shipped off to the Crown
Prince, Captain Hutchison, at Chatham, where were thirteen other
prison ships and some 1,200 Americans. On this hulk, Waterhouse
says, they fared ‘as well as could be expected ... not that we fared so
well as British prisoners fare in America’, the daily allowance being
half a pound of beef, one gill of barley, one and a half pounds of
bread, on five days of the week, and on the others one pound cod
fish, and one pound potatoes, or one pound smoked herring, porter
and beer being purchasable. He dilates bitterly on the extraordinary
lack of humanity in John Bull, as evidenced by the hard fare of
soldiers and sailors, the scoundrelism of some officers, especially
those of the provisioning departments, and, above all, the shockingly
cruel punishments in the Army and Navy. During the daytime, he
says, life on a prison ship was not so unpleasant, but at night the
conditions were very bad—especially as American prisoners were
more closely watched and guarded than were men of other
nationalities. ‘The French were always busy in some little mechanical
employ, or in gaming, or in playing the fool, but the Americans
seemed to be on the rack of invention to escape.’
Amongst themselves, the Americans elected by voting, every four
weeks, a President, and twelve Committee men, whose functions
were to make wholesome laws, to define crimes and award
punishments, and particularly to insist upon personal cleanliness.
The punishments were fines, whippings, and in very extreme cases
the Black Hole. The volubility and the eloquence of the orators at
these Committee Meetings very much impressed the British officers.
The Frenchmen, Waterhouse says, were almost to a man gamblers:

‘Their skill and address at these games of apparent hazard were far
superior to the Americans. They seemed calculated for gamesters;
their vivacity, their readiness, and their everlasting professions of
friendship were nicely adapted to inspire confidence in the
unsuspecting American Jack Tar, who has no legerdemain about
him. Most of the prisoners were in the way of earning a little money;
but almost all of them were deprived of it by the French gamesters.
Our people stood no chance with them, but were commonly stripped
of every cent, whenever they set out seriously to play with them. How
often have I seen a Frenchman capering, singing, and grinning in
consequence of his stripping one of our sailors of all his money; ...
the officers among them are the most adroit gamesters. We have all
tried hard to respect them; but there is something in their conduct so
much like swindling, that I hardly know what to say of them. When
they knew that we had received money for the work we had been
allowed to perform, they were very attentive, and complaisant and
flattering.... They would come round and say: “Ah! Boston fine town,
very pretty—Cape Cod fine town, very fine! Town of Rhode Island
superb! Bristol Ferry very pretty! General Washington très grand
homme, General Madison brave homme!” With these expressions
and broken English, they would accompany, with their monkey
tricks, capering and grinning and patting us on the shoulder, with:
“The Americans are brave men—fight like Frenchmen;” and by their
insinuating manners allure our men once more to their wheels of
fortune and billiard-tables, and as sure as they did, so sure did they
strip them of all their money.’
Waterhouse adds that ‘if an American, having lost all his money,
wanted to borrow of a Frenchman under promise of repayment, the
latter would say: “Ah mon ami! I am sorry, very sorry, indeed; it is la
fortune de guerre. If you have lost your money you must win it back
again; that is the fashion in my country—we no lend, that is not the
fashion!”...
‘There were here some Danes as well as Dutchmen. It is curious to
observe their different looks and manners.... Here we see the thick-
skulled plodding Dane, making a wooden dish; or else some of the
most ingenious making a clumsy ship; while others submitted to the
dirtiest drudgery of the hulk, for money; and there we see a
Dutchman, picking to pieces tarred ropes ... or else you see him lazily
stowed away in some corner, with his pipe ... while here and there
and every where, you find a lively singing Frenchman, working in
hair, or carving out of a bone, a lady, a monkey, or the central figure
of the crucifixion! Among the specimens of American ingenuity I
most admired their ships, which they built from three to five feet
long.... Had not the French proved themselves to be a very brave
people, I should have doubted it by what I have observed of them on
board the prison-ship. They would scold, quarrel and fight, by
slapping each other’s chops with the flat hand, and cry like so many
girls.... Perhaps such a man as Napoleon Bonaparte could make any
nation courageous.’
Very bitter were the complaints of the Americans about the supine
and indifferent attitude towards them of Beasley, their agent, who
was supposed to keep constant watch and ward over the interests of
his unfortunate countrymen. He lived in London, thirty-two miles
away, paid no attention to complaints forwarded to him, and was
heartily hated and despised. Once he paid a visit to the hulks in
Gillingham Creek, but seemed anxious to avoid all interviews and
questionings, and left amidst a storm of hisses and jeers.
Waterhouse dwells severely on the fact that the majority of the
Americans on the Crown Prince and the other hulks were not men
who had been fairly taken in open combat on the high seas, but men
who had been impressed into the British Navy from American
merchant ships previous to the war between the two countries and
who, upon the Declaration of War, had given themselves up as
prisoners of war, being naturally unwilling to fight against their own
country, but who had been kept prisoners instead of being
exchanged. This had been the British practice since 1755, but after
the War of Independence it had ceased. All the same the British
authorities had insisted upon the right of search for British subjects
on American ships, and to the arbitrary and forcible exercise of this
‘right’ was very largely owing the War of 1812.
Waterhouse admits that on the whole he was treated as well on the
Crown Prince as were the British prisoners at Salem or Boston.
Recruiting sergeants for the British service came on board and tried
to tempt Americans with a bounty of sixteen guineas, but they were
only chaffed and sent off.
Later on, 500 more prisoners arrived from America in a pitiable
condition, mostly Maryland and Pennsylvania men—‘Colonel
Boerstler’s men who had been deceived, decoyed and captured near
Beaver Dams on January 23rd, 1813’. With their cruel treatment on
board the Nemesis on their trans-Atlantic voyage, Waterhouse
contrasts favourably the kind treatment of the prisoners brought by
the Poictiers 74, Captain Beresford, after his capture of the American
Wasp and her prize the Frolic.
The author gives a glaring instance of provision cheating. By the
terms of his contract, if the bread purveyor failed to send off to the
hulks fresh bread when the weather was favourable, he forfeited half
a pound of bread to each man. For a long time the prisoners were
kept in ignorance of this agreement, but they found it out, and on the
next occasion when the forfeit was due, claimed it. Commodore
Osmore refused it, and issued hard ship’s bread. The prisoners
refused to take it. Osmore was furious, and ordered his marines to
drive the prisoners, now in open mutiny, below. A disturbance was
imminent, but the Americans remained firm, and the commodore
gave way.
The American prisoners took in newspapers, as they were mostly
intelligent and well-educated men, but paid dearly for them.
The papers were the Statesman, Star, Bell’s Weekly Messenger,
and Whig. The Statesman cost 28s. a month, plus 16s. a month for
conveyance on board.
As the weather grew milder, matters were more comfortable on
board until small-pox broke out. Vaccination was extensively
employed, but many prisoners refused to submit to it, not from
unbelief in its efficacy, but from misery and unwillingness to live!
Then came typhus, in April 1814. There were 800 prisoners and 100
British on the ship. The hospital ship being crowded, part of the
Crown Prince was set apart for patients, with the result that the
mortality was very high. Still Beasley, the American agent, never
came near the ship to inquire into affairs.
The gambling evil had now assumed such proportions that the
Americans determined to put it down. In spite of the vigorous
opposition of the Frenchmen, the ‘wheels of fortune’ were abolished,
but the billiard-tables remained, it being urged by the Frenchmen
that the rate of a halfpenny per game was not gambling, and that the
game afforded a certain amount of exercise. There remained,
however, a strong pro-gambling party among the Americans, and
these men insisted upon continuing, and the committee sent one of
them to the Black Hole without a trial. This angered his mates; a
meeting was held, violent speeches were made in which the names of
Hampden, Sidney, and Wilkes were introduced, and he was brought
out. He was no ordinary rough tar, but a respectable well-educated
New England yeoman, with the ‘gift of the gab’; and the results of his
harangue were that the committee admitted their error, and he was
released.
Finally the billiard-tables were abolished; a great improvement
was soon manifest among the captives, education was fostered, and
classes formed, although a few rough characters still held aloof, and
preferred skylarking, and the slanging and chaffing of passers-by in
boats on the river.
In May 1814 four men went on deck and offered themselves for
British service. Two got away, but two were caught by their mates,
tried, and sentenced to be marked with indian ink on their foreheads
with the letter T (= Traitor). The Frenchmen were now being shipped
home. Some of them had been prisoners since 1803. Waterhouse
comments upon the appalling ignorance among English people in
the educated class of all matters American, and quotes the instance
of the lady who, wishing to buy some of the articles made by the
American prisoners, was confronted by the difficulty of ‘not knowing
their language’!
Waterhouse describes the surroundings of the Crown Prince thus:

‘The Medway is a very pleasant river ... its banks are rich and
beautiful.... The picture from the banks of the river to the top of the
landscape is truly delightful, and beyond any thing I ever saw in my
own country, and this is owing to the hedges.... Nearly opposite our
doleful prison stands the village of Gillingham, adorned with a
handsome church; on the side next Chatham stands the castle,
defended by more than an hundred cannon.... This place is noted for
making sulphate of iron.... Near to this village of Gillingham is a neat
house with a good garden, and surrounded by trees, which was
bequeathed by a lady to the oldest boatswain in the Royal Navy.’

Waterhouse complains strongly of the immorality on board: ‘Such


a sink of vice, I never saw, or ever dreamt of, as I have seen here,’ He
relates a daring escape. A hole was cut through the ship’s side near
the stern, the copper being removed all round except on one side so
as to lap over and be opened or closed at will. Sixteen men escaped
through this, and swam ashore one dark night, the sentry on duty
close by being allured away by the singing of droll songs and the
passing of a can of grog. At the numbering of the prisoners next
morning, the correct tale was made up by the passing through a hole
cut in the bulk-head of sixteen men who had been already counted.
At another attempt two men slipped into the water; one of them got
tired and benumbed with cold, and turned back. The sentry heard
him breathing and said: ‘Ah! Here is a porpoise, and I’ll stick him
with my bayonet,’ and only the crying out of the poor would-be
refugee saved him. The ship’s officers on examining the hole were
amazed, and one of them remarked that he did not believe that the
Devil himself could keep these fellows in hell if they made up their
minds to get out. The next day the other poor chap was seen lying
dead on the beach, and to the disgust of the prisoners was allowed to
remain there two days before he was buried.
Commodore Osmore was always the butt of the American
prisoners. A yarn got about that he had procured a sheep from a
farmer ashore without paying for it. Thereupon his appearance was
the signal for a chorus of ‘Baa! Baa!’ He was mad with rage, and
ordered the port through which the insulting chorus had been made
to be closed. The Americans forced it open. The marines drove the
prisoners from the fo’c’sle into the ‘Pound’. As more ‘Baa!’s
resounded, they were driven below decks, and all market boats were
stopped from approaching the ship, so that for two days the
prisoners were without extra food. However, Captain Hutchison
instituted an inquiry, and peace was arranged.
In June 1814 three men escaped in a water tank. Others would
have followed, but one of the former party had stupidly written an
ironical letter of thanks to Captain Hutchison, in which he described
the method of escape.
A daring escape was made from the Irresistible in broad daylight.
Four Americans saw a jolly-boat made fast to the accommodation-
ladder under the charge of a sentry. One of them was a big, strong
Indian of the Narragansett tribe from Rhode Island. The four men
dashed down, seized the sentry, disarmed him, threw him into the
boat, and pulled off. They were fired at from all sides, and boats put
off from all the ships to chase them, but only one man was wounded.
They reached shore and struck across the fields, which were soon
covered by people in chase from the farms and brickfields, who soon
ran all the prisoners down except the Indian, who out-distanced the
prisoners, and would have got away had he not sprained his ankle in
getting over a fence, and even then, as he was sitting down, none of
the country folk would approach him, until the marines came up.
The chase had been closely followed with great excitement on the
ship, and on the arrival of the captured men alongside, they were
loudly cheered, their healths drunk, and the Indian at once dubbed
‘Baron Trenck’. Said the boys: ‘If it took 350 British seamen and
marines to capture four Yankees, how many British sailors and
marines would it take to catch ten thousand of us?’
Two Scotsmen Waterhouse excepted from his condemnation of
their nation: Galbraith, the master-at-arms, and Barnes, the sailing-
master, who was wont to reprove them for misdeeds, saying: ‘I
expect better things of you as Americans, I consider you all in a
different light from that of a d—d set of French monkeys.’
The British officers were clearly uneasy about their custody of the
Americans, and felt it to be an ignoble business. Said they: ‘The
Yankees seemed to take a pleasure in making us uneasy, and in
exciting our apprehensions of their escape, and then they laugh and
make themselves merry at our anxiety. In fact, they have
systematized the art of tormenting.’
The Government, too, appreciated ‘the difficult task which the
miserable officers of this miserable Medway fleet had to perform’. It
did not wish them to be more rigorous, yet knew that more rigour
was necessary. Rumours got about that in desperation the
Government was about to transfer all the Americans from the prison
ships to Dartmoor—the place which, it was said, had been lost by the
Duchess of Devonshire at a game of hazard to the Prince of Wales,
who determined to utilize it profitably by making a prison there.
The national festival on July 4 was duly celebrated on board the
two prison ships Crown Prince and Nassau. An additional allowance
of drink was sanctioned, but the American flag was only allowed to
be flown as high as the ‘railings’. There were drums and pipes which
played Yankee Doodle on the fo’c’sle: cheers were exchanged
between the ships, and the toast of the day was drunk in English
porter. There was, of course, much speechifying, especially on the
Nassau, where one orator declaimed for half an hour, and another
recited a poem, ‘The Impressment of an American Sailor Boy’, which
is too long to be quoted, but which, says our author, brought tears
into many eyes. All passed off quietly, and acknowledgement is made
of the ‘extraordinary good behaviour of all the British officers and
men on board the Crown Prince‘.
Although Commodore Osmore was unpopular with the Americans,
his charming wife exercised a good influence in the ship by her
amiability and appreciation of the fact that American prisoners were
not all a gang of vagabonds; and gradually a better feeling developed
between captors and captured.
In August 1814 the news of the transfer to Dartmoor was
confirmed, and, says Waterhouse, was received with regret on the
Crown Prince—the ship being ‘actually viewed with feelings of
attachment’. The last scene, however, was marked by a disturbance.
Thirty prisoners had been told off to prepare for embarkation on a
tender. At the appointed hour no tender appeared, and the
embarkation was put off. But all hammocks had been packed, and
upon application to Osmore for hammocks, the prisoners were told
to shift as they could for the night, as the tender would arrive early
the next morning, and it was not worth while to unpack the
hammocks. Upon hearing this the prisoners resolved that if they
were to be deprived of their night’s rest, nobody else should have
any. So they harnessed themselves to benches, and ran about the
deck, shouting and singing, and bumping the benches against
everything which would make a noise, jammed down the marines’
crockery and brought into play every article which could add to the
pandemonium. Osmore sent a marine down to quiet them. The
marine returned, dishevelled, and disarmed. Osmore was furious.
‘I’ll be d—d if I do not fire on them!’ he roared: ‘Fire, and be d—d,’
was the response. As it was useless to attempt to quiet them, and to
fire would have been criminal, the commodore retired, and did what
he could to sleep amid the infernal din of bumping benches, jangling
metal, shouts and songs, which lasted throughout the night.
When the tender took the men off in the morning it was to the
accompaniment of a great roar of ‘Baa! Baa!’ as a parting shot.
The remainder of the Crown Prince Americans were transferred to
the Bahama on October 15, 1814. Here they found 300 of their
countrymen of the vicious, baser sort, gamblers all, and without any
men of influence to order them. Danes occupied the main deck and
Americans the lower. Jail fever had played havoc among Danes and
Americans—no less than 84 of the latter being buried in the marshes
in three months.
Next to the Bahama lay the Belliqueux hulk, full of harmless and
dull Scandinavians, so that the captain thereof, having nothing to do
in his own ship, started to spy upon the doings aboard the Bahama,
and succeeded in getting a marine punished for smuggling liquor.
Next day, the rations were fish and potatoes. The Americans
collected all their potatoes, and watched for the appearance of the
Belliqueux commander for his spying promenade on his quarter
deck, the result being that when he did appear, he was greeted with
such a hail of potatoes that he was fain to beat an undignified retreat.
Soon he came off in his boat to complain to Commander Wilson of
the Bahama of his treatment. Wilson, a passionate, hot-tempered,
but just and humane man, said he was very sorry, but could do
nothing, so back the discomfited officer had to go, pelted with more
potatoes and some coals. Said Wilson: ‘These Americans are the
sauciest dogs I ever saw; but d—n me if I can help liking them, nor
can I ever hate men who are so much like ourselves.’
In October 1814 two hundred Americans were sent to Plymouth,
where they were at once boarded by an army of loose women.
With Waterhouse’s experiences at Dartmoor I deal in the chapter
devoted to that prison.
CHAPTER VI
PRISON-SHIP SUNDRIES

Under this heading are included various reminiscences of, and


particulars about, the prison ships which could not be conveniently
dealt with in the foregoing chapters.
In April 1759 five French prisoners from the Royal Oak hulk at
Plymouth were executed at Exeter for the murder of Jean Maneaux,
who had informed the agent that his comrades had forged passports
in order to facilitate their escape to France. Finding this out, they got
Maneaux into an obscure corner of the ship, tied him to a ringbolt,
and gave him sixty lashes with a rope to the end of which was
fastened an iron thimble as thick as a man’s wrist. He got loose, and
fell back; they jumped on him till they broke his neck, then cut his
body into small pieces, and conveyed them through a waste pipe
overboard. The next day twenty-seven prisoners were arrested, and
one of them pointed out the actual murderers.
In 1778 two prisoners escaped from the San Rafael at Plymouth,
swam off to a lighter full of powder, overpowered the man in charge,
ran down through all the ships in Hamoaze, round Drake’s Island,
and got safely away to France, where they sold the powder at a
handsome price.
Even more daring was the deed of eleven Frenchmen who, early in
the morning of April 7, 1808, made their escape from the hulk
Vigilant at Portsmouth, by cutting a hole, and swimming to the
Amphitrite, a ship in ordinary, fitted up as the abode of the
Superintendent Master. They boarded a boat, hanging on the davits,
clothed themselves in the greatcoats of the boat’s crew, lowered her,
and in the semi-darkness pulled away to the Master Attendant’s buoy
boat, one of the finest unarmed crafts in the harbour, valued at
£1,000. They boarded her, immediately got under way at about five
a.m., and successfully navigated her to Havre, or Cherbourg, which
they reached in the evening, and sold her for £700. She was fitted
out, armed with eight six-pounders, and went forth as a privateer
under the name of Le Buoy Boat de Portsmouth. Her career,
however, was short, for in November she was captured by the
Coquette.
The above-mentioned prison ship Vigilant seems to have hardly
deserved her name, for in the year 1810 alone no less than thirty-two
prisoners escaped from her, and of these only eight were recaptured.
On another occasion three prisoners escaped from a hulk, got a
small skiff, rowed to Yantlett Creek, where they boarded a fishing-
smack of which the master and boy were asleep. The master made a
stout resistance and called on the boy to help him, but he was too
terrified to do so. The master was overpowered and severely beaten,
and then managed to jump overboard. The Frenchmen got off, taking
the boy with them.
The Sampson at Chatham was evidently an ill-omened ship. It was
on board her that occurred the disastrous event of May 31, 1811,
when the half-starved prisoners, upon being docked of half their
rations for the misdeeds of a few of their number, broke out into
open mutiny, which was only quelled at the cost of six prisoners
being killed and a great many wounded. On the Sampson, also, was
fought a particularly terrible duel in 1812. Two prisoners quarrelled
and determined to settle their difference quietly. So, attended only by
their seconds, they betook themselves to the ordinary ship prison,
which happened to be empty, and, armed with sticks to which
scissor-blades had been fastened, fought. One of them received a
mortal thrust in the abdomen, but, although his bowels were
protruding, he continued to parry his opponent’s blows until he was
exhausted. He died in spite of the surgeon’s attentions.
On board the same ship in 1813, three prisoners decided to murder
the master’s mate and the sergeant of marines—men universally
detested for their brutal behaviour—and drew lots as to who should
do it. The lot fell upon Charles Manseraux. But he had ‘compunction
of conscience’ because the sergeant was a married man with a family.
However, he had to kill some one, and fixed on a private of the
Marines. He took the opportunity when the unfortunate man was
doing duty on the fo’c’sle and drove a knife into his back. Another
prisoner saw the deed done, knocked Manseraux down and secured
him. Manseraux and the others were tried at the Maidstone Assizes,
found guilty, and executed.
Duelling and crimes of violence seem to have been rampant on
certain ships more than on others. The San Damaso at Portsmouth
was one of these, although on the Chatham hulks the unnatural
deaths were so frequent that the Coroner of Rochester in 1812
claimed special fees from the Transport Office on account of the
trebling of his duties, a claim which was not granted.
A very bold attempt at escape in broad daylight was made by some
desperate prisoners of the Canada hulk at Chatham in 1812. Beef
was being hoisted on board the prison ship from a lighter alongside,
on board of which were half a dozen American prisoners who were
assisting in the operation. Suddenly, they cut the painter, and,
helped by a stiff breeze, actually sailed off, and, although the guards
on all the prison ships fired at them, would have escaped if they had
not run aground off Commodore’s Hard, Gillingham. They sprang
ashore here, and ran, but the mud was too much for them and they
were captured.
The Americans, whether ashore or afloat, were the hardest
prisoners to guard of any. They seem never to have relaxed in their
plans and attempts to escape, and as they were invariably better
supplied with money than Frenchmen and Spaniards, they could add
the power of the bribe to the power which knowledge of their captors’
language gave them. Hence no estimate can be formed of the real
number of Americans who got away from the hulks, for, although a
very exact system of roll call was in use, the ingenuity of the
Americans, immensely backed by their purses, contrived matters so
that not merely were the numbers on board always complete at each
roll call, but upon more than one occasion, by some over-exercise of
ingenuity, the captain of a hulk actually found himself commanding
more prisoners than there were!
By way of relief to the monotony of this guerre à outrance between
captors and captives we may quote instances when the better
humanity of the hapless ones came to the fore.
In 1812 a prisoner made an attempt to set the hulk Ganges on fire
at Plymouth, and a large hole was burned in her side. The other
prisoners helped to extinguish the flames, and were so angry with the
incendiary that they were with difficulty prevented from tearing him
to pieces.
Three officers of the Inverness Militia were sailing in the harbour
at Portsmouth in the same year, when a squall upset their boat, and
they were thrown into the water. One of the officers could not swim,
and seeing him struggling for life, a French prisoner on the Crown
hulk at once sprang overboard and brought him safely to the ship. He
was at once liberated and returned to France.
But even heroism became a cloak for trickery among these weary,
hopeless, desperate exiles ever on the watch for a chance of escaping.
In 1810 a French prisoner at Plymouth obtained his freedom by
saving a British sentry from drowning, but the number of British
sentries who, after this, met with accidents which tumbled them
overboard, and the unfailing regularity with which heroic prisoner-
rescuers appeared on the scene, awakened the suspicions of the
authorities, who found out that these occurrences were purely
commercial transactions. So they stopped automatically.
It is equally pleasing to come across, in this continually dreary
record of crime and misery, a foreign testimony to English kindness.
The following letter was kindly lent to me by Mr. J. E. Mace, of
Tenterden, Kent, to whose grandfather it was addressed:

‘Chatham. Le 10 janvier, 1798.

‘A Monsieur Mace, Tenterden.

‘Cher Monsieur:

‘S’il est cruel d’être livré aux dégoûts et aux peines que cause la
captivité la plus dure, il est bien doux de trouver des êtres sensibles
qui, comme vous, cher Monsieur, savent plaindre le sort rigoureux
des victimes de la guerre. Ce que vous avez eu la bonté de m’envoyer,
plus encore, l’expression des beaux sentiments me touche, me
pénètre de la plus vive reconnaissance, et me fait sentir avec une
nouvelle force cette vérité constante:—L’Humanité rapproche et unit
tous les cœurs faits pour elle. Comme vous, cher Monsieur, et avec
vous, je désire avec ferveur que les principes de notre Divin
Législateur reprennent leur Empire sur la terre, la conséquence en
est si belle!
‘Dieu vous garde beaucoup d’années.
‘Farbouriet, Colonel 12me Hussards.’

In 1807, as a consequence of the bombardment of Copenhagen and


the subsequent surrender to England of the Danish fleet, there were
1,840 Danish prisoners in England, who received double the
allowance of French prisoners, inasmuch as they were rather
hostages than prisoners—hostages for the good behaviour of
Denmark as regards Napoleon;—the captain of a man-of-war got
four shillings per diem, a commanding officer two shillings, the
captain of an Indiaman three shillings, and so on. In other respects
they were treated as prisoners of war.
These Danes were largely taken from the hulks to man our
merchant navy, and one Wipperman, a Danish clerk on H.M.S. Utile,
seems to have made this transfer business a very profitable one, until
the accusation brought against him by a Danish prisoner of war of
having obtained a watch and some money under false pretences,
brought to light the fact that his men rarely if ever joined the British
merchant service except to desert at the first opportunity, and
generally went at large as free men. He was severely punished, and
his exposure brought to an end an extensive crimping system by
which hundreds of dangerous foreigners had been let loose from the
prison ships, many of them spies and escape-aiders.
Foreign writers have included among their various complaints
against the British Government its reluctance to allow religious
ministration among the prisoners of war. But the Transport Office,
as we shall see later, had learned by experience that the garb of
sanctity was by no means always the guarantee of sanctity, and so
when in 1808 a Danish parson applied to be allowed on the prison
ships at Chatham, he got his permission only on the condition that
‘he does not repeat, the old offence of talking upon matters
unconnected with his mission and so cause much incorrect
inferences’—a vague expression which probably meant talking about
outside affairs to prisoners, who had no other source of information.
In 1813 the Transport Office replied to the Bishop of Angoulême,
who requested that a priest named Paucheron might minister on the
prison ships at Chatham, that they could not accede inasmuch as
Paucheron had been guilty ‘of highly improper conduct in
solemnizing a marriage between a prisoner of war and a woman in
disguise of a man’.
In no branch of art did French prisoners show themselves more
proficient than in that of forgery, and, although when we come to
treat of the prisons ashore we shall find that, from the easier
accessibility to implements there, the imitation of passports and
bank notes was more perfectly effected than by the prisoners on the
hulks, the latter were not always unsuccessful in their attempts.
In 1809 Guiller and Collas, two prisoners on El Firme at Plymouth,
opened negotiations with the captain’s clerk to get exchanged to the
Généreux, telling him what their object was and promising a good
reward. He pretended to entertain their proposals, but privately told
the captain. Their exchange was effected, and their ally supplied
them with paper, ink, and pencils of fine hair, with which they
imitated notes of the Bank of England, the Naval and Commercial
Bank, and an Okehampton Bank. Not having the official perforated
stamp, they copied it to perfection by means of smooth halfpennies
and sail-makers’ needles. When all was ready, the clerk gave the
word to the authorities, and the clever rascals got their reward on the
gallows at Exeter in 1810, being among the first war prisoners to be
executed for forgery.
In 1812 two French prisoners on a Portsmouth hulk, Dubois and
Benry, were condemned to be hanged at Winchester for the forgery
of a £1 Bank of England note. Whilst lying in the jail there they tried
to take their own lives by opening veins in their arm with broken
glass and enlarging the wounds with rusty nails, declaring that they
would die as soldiers, not as dogs, and were only prevented by force
from carrying out their resolve. They died crying ‘Vive l’Empereur!’
In 1814 six officers were found to have obtained their liberty by
forged passports. These men were, in their own vernacular, ‘Broke-
Paroles’—men who had been sent from parole places to prison ships,
for the crime of forging passports. Further investigation caused
suspicion to be fixed upon a woman calling herself Madame
Carpenter, who was ostensibly a tea and sugar dealer at 46 Foley
Street, Portland Chapel, London, but who had gained some influence
at the Transport Office through having rendered services to British
prisoners in France, which enabled her to have access to the prison
ships in her pretended trade, although she was a Frenchwoman. I
cannot discover what punishment she received. We shall hear more
of her in the chapter upon Stapleton Prison.
A clever quibble saved the life of a prisoner on the San Rafael hulk
at Plymouth. He was tried at Exeter for imitating a £2 note with
indian ink, but pleaded that as he was under the protection of no
laws he had not broken any, and was acquitted. This was before cases
of murder and forgery were brought under the civil jurisdiction.
Well-deserved releases of prisoners in recognition of good actions
done by them in the past were not rare. In 1808 a prisoner on the
Sampson at Chatham, named Sabatier, was released without
exchange on the representation of the London Missionary Society,
who acted for Captain Carbonel of the famous privateer Grand
Bonaparte, who had shown great kindness to the crew and
passengers of the ship Duff which he had captured.
In the same year a prisoner at Plymouth, named Verdie, was
released unconditionally on the petition of Lieut. Ross, R.N., for
having kindly treated the Lieutenant’s father when the latter was a
prisoner in France.
In 1810 a Portsmouth prisoner was unconditionally liberated upon
his proving satisfactorily that he had helped Midshipman Holgate of
the Shannon to escape from imprisonment in France.
Almost to the very last the care of sick prisoners on the hulks
seems to have been criminally neglected. For instance, the In-letters
to the Transport Office during the year 1810 are full of vehement or
pathetic complaints about the miserable state of the sick on the
Marengo and Princess Sophia hospital ships at Portsmouth. Partly
this may be due to an economical craze which affected the authorities
at this time, but it must be chiefly attributed to medical inefficiency
and neglect. Most of the chief medical officers of the prison ships had
their own private practices ashore, with what results to the poor
foreigners, nominally their sole care, can be imagined, and all of
them resented the very necessary condition that they should sleep on
the ships.
In this year 1810, Dr. Kirkwood, of the Europe hospital ship at
Plymouth, was convicted of culpable neglect in regularly sleeping
ashore, and was superseded. As a result of an inquiry into the causes
of abnormal sickness on the Vigilant and at Forton Prison,
Portsmouth, the surgeons were all superseded, and the order was
issued that all prison-ship surgeons should daily examine the healthy
prisoners so as to check incipient sickness. I append the States of the
Renown hospital ship at Plymouth for February 1814:

‘Staff: 2 surgeons, 1 assistant surgeon, 1 matron, 1 interpreter, 1


cook, 1 barber, 1 mattress maker, 1 tailor, 1
washerwoman, and 10 nurses.
Received 141. Discharged 69. Died 19. Remaining 53.
‘Fever and dysentery have been the prevalent complaints among
the prisoners from Pampelune, whose deplorable state the Board of
Inspection are in full possession of. (Among these were some forty
women “in so wretched a state that they were wholly destitute of the
appropriate dress of their sex”. Two of the British officers’ wives
collected money for the poor creatures and clothed them.)
Pneumonia has recently attacked many of these ill-conditioned men
termed Romans, many of whom were sent here literally in a state of
nudity, an old hammock in the boat to cover them being excepted.’

(The Romans above mentioned were the most degraded and


reckless of the Dartmoor prisoners, who had been sent to the hulks
partly because there was no power in the prison that could keep
them in order, and partly because their filthy and vicious habits were
revolting to the other and more decent prisoners.)
The horrors of the English prison ships were constantly quoted by
French commanders as spurs to the exertions of their men.
Bonaparte more than once dwelt on them. Phillipon, the gallant
defender of Badajos, afterwards a prisoner on parole in England,
reminded his men of them as they crowded to hurl our regiments
from the breaches. ‘An appeal’, says Napier, ‘deeply felt, for the
annals of civilized nations furnish nothing more inhuman towards
captives of war than the prison ships of England.’
The accompanying drawing from Colonel Lebertre’s book may give
some idea of the packing process practised on the hulks. It
represents a view from above of the orlop deck of the Brunswick
prison ship at Chatham—a ship which was regarded as rather a good
one to be sent to. The length of this deck was 125 feet, its breadth 40
feet in the widest part, and its height 4 feet 10 inches, so that only
boys could pass along it without stooping. Within this space 460
persons slept, and as there was only space to swing 431 hammocks,
29 men had to sleep as best they could beneath the others.
Something with an element of fun in it may serve as a relief to the
prevalent gloom of this chapter. It has been shown how largely
gambling entered into the daily life of the poor wretches on the
hulks, and how every device and excuse for it were invented and
employed, but the instance given by Captain Harris in his book upon
Dartmoor is one of the oddest.

‘When the lights were extinguished’, he says, ‘and the ship’s


lantern alone cast a dim glimmer through the long room, the rats
were accustomed to show themselves in search of the rare crumbs to
be found below the hammocks. A specially tempting morsel having
been placed on an open space, the arrival of the performers was
anxiously looked for. They were all known by name, and thus each
player was able to select his champion for the evening. As soon as a
certain number had gained the open space, a sudden whistle, given
by a disinterested spectator, sent them back to their holes, and the
first to reach his hole was declared the winner. An old grey rat called
“Père Ratapon” was a great favourite with the gamblers, for, though
not so active as his younger brethren, he was always on the alert to
secure a good start when disturbed.’

In justice to our ancient foe I give here a couple of extracts, for


which I have to thank Mr. Gates of Portsmouth, from the Hampshire
Telegraph, illustrative of generous behaviour towards Englishmen
who had been forced to aid prisoners to escape.
Orlop deck of Brunswick Prison Ship,
Chatham.

(After Colonel Lebertre.)

Length, 125 feet. Breadth in widest part, 40 feet.


Height, 4 feet 10 inches. Number of prisoners,
460.

‘July 20th, 1801. In a cartel vessel which arrived last week from
France, came over one Stephen Buckle, a waterman of this town.
Three gentlemen had hired this waterman to take them to the Isle of
Wight, and they had not proceeded farther than Calshot Castle when
they rose upon him, gagged him, tied him hand and foot, and
threatened him with instant death if he made the slightest noise or
resistance. The boatman begged for mercy, and promised his
assistance in any undertaking if they would spare his life; on which
he was released, and was told they were French prisoners, and
ordered to make for the nearest port in France, at his peril. The
darkness of the night, and the calmness of the wind, favoured their
intentions, for after rowing two days and nights in a small, open
skiff, without having the least sustenance, they arrived safe at
Cherbourg. The waterman was interrogated at the Custom House as
to the prisoners’ escape; when, after giving the particulars and
identifying the persons, saying they threatened to murder him, the
officers took the three Frenchmen into custody, to take their
respective trials. The poor man’s case being made known to the
Government, he was ordered to be liberated, and his boat restored.’

‘September 21st, 1807. Between 9 and 10 o’clock on the evening of


last Sunday three weeks, two men engaged Thomas Hart, a ferryman,
to take them from Gosport beach to Spithead, to go on board a ship
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!

ebookgate.com

You might also like