100% found this document useful (1 vote)
20 views

Download ebooks file MySQL Learn MySQL the Quick and Easy Way 2nd edition Edition Ullman all chapters

The document provides information about various MySQL-related ebooks available for download on ebookgate.com, including titles like 'Learn MySQL the Quick and Easy Way' and 'PHP and MySQL Web Development'. It also includes details about the Visual QuickStart Guide for MySQL by Larry Ullman, which covers installation, database design, SQL basics, and integration with PHP, Perl, and Java. The content is structured with chapters that guide readers through different aspects of using MySQL effectively.

Uploaded by

bedialevkoeb
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
100% found this document useful (1 vote)
20 views

Download ebooks file MySQL Learn MySQL the Quick and Easy Way 2nd edition Edition Ullman all chapters

The document provides information about various MySQL-related ebooks available for download on ebookgate.com, including titles like 'Learn MySQL the Quick and Easy Way' and 'PHP and MySQL Web Development'. It also includes details about the Visual QuickStart Guide for MySQL by Larry Ullman, which covers installation, database design, SQL basics, and integration with PHP, Perl, and Java. The content is structured with chapters that guide readers through different aspects of using MySQL effectively.

Uploaded by

bedialevkoeb
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/ 80

Get the full ebook with Bonus Features for a Better Reading Experience on 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 HERE

DOWLOAD NOW

Download more ebook instantly today at https://ebookgate.com


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
Running MySQL

✔ Tips
■ If, while running the MySQL Server
Instance Configuration Wizard (Figure 2.1),
you opted to include the bin directory in
the Windows PATH, then you can start
MySQL by just using mysqld --console.
This will be true no matter what directory
you are currently in (within the console
window).
■ Technically, on Windows, you could go
straight into the bin directory and run
your commands from there. The syntax
demonstrated in the preceding steps is
common on other operating systems, so
I’ve used it for consistency’s sake.
■ If you don’t use the --console option
when starting MySQL, all output will be

Running MySQL on Windows and Windows NT


written to an error log. This is fine, if not
preferred, normally, but it’s best to use
the --console option the first couple
times you start the server to make sure
there are no problems. The error log
would be stored in the data directory
(C:\Program Files\MySQL\MySQL Server
5.0\data, by default), with a .err exten-
sion. It is readable in any text editor.
■ You may be able to invoke the mysqlshow
and mysqladmin applications without
specifying a user at all, but I think it’s
best to be explicit.

29
Chapter 2

Running MySQL as a service


on Windows
If you are using an NT version of Windows,
which covers Windows NT, 2000, 2003, XP,
and probably all future versions as well, you
can run MySQL as a service. As a service,
MySQL can be controlled in two ways: by
Figure 2.8 Starting and stopping the MySQL service
typing commands in a console window or by on Windows XP.
using the Windows Service Control Manager.
If you would prefer to use the first method,
access a DOS prompt (using the Steps 3–5 in
the preceding set of instructions) and then
enter NET START MySQL to start the service or
NET STOP MySQL to stop it (Figure 2.8). You
can do this no matter what directory you are
currently in (in the console window). If MySQL
will not start for some reason, you’ll need to
check the error log, found in the MySQL
Running MySQL on Windows and Windows NT

data directory, with a name ending in .err.


This is viewable in any text editor.
The other way you can control the MySQL
service is to use Windows’ built-in Services
utility. I’ll run through that process now, but
the steps do assume that MySQL has been Installing MySQL as a Service
installed as a service (see the sidebar). The The easiest way to install MySQL as a
instructions I’ll use will apply to Windows service is to check the right box during
XP; you may need to make slight adjustments the configuration process (see Figure 2.1).
if you are using a different version of the If MySQL is not already installed as a
operating system. service, you’ll have to use a console win-
dow. Bring one up and move into the
MySQL installation directory (using Steps
3–6 in the preceding section of this chap-
ter). At the prompt type
bin\mysqld --install
and press Enter.
If you would like MySQL to be available as
a service but not have it automatically start
and stop, you can use the --install-manual
option instead. In such a case, you would
use NET START MySQL and NET STOP MySQL
to control it. To remove the MySQL service,
use mysqld --remove at the DOS prompt.

30
Running MySQL

To start and stop the MySQL service:


1. Click Start to bring up the Start menu.
2. Select Control Panel.
This brings up the Control Panel window.
3. Double-click the Administrative Tools
Control Panel.
If you are in the Classic view in Windows
Figure 2.9 The Windows XP Control Panel, in Classic XP (Figure 2.9), the Administrative Tools
view. Double-click Administrative Tools here.
is immediately available. If you are in the
Category view (Figure 2.10), you must
first click Performance and Maintenance
and then click Administrative Tools.
4. In the Administrative Tools window
(Figure 2.11), double-click Services.
continues on next page

Running MySQL on Windows and Windows NT


Figure 2.10 The Windows XP Control Panel, in Category
view. Click Performance and Maintenance here.

Figure 2.11 The Windows list of shortcuts to


Administrative Tools like Services.

31
Chapter 2

5. In the Services window, click MySQL


(Figure 2.12) to select it.
In this window you can see every avail-
able service. The current status of each
is listed, along with its startup type
(Automatic, Manual, Disabled).
6. Start the service. Figure 2.12 You can control the MySQL service using
this Windows tool.
You can either click the Start link (found
to the left of the list of services, see
Figure 2.12) or click the right-pointing
triangle at the top of the window (which
looks like a Play button).
7. Stop the service.
With the service started, you can either
click the Stop link (Figure 2.13) or use the
square button at the top of the window.
Figure 2.13 The links of options change when a
✔ Tips service is running (compare with Figure 2.12).
Running MySQL on Windows and Windows NT

■ It’s recommended that you keep the


Services window closed when installing
MySQL or using NET START MySQL or NET
STOP MYSQL commands.

■ If you right-click the MySQL service and


select Properties from the contextual
menu, you’ll be able to tweak the MySQL
service in other ways (Figure 2.14). You
can adjust which version of mysqld is
started by the service (see the Path to
executable setting), change the Startup
type, and so on.

Figure 2.14 Each service has a list of properties that


can be adjusted as warranted.

32
Running MySQL

Running MySQL on
Mac OS X
On Mac OS X, there are a handful of ways
to get MySQL running. For starters, there
is an optional System Preferences panel
(Figure 2.15) that handles the task nicely.
There is also the choice of having MySQL
automatically start when you turn on your
Figure 2.15 MySQL on Mac OS X comes with a System computer. You can enable this feature by
Preferences panel that can be used to stop and start
the database server.
checking the box in the System Preferences
panel or by installing the MySQL Startup
Item when you installed MySQL (see the
instructions in Chapter 1). With the Startup
Item, you can use the information presented
in the sidebar to also control MySQL.

Using the Startup Item


The Startup Item is a simple shell script that provides a shortcut for starting and stopping
MySQL. In fact, the hardest thing about using the Startup Item is finding where it was

Running MySQL on Mac OS X


installed in the first place. Depending upon your versions of OS X and MySQL, the full path
and script name will most likely be one of the following:
◆ /System/Library/MySQL/MySQL

◆ /System/Library/MySQLCOM/MySQLCOM

◆ /Library/MySQL/MySQL

◆ /Library/MySQLCOM/MySQLCOM

Once you confirm its location (just use the Finder to hunt around), you can start and stop
MySQL using the proper commands within a Terminal window. These would be simply
sudo /path/to/script start
and
sudo /path/to/script stop

(You have to run them using sudo; you will then be prompted for your Mac OS X administra-
tive password.)
For example, in two test environments I have—MySQL 4.1.13 on Mac OS X 10.4 Server and
MySQL 5.0.18 on Mac OS X 10.3 Server—I use
sudo /System/Library/StartupItems/MySQL/MySQL start

If there’s a problem, an error message will be displayed, and the Terminal will seem to sit
there. In that case, press Enter to get a prompt again. Voilà! That’s all there is to it!

33
Discovering Diverse Content Through
Random Scribd Documents
55 The Romans compel the Parthians to evacuate Armenia.
58 Vologases again attacks Armenia and brings on war with
Rome. Revolt of Hyrcania. Corbulo destroys Artaxarta
and occupies Tigranocerta (59).
61 Peace restored in Hyrcania.
62 War with Rome resumed. The Romans are repulsed.
63 Corbulo crosses the Euphrates, and the Parthians sue for
peace.
72 The Alani drive Pacorus of Media from his throne.
75 The Alani enter Parthia. Vologases appeals in vain to
Vespasian.
78 About this date Vologases dies. He seems to have been
succeeded by two kings, Vologases II and Pacorus
II, probably brothers, and reigning together.
81 Artabanus IV appears to be the king in this year. He
protects Terentius Maximus, who pretends to be Nero.
Parthia is torn with civil wars.
93 Pacorus II is sole king.
110 Pacorus sells the crown of Edessa to Abgar VII. Death of
Pacorus. His brother (or perhaps son) Chosroes or
Osroes succeeds. Vologases II reappears as a rival
king, also a Mithridates or Meherdates VI. Parthia is
completely upset with civil war which goes on until
113 Chosroes wrests Armenia from King Exedares and gives
it to Parthamariris, both sons of Pacorus.
114 The emperor Trajan, indignant at Chosroes’ act, seizes
Armenia and makes it a Roman province.
115 Trajan takes Ctesiphon and Seleucia.
116 Revolt in Parthia with Mithridates VI at its head. Death
of Mithridates, and his son Sinatruces takes his place.
Chosroes regains Nisibis, Seleucia, and Edessa.
117 Trajan crowns Parthamaspates king of Parthia,
deposing Chosroes. Death of Trajan. Hadrian withdraws
Roman soldiers and Chosroes recovers throne.
Parthamaspates expelled.
130 About this date Chosroes dies and Vologases II rules as
sole king. The influence of Rome preserves peace in the
kingdom.
148 Death of Vologases, aged ninety-six, having reigned
seventy-one years. Vologases III succeeds. He
continues the peace with Rome until,
162 when, after death of Antoninus Pius, Vologases enters
Armenia and expels the king. The greatest war between
Rome and Parthia ensues.
164 Aridius Cassius drives Vologases from Syria, enters
Babylonia, and burns Seleucia, the most important city
of the East.
165 Great plague, originating in Parthia, spreads over the
whole world.
166 Peace with Rome. Mesopotamia becomes a Roman
province. Parthia begins steadily to decline.
191 Death of Vologases III. Vologases IV succeeds.
194 Vologases permits the Medes to assist Orrhœne in revolt
against the Romans.
196 The Parthians ravage Mesopotamia.
199 Severus surprises the Parthians and takes Seleucia,
Coche, and Ctesiphon.
201 Siege of Atra by Severus, who is compelled to raise it.
209 Vologases succeeded by his son, Vologases V.
213 His brother, Artabanus (IV), appears as a claimant of
the throne. Civil war.
215 Caracalla demands the surrender of Tiridates, brother of
Vologases IV, who has taken refuge with Vologases V.
The latter refuses to give him up. Caracalla declares
war, and the exile is delivered up. Artabanus gains the
upper hand and holds Ctesiphon. Caracalla declares war
on Artabanus on the latter’s refusal to give his daughter
to the Roman emperor.
216 The Romans penetrate to Arbela.
217 On death of Caracalla an immense Parthian force
invades Mesopotamia. Macrinus defeated and purchases
peace.
222 Artabanus replaces his brother over the whole of
Parthia.
224 Ardashir, the Sassanian king of Persis (or Persia),
invades Parthia, taking several cities.
227 Battle of Hormizdjan. Victory of Ardashir and death of
Artabanus.
228 Ardashir completes his conquest. End of the Parthian
empire.

THE EMPIRE OF THE SASSANIDS (228-651 a.d.)

While the Arsacids were ruling their kingdom and lording it


over the minor kings of the neighbouring country, the
rulers of Persis (or Persia proper) seem to have
occupied an isolated position and not been included in
the Parthian empire. At the beginning of the third
century a.d. the kings of Persia have lost all power of
keeping the empire together; all the land is ruled by a
number of local potentates. One of these is Pabak, son
and descendant of a certain Sasan of Khir. Pabak
conquers considerable territory beyond his own
dominions. On his death the succession of Shapur or
Sapor, the eldest son, is disputed by Ardashir, a younger
son. Sapor dies suddenly and Ardashir puts his other
brother to death, and settles himself on his throne in
211 or 212 a.d. About 224 he invades the land of the
“great king” Artabanus IV of Parthia, and by 228 the
conquest is complete and the title of “great king”
devolves upon Ardashir. He makes his capital at
Ctesiphon.
228 Foundation of the Sassanian empire by Ardashir or
Artaxerxes. He passes his reign in extending and
consolidating his empire.
236-238 War with Rome. Nisibis and Carrhæ taken.
241 Death of Ardashir. His son Shapur or Sapor I
succeeds.
242 Sapor penetrates to Antioch but is driven back by the
Romans.
244 Philippus concludes a humiliating peace with Sapor.
Peace reigns until
251 when Sapor invades Armenia and puts the king to flight.
The Persians now make repeated invasions of Syria.
258 The Roman emperor Valerian takes the field against the
Persians.
260 Capture of Valerian by Sapor. He proceeds towards Asia
Minor but is repulsed by Odenathus, king of Palmyra,
who lays siege to Ctesiphon. Sapor acquires no
permanent gain of territory. In his reign Mani preaches
his doctrines tending to the amalgamation of
Christianity and Zoroastrianism, and leading to the
formation of the Manichæan sect.
272 or 273 Sapor succeeded by his son Hormuz (Hormizd)
or Hormisdas I.
274 Death of Hormuz and accession of his brother (?)
Bahram or Varanes I—a weak prince, given to
pleasure. Mani executed in his reign. Persecution of the
Manichæans and Christians.
277 Bahram or Varanes II succeeds his father. He wars
with Rome, ending
282 with a peace with Probus.
283 After murder of Probus, Carus invades Persia, takes
Ctesiphon and Coche, and dies suddenly. There are civil
wars, probably led by a brother of the king, assisted by
the barbarous tribes in the northwest.
294 Death of Bahram. The throne seems to be contested by
Bahram or Varanes III, probably a son of Hormuz,
who reigns a short time, and Narses or Narseh, who
soon gains the upper hand.
297 Narseh occupies Armenia and defeats the Roman
general Galerius.
298 Peace with Rome after a great defeat of Narseh by
Galerius. Armenia and Mesopotamia ceded to Rome.
Peace lasts forty years.
303 Abdication of Narseh in favour of his son Hormuz II.
310 Death of Hormuz. His son Adharnarseh succeeds, but
is soon deposed for cruelty. His brothers are killed or
imprisoned and the new born (or unborn) son of
Hormuz, Shapur or Sapor (II) Postumus is chosen
king. He proves to be the greatest of the Sassanians.
337 Sapor begins a long war with Rome, owing to the latter
becoming Christianised.
339-340 Terrible persecution of the Christians in Persia. The
war with Rome continues. Sapor aims to seize Nisibis
and reduce Armenia.
348 Great defeat of the emperor Constantius at the battle of
Singara.
350 Sapor almost succeeds in capturing Nisibis when
troubles with the barbarians in the East compel him to
raise the siege.
350-358 War in the East causes almost complete suspension
in the conflict with Rome.
358 Peace made in the East and Romans sue for peace.
Sapor declines and war is continued.
359 Sapor captures Amida, but the Romans regain it the
following year. Hostilities are suspended until
363 when the emperor Julian attempts to strike a death-
blow at Sapor. He takes Seleucia but fails to capture
Ctesiphon. Death of Julian in battle. His successor
Jovian makes a shameful peace with Sapor, granting
him the lands east of the Tigris, and part of
Mesopotamia with Nisibis and Singara. The Romans also
agree not to help Arsaces of Armenia, and Sapor
proceeds against him.
365-366 Reduction of Armenia and Iberia by Sapor.
371 The Romans attempt to recover Armenia, but fail
through breaking out of the Gothic war.
379 Death of Sapor, succeeded by his brother Ardashir II.
383 or 384 Ardashir deposed by the nobles towards whom
he has been very severe. Shapur or Sapor III,
probably a son of Sapor II, raised to the throne. He
makes a definite treaty of peace with Rome.
388 or 389 Murder of Sapor by the nobles. His brother (or
perhaps son) Bahram or Varanes III succeeds.
390 Division of Armenia between Persia and Rome by treaty.
The division practically lasts until Arab times.
399 Assassination of Bahram. Yezdegerd or Jezdegird (I)
the Sinner, son of Sapor I or Sapor II, succeeds. He is
friendly to Rome, and Arcadius appoints him the
guardian of his son Thedorius. He sets his son Sapor on
the throne of Pers-Armenia.
420 Death of Yezdegerd, probably slain by the nobles. Sapor
hurries from Armenia to take throne, but is slain. A
certain Khosrau or Chosroes is made king, but another
son of Yezdegerd, Bahram or Varanes (V) the Wild
Ass, succeeds in getting the throne, with the help of
the Arabs, among whom he has been living in exile. This
is the first intervention of the Arabs in the affairs of
Persia.
421 War breaks out with Rome, probably instigated by the
nobles hostile to the king. Persians defeated, and
422 peace is made, giving religious freedom to Christians in
Persia, and to Zoroastrians in the Roman Empire. There
is constant warfare with Hephthalites or White Huns
during this reign.
429 Bahram reduces Pers-Armenia to a province.
438 or 439 Bahram succeeded by his son, Yezdegerd II,
who is cruel to the Jews and Christians. He suffers
severe defeats from the White Huns.
451 A severe rebellion, due to religious persecutions, breaks
out in Pers-Armenia, and is quelled with difficulty.
457 Death of Yezdegerd, and contest for the throne,
between his two sons, Hormuz III and Peroz or
Peroses. The latter is finally successful, owing to
assistance from the White Huns. Peroz persecutes Jews
and Christians, but favours the Nestorians, when they
are driven from Rome.
484 Defeat and death of Peroz in a great battle with the
White Huns, with whom he has been at war for some
years. Revolt in Armenia put down by Zarmihr. Balash,
Peroz’s brother, made king. He puts his brother, Zareh, a
claimant of the throne, to death.
488 or 489 Balash deposed by the nobles, and blinded.
Kavadh I or Kobad, son of Peroz, succeeds him.
Kobad favours Mazdak and his new communistic
religion, and in consequence
496 is deposed and imprisoned. His brother, Jamasp or
Zames, is placed on the throne. Kobad escapes to the
White Huns, and with their help
498 or 499 recovers his kingdom.
502 Kobad begins an exhausting war with Rome, which
opens the way for the Arabian conquests. He seizes
Theodosiopolis, capital of Roman Armenia.
503 Fall of Amida, and terrible massacre of the inhabitants.
The Romans recover it the following year.
506 Peace concluded with Rome. The Romans build the
great fortress at Dara.
521 War renewed with Rome. Belisarius first comes to the
front as a general. Narses and his brother desert Kobad,
and join the army of Justin.
529 Mundhir of Hira invades Syria. Kobad massacres the
Mazdukites, who have become too powerful.
531 Kobad makes campaign in Syria. Belisarius compels him
to turn back. Defeat of Belisarius at Rakka. Persian
successes in Mesopotamia. Death of Kobad and truce
with Rome. Khosrau or Chosroes (I) the Just, his
son, succeeds. His wise internal government benefits
the kingdom greatly.
532 “A Perpetual Peace” made with Rome.
540 Chosroes, jealous of Belisarius’ conquests in Africa and
Italy, goes to war with the empire. He invades Syria,
Antioch taken, Dara laid under tribute. Ctesiphon is
captured.
541 Chosroes takes Petra in Lazistan.
546 Rome buys a truce for a large sum.
551 The son of Chosroes rebels in Susiana. He is taken and
partially blinded.
560 The Turks take the right bank of the Oxus from the
White Huns. Bactria becomes a part of Chosroes’
kingdom.
562 Fifty years’ peace made with the Romans.
570 Chosroes sends an expedition against the Christian
Abyssinians in Yemen. He puts them under tribute.
571 War breaks out with Rome, over the threatened loss of
Pers-Armenia.
573 Chosroes takes Dara. The war continues.
579 Death of Chosroes, succeeded by his son, Hormuz or
Hormisdas IV. He makes a severe but just ruler. The
war with Rome and a severe one with the Turks fill his
reign.
589 The general Bahram, defeated by the Romans in the
Caucasus. He is removed by Hormuz, and revolts. The
king’s son, Chosroes, joins the rebels.
590 Hormuz is deposed, and shortly afterwards put to death.
His son, Khosrau or Chosroes (II) Parvez, succeeds.
Bahram contests the crown, and seizes it. Bahram or
Varanes VI puts down an insurrection in Ctesiphon.
591 Chosroes recovers the throne, with help of the emperor
Maurice. Bahram flees to the Turks, and is murdered.
Chosroes strengthens his position, and puts his brother,
Bindoe to death. Another brother, Bistam, escapes to
Media and makes himself king.
595 or 596 Death of Bistam.
604 War breaks out with Rome, over usurpation of Phocas.
Dara captured by Chosroes.
606-608 The Persians invade Asia Minor. They advance as far
as Chalcedon.
610 Chosroes abolishes the kingdom of Hira.
614 The Persians capture Damascus.
615 The Persians capture Jerusalem and the holy cross.
616 Persian invasion of Egypt.
617 The Persians occupy Chalcedon.
622 Heraclius proceeds in person against the Persians, and
gradually wins back the Persian conquests.
628 Heraclius reaches Ctesiphon but is unable to take it.
Rebellion in Ctesiphon. Chosroes and most of his family
are slain. His eldest son Kavadh (Kobad) II, or
Siroes, is made king. He murders most of his brothers,
and sues for peace from the Roman Empire. A terrible
pestilence breaks out and Kobad dies. His infant son,
Ardashir III, succeeds. He is the last male Sassanid.
The throne is disputed by many claimants. Chosroes, a
son of Kobad II, makes himself king in Khorasan, but is
soon slain.
629 The holy cross is returned to Heraclius. The general
Shahrbaraz is supported in a claim to the throne by
Heraclius. He takes Ctesiphon.
630 Murder of Ardashir, followed by that of Shahrbaraz.
Boran or Puran, a daughter of Chosroes II, takes the
throne. She makes a treaty with Heraclius.
631 Boran succeeded by Peroz (Peroses) II, who rules but
a short time; then Azarmidokht, sister of Boran, takes
the throne. Hormuz V, grandson of Chosroes II,
maintains a rule over a portion of the country for a
short time.
632 Azarmidokht dethroned by Rustem, hereditary marshal
of Khorasan. Ferrukhzadh reigns a short time in
Ctesiphon.
632 or 633 Yezdegerd III, grandson of Chosroes II, is put
forward by some of the nobles and crowned.
Ferrukhzadh is slain and Yezdegerd acknowledged as
sole king. He declines to accept the Mohammedan
religion at invitation of Abu Bekr, and the Moslems
invade Persia.
636 Persian defeat by the Moslems at Cadesia, or Kadisiya.
640 or 642 The “Victory of Victories” by the Arabs over the
Persians at Nehavend. The last great Persian army is
shattered. The nobles gradually yield to the Arab chiefs.
Yezdegerd is driven from place to place, continually
shorn of more and more power until he is murdered in
651, and Persia becomes part of the Mohammedan
dominions.

THE ARABS

THE PRE-MOHAMMEDAN ERA

Before the Mohammedan conquests, Arabia is divided into a


number of local monarchies. In these we recognise two
distinct origins.
(1) Those ruled by a race of southern origin—the genuine or
Kahtanee Arabs. Their monarchies form a rim around
the wild and desert centre of the peninsula.
(2) The centre of Arabia is occupied by nomadic races—the
Mustareb Arabs, of northern origin, descendants of a
mythical Adnan.

THE KAHTANEE KINGDOMS (ca. 380 b.c.-634 a.d.)

The kingdom of Yemen is the most important and powerful


of these. It occupies a portion of the ancient Arabia
Felix. Descendants of Kahtan and Himyar—names of
African origin—its monarchs rule over the whole of
southern Arabia from about 380 b.c., with but few
interruptions. The capital is first at Mareb and then at
Sana. The northern kingdoms are more or less tributary.
The Persians, Greeks, and Macedonians make no
attempts upon Arabia, if we except the frontier
skirmishes of Antigonus and Ptolemy. Rome had an eye
to its conquest. Pompey, the first to attempt it, is foiled,
and it was not until
b.c.

25 when Ælius Gallus, the prefect of Egypt, undertakes an


expedition at the command of Augustus. His army is
unable to support the hardships of the desert, and the
following year the Arabs drive the remnant out. Later
attempts under Trajan and Severus do not succeed
beyond the frontier, and Bosrah and Petra mark the
extreme limits of Roman dominion.
a.d.

100 Probable date of the great flood of Arem or Mareb,


which leads to the foundation of other Arab kingdoms.
529 The Abyssinians, under Aryat, invade Yemen, to avenge
the Christians persecuted by Dhu-Nowas the king.
Dhu-Nowas is killed, and the Abyssinians rule the
kingdom until
605 when Saif, with the assistance of Chosroes the Great,
restores the Kahtanee dynasty, but it becomes
dependent on Persia.
634 Mohammedan conquest of Yemen.

THE KINGDOM OF HIRA (195-610 a.d.)

Next in importance to Yemen. It is situated in Irak. Founded


about 195 a.d. by Malik, it is more or less under
allegiance to the Persians, but exercises considerable
control over the Mustareb Arabs.
529 Mundhir III, king of Hira, who has been driven from
the throne by Kavadh I of Persia, because he is too
powerful, invades Syria, cruelly ravaging the country as
far as Antioch. He kills Harith, whom Kavadh has set
over his kingdom, and is finally himself killed, in 554, by
a Roman vassal.
610 Chosroes II puts an end to the kingdom of Hira.

THE KINGDOM OF GHASSAN (300-636 a.d.)

Founded about 300 by Thalaba, the first to take the name


of king. His successors rule until 636, when Djabala VI
surrenders to the Mohammedans.

THE KINGDOM OF KINDEH

A small kingdom, of Yemenite origin, which detaches itself


from Irak in the fifth century a.d. and maintains its
existence for about 160 years, when it is absorbed by
the Mustarebs.

THE MUSTAREB KINGDOMS

The northern tribes inhabiting central Arabia, or Arabia


Petræa, become consolidated into five kingdoms:
Rabiah, in the east centre of the peninsula.
Kais, or Kais-Ailan, in the north.
Hawazin, in the north.
Tamin, in the middle.
They are, from the time of their foundation, more or less
tributary to Yemen until
500 They make themselves independent, under the
leadership of Kolaib, who now tries to unite his people
in a single confederacy, but the plan is frustrated by his
assassination. The tribes now lead a warlike,
disorganised existence, encroaching slowly upon the
Kahtanee kingdoms. During this period the tribe of
Koreish becomes prominent. Tradition assigns their
origin to Ishmael, and they have become the guardians
of the sacred Kaaba. This gives them pre-eminence over
all other Arabian clans, and at the beginning of the
seventh century a.d. the tribe of Koreish and its
Mustareb allies is the most powerful confederacy in
Arabia, the Kahtanee kingdoms having become more or
less vassals of the Persian and Byzantine empires.

THE KINGDOM OF NABATÆA

The Nabatæans are a famous people of ancient Arabia.


Secure knowledge of their history goes back only to 312
b.c., when Antigonus failed to take their fortress of
Petra. They are described by Diodorus as a pastoral and
trading people, preserving their liberty in the arid
country of Arabia Petræa. At the fall of the Seleucids
they extend their territory over the fertile country east
of the Jordan. They occupy the Hauran. Pompey
reduces them to vassalage, and in 105 a.d. Trajan takes
Petra and breaks up the Nabatæan nation.

MOHAMMED AND HIS SUCCESSORS (570-661 a.d.)

ca. 570 Birth of Mohammed, of a noble Koreish family, at


Mecca.
605-610 Years of meditation, during which the principles of
Mohammedanism are developed.
610 Year of the “call,” Mohammed begins to make converts.
Opposition to his doctrines increases among the
Meccans until
622 he flees with a body of followers to Medina. The Hegira.
Beginning of the Mohammedan era.
623 The first mosque built. Mohammed becomes a warrior.
624 First battle for the faith with the Meccans at Bedr.
Victory of Mohammed.
625 Battle of Ohod, and victory of the Meccans.
627 War of the Fosse. The Koreish make terms with
Mohammed.
628 War against the Jews of Khaibar.
629 War against the Greek subjects in Arabia.
630 Mohammed moves against Mecca. He conquers it. War
with the Hawazin. Rapid spread of Islam.
632 Death of Mohammed. He leaves the entire peninsula,
with the exception of a few tribes, under one sceptre
and one creed. His father-in-law, Abu Bekr, is chosen
caliph, or representative. An army under Khalid sets out
against the Byzantine Empire. Abu Bekr reduces a revolt
in Nejd and Yemen, and defends Medina.
633 Khalid, on the lower Euphrates, is called to Syria.
634 Khalid captures Bosrah and overruns the Hauran. Death
of Abu Bekr. Omar succeeds.
635 Capture of Damascus.
636 Emesa, Heliopolis, Chalcis, Berœa, and Edessa added to
the Mohammedan empire. Battle of the Hieromax
(Yermuk). Heraclius abandons Syria to the Moslems.
637 Battle of Cadesia, or Kadisiya, and victory over the
Persians. Omar captures Jerusalem, and follows it up by
taking Aleppo and Antioch.
638 Mesopotamia is conquered by the Mohammedans, also
Tarsus and Diar-Bekr.
639 Invasion of Egypt by Amru.
641 Battle of Nehavend, and great victory of the
Mohammedans over the Persians. Most of the Persian
nobility come to terms with the Mohammedans.
Yezdegerd the king flees to a remote corner of the
realm, where he holds a vestige of power until 651 or
652. Alexandria captured.
644 Death of Omar, succeeded by Othman, a weak ruler,
who allows the power to fall into the hands of the
Koreish nobility.
647 Invasion of Africa by Abdallah. Arabian victories,
expelling the Romans.
649 Invasion of Cyprus.
650 Conquest of Aradus.
652 Conquest of Armenia.
654 Conquest of Rhodes.
655 Defeat of the emperor Constans by the Mohammedans
in naval battle off Mt. Phœnix in Lycia.
656 Murder of Othman by a party in opposition to the
growing worldliness of Islam. Ali, of the opposition, and
son-in-law of Mohammed, succeeds. Battle of the
Camel. Ali victorious over his opponents. Moawiyah,
governor of Syria, heads the opponents of Ali, and
incites them to revenge.
657 Ali invades northern Syria. Battle of Siffin. The theocratic
faction rebels against Ali.
658 Decision of the umpires, Ali and Moawiyah; the latter
wins. Peace made with the Byzantine Empire. Egypt
conquered for Moawiyah.
660 Truce between Ali and Moawiyah, dividing the caliphate
into the East and West divisions.
661 Kharejite conspiracy to murder Ali, Moawiyah, and
Amru. The former alone falls. His son Hassan succeeds,
but abdicates in favour of Moawiyah.

THE OMAYYAD DYNASTY (661-750 a.d.)

661 Moawiyah at head of the reunited caliphate. The


opposition to him is gradually reduced. The capital is
removed to Damascus.
662-663 Great invasion of Asia Minor. Death of Amru.
668 Mohammedans advance to Chalcedon and hold
Amorium for a short time.
669 Great invasion of Sicily.
670 Foundation of Kairwan.
673-677 The Mohammedans besiege Constantinople, and
are finally driven off by means of Greek fire.
676 Yazid, son of Moawiyah, is appointed heir-apparent.
Hereditary nomination becomes a precedent.
678 Thirty years’ peace made with Constantine IV of
Constantinople.
680 Death of Moawiyah. Yazid I succeeds. The Ali faction
refuse recognition. Hosein, son of Ali, and his company
slain.
681 Abdallah ben Zobair proclaims himself caliph.
683 Rebellion and sack of Medina. The cause of Ibn Zobair
grows. He maintains a rival court at Mecca, and rebuilds
the Kaaba.
684 Death of Yazid. His weak son, Moawiyah II, reigns but
a few months. Merwan elected to succeed.
685 Death of Merwan. His son, Abdul-Malik, succeeds.
Peace with the emperor Justinian II.
685-687 Rebellion of Mukhtar. He is defeated and slain.
689 Abdul-Malik has Amru put to death.
692 Death of Ibn Zobair. The Omayyad rule is recognised
without dispute.
692-693 The Mohammedans ravage Asia Minor and Armenia,
but are compelled to accept peace.
695 The peace is broken. Arabic coinage first substituted for
that of the Byzantine Empire.
697-698 Hassan’s invasion of Africa. Carthage taken. The
last remnants of the Roman Empire disappear from the
southern shore of the Mediterranean.
705 Death of Abdul-Malik and succession of his brother,
Walid I, already designated as heir to the caliphate. His
reign marks the culminating glory of the Omayyads.
Schools founded, and public works of all kinds
promoted.
709 Conquest of Tyana by the Mohammedans.
711 Invasion of Spain at instigation of Julian, governor of
Ceuta. Battle of Xerxes. Tarik destroys the Visigothic
kingdom.
712 The Mohammedans take Antioch in Pisidia. In these
years great success of the generals Kotaiba and
Muhammed b. Kasim in Asia.
715 Death of Walid and accession of Suleiman, the
predesignated heir.
716 The Mohammedans invade Asia Minor. Siege of
Amorium. The town is relieved by Leo the Isaurian.
717 Siege of Pergamus. Siege of Constantinople. Death of
Suleiman. The appointed heir Omar II, grandson of
Merwan I, succeeds.
718 Repulse of the Mohammedans from Constantinople. In
revenge the caliph excludes all Christians from service in
the state. Omar’s reign is not distinguished by any
important warlike events. It marks the beginning of the
Abbasid movement in favour of the descendants of
Abbas, uncle of the prophet, acquiring the caliphate.
720 Death of Omar. Yazid II, son of Abdul-Malik, succeeds.
Yazid b. Muhallab, who has been in disgrace for some
years, collects a small army and takes Basra (Bassora).
721 Death of Ibn Muhallab in battle. The Mohammedans
cross the Pyrenees and capture Narbonne, but, defeated
at Toulouse, they retire under Abd ar-Rahman.
724 Death of Yazid. His son Hisham, the appointed heir,
succeeds. He is a severe and pious ruler.
725 Abbasid revolt at Balkh. Abbasid troubles continue.
726 The Mohammedans invade Cappadocia.
734 Mohammedan invasion of Asia Minor.
737 Peace restored in the Abbasid faction.
739 Great Moslem defeat by the Byzantines at Acroinon.
Death of Sid (Said) al-Battal. The Saracen power ceases
to be formidable to the empire.
743 Death of Hisham. His nephew, Walid II, succeeds.
Walid’s debaucheries and irreligion make him hated.
Yazid, son of Walid I, assumes title of caliph, and is
received at Damascus, in absence of Walid.
744 Death of Walid in battle with his rival. Yazid III
succeeds. Signs of disintegration become marked. Abd
ar-Rahman b. Muhammed declares himself independent
in Africa. Revolt of Emesa over Walid’s death, and
defeat of rebels at Eagle’s Pass. Merwan, Yazid’s
grandfather, attempts to obtain caliphate. Yazid makes
him governor of Mesopotamia. Death of Yazid, after
reign of six months. His brother, Ibrahim, succeeds.
Merwan marches against Damascus. Ibrahim flees, after
reign of two months, and Merwan II is acknowledged
caliph.
746 Mohammedan invasion of Cyprus.
750 As a result of the ferment in the eastern part of the
empire, the Abbasid Abul-Abbas assumes title of caliph.
War between Omayyads and Abbasids. Battle of the
Zab. Defeat of Merwan, and downfall of the Omayyad
dynasty.

THE ABBASID DYNASTY (750-1258 a.d.)


750 Abul-Abbas established in the caliphate. He has all the
Omayyad princes (except Abd ar-Rahman b. Moawiyah,
who escapes to Africa) put to death. Revolts break out,
owing to his cruelty, but they are suppressed. Abul-
Abbas fixes his residence at Anbar.
754 Death of Abul-Abbas. He has designated Abu Jafar (Al-
Mansur), his cousin, as his successor. Abdallah b. Ali
revolts, but is defeated at Nisibis. Several risings are
suppressed. Revolt in Africa, which hereafter only
nominally belongs to the caliphs.
755 The Mohammedans in Spain elect Abd ar-Rahman b.
Moawiyah caliph. Spain lost to the Abbasids.
756 Foundation of the western Omayyad caliphate.
756-757 Invasion of Asia Minor. Capture of Malatiya. Defeat
of the Byzantines in Cilicia. Seven years’ truce with the
emperor.
762 Baghdad made the capital of the caliphate.
763 Muhammed Mahdi falls in battle, after having caused
himself to be proclaimed caliph. His brother, Ibrahim,
also revolts, and is killed in battle.
775 Death of Mansur. His son, Muhammed (Al-Mahdi),
succeeds. He busies himself at once with improving
internal conditions and restoring peace. Revolt of Hakim
in Khorasan. Continued invasion of Asia Minor.
780 Capture of Semaluos by Harun ar-Rashid.
782 Renewal of war between Moslems and Byzantines.
Victory for the latter in Cilicia. Harun ar-Rashid takes
command. He marches to the Bosporus, and compels
the empress Irene to pay large yearly tribute.
785 Rebellion of Mahdi’s eldest son, Musa, because Harun is
preferred as heir. Death of Mahdi on his way to crush
the rebellion. Musa, who takes the title Hadi, succeeds.
Rising of Hosein b. Ali suppressed.
786 Hadi attempts to exclude Harun from the caliphate, and
is smothered at instigation of his mother. Harun ar-
Rashid, the most celebrated of the caliphs, succeeds
without opposition.
789 The Arabs invade Rumania.
792-793 Suppression of the party formed by Yahya b.
Abdallah.
797-798 Continued victories over the Byzantines cause the
empress Irene to sue for peace. The Khazars driven out
of Armenia.
800 The Aglabite dynasty founded at Kairwan.
801 Harun sends an embassy to Charlemagne.
802 The emperor Nicephorus refuses to continue payment of
tribute. Harun makes such a devastating invasion of
Asia Minor that Nicephorus sues for peace. He breaks it
the next year, and the same process is repeated.
804-805 Rebellion in Khorasan.
806 Peace renewed with Nicephorus after hostilities have
once more been begun.
808 Edrisite dynasty founded at Fez.
809 Death of Harun on the way to quell disturbances in
Khorasan. His reign is a flourishing period of art and
science. His son, Emin, succeeds. His reign is mostly
taken up with the rebellion of his brother, Mamun, who
gradually wins all the provinces, except Baghdad, to his
side.
813 Capture and assassination of Emin. Mamun proclaimed
at Baghdad. The civil war continues.
817 Mamun appoints Musa b. Ali heir to the throne,
whereupon the people of Baghdad declare Mamun
deposed and elect his uncle, Ibrahim, caliph. Sudden
death of Musa.
820 Appointment of Tahir as governor of Khorasan, where
his descendants rule until 872—sometimes called
Tahirite dynasty.
829 Euphemius invites the Mohammedans from Africa into
Sicily. They take Palermo.
831 The Mohammedans begin a long invasion of Asia Minor.
832 Capture of Heraclea.
833 Death of Mamun. His reign is the Augustan age of
Arabian literature. Works on science and philosophy
translated from the Greek. Mamun orders the
measurement of a degree of the earth’s circumference.
The designated heir, his brother Mutasim, succeeds. A
party in favour of Mamun’s son, Abbas, is put down.
Mutasim employs Turks in his body-guard, and their
excesses cause Baghdad to revolt. The caliph removes
the capital to Samarra.
836 The emperor Theophilus destroys Zapetra in his savage
war on the Moslems.
838 Moslem victory at Dasymon. Amorium captured. Second
revolt of Abbas, who dies in prison.
841 Death of Mutasim. His son, Wathik, succeeds. The
caliphate begins to decline.
845 Truce with the empress Theodora.
847 Death of Wathik. The state officials elect his son,
Muhammed, to succeed, but immediately recall their
choice and substitute Wathik’s brother, Mutawakkil. He
is noteworthy for his atrocious cruelty, and persecutes
the Jews and Christians.
852 Serious revolt in Armenia suppressed in four years.
858 A great war with the Byzantines begins in Asia Minor.
The Mohammedans capture the Byzantine commander.
860 Byzantine defeat near Melitene.
861 Murder of Mutawakkil by his Turkish guard, bribed by his
son, Muntasir, who takes the caliphate.
862 Death of Muntasir, probably by poison. His cousin,
Akhmed, who takes name of Mustain, is chosen to
succeed by the Turkish soldiery.
863 Great victory of the Byzantines over the Moslems at
Amasia. Death of the general, Omar. Peace for some
years results.
866 The Turks revolt against Mustain and choose his brother,
Motazz, caliph. Surrender of Motazz, who is put to
death. He tries to free himself of the yoke of the Turkish
soldiery.
869 The Turks besiege the caliph, who is imprisoned and
dies. Mutahdi, son of Wathik, is chosen caliph. He tries
in vain to reform the empire.
870 Mutahdi slain by the Turks. Mutamid, son of
Mutawakkil, chosen as caliph. He reduces the power of
the Turkish soldiery, and re-establishes capital at
Baghdad.
872 The Tahirites overthrown in Persia, and the Saffarid
dynasty founded. War with Byzantines recommences.
878 Akhmed b. Tulun, governor of Egypt, makes himself
independent, and founds Tulunite dynasty that lasts
until 905.
887-888 Mohammedan invasions of Asia Minor.
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