SKIP THE SHIPPING
Use code NOSHIP during checkout to save 40% on eligible eBooks, now through January 5. Shop now.
Register your product to gain access to bonus material or receive a coupon.
A new edition of this title is available, ISBN-10: 0672329387 ISBN-13: 9780672329388
For years, MySQL has been helping MySQL developers and database administrators learn their MySQL system inside and out. This newest edition has been updated to include information on MySQL 5 and it will prove itself again to you as being the most definitive reference guide to using, administering and programming MySQL databases. You'll learn everything from the basics to using MySQL to generate dynamic web pages to administering MySQL servers. This edition has been reviewed by the top developers in the MySQL community and the changes reflect their feedback, as well as the feedback of many other readers, and it has turned out to be the most comprehensive, thorough edition of MySQL to date. Don't go to work without it!
Paul DuBois maintains a book companion web site where you can find the latest code samples, errata, and general information for MySQL, Third Edition. Please go to www.kitebird.com/mysql-book/ to access the book companion web site.
Getting Started with MySQL and SQL
Getting Started with MySQL and SQL
Introduction.
Why Choose MySQL?
Already Running Another RDBMS?
Tools Provided with MySQL.
What You Can Expect from This Book.
Road Map to This Book.
Part I: General MySQL Use.
Part II: Using MySQL Programming Interfaces.
Part III: MySQL Administration.
Part IV: Appendixes.
How to Read This Book.
Versions of Software Covered in This Book.
Conventions Used in This Book.
Additional Resources.
1. Getting Started with MySQL and SQL.
How MySQL Can Help You.
A Sample Database.
The U.S. Historical League.
The Grade-Keeping Project.
How the Sample Database Applies to You.
Basic Database Terminology.
Structural Terminology.
Query Language Terminology.
MySQL Architectural Terminology.
A MySQL Tutorial.
Obtaining the Sample Database Distribution.
Preliminary Requirements.
Establishing and Terminating Connections to the MySQL Server.
Executing SQL Statements.
Creating a Database.
Creating Tables.
Adding New Records.
Resetting the sampdb Database to a Known State.
Retrieving Information.
Deleting or Updating Existing Records.
Tips for Interacting with mysql.
Simplifying the Connection Process.
Issuing Statements with Less Typing.
Where to Now?
2. MySQL SQL Syntax and Use.
MySQL Naming Rules.
Referring to Elements of Databases.
Case Sensitivity in SQL Statements.
The Server SQL Mode.
Character Set Support.
Character Set Support Before MySQL 4.1.
Character Set Support in MySQL 4.1 and Up.
Selecting, Creating, Dropping, and Altering Databases.
Selecting Databases.
Creating Databases.
Dropping Databases.
Altering Databases.
Creating, Dropping, Indexing, and Altering Tables.
Storage Engine Characteristics.
Creating Tables.
Dropping Tables.
Indexing Tables.
Altering Table Structure.
Getting Information About Databases and Tables.
Performing Multiple-Table Retrievals with Joins.
The Trivial Join.
The Cross Join.
Left and Right Joins.
Performing Multiple-Table Retrievals with Subqueries.
Subqueries with Relative Comparison Operators.
IN and NOT IN Subqueries.
ALL, ANY, and SOME Subqueries.
EXISTS and NOT EXISTS Subqueries.
Correlated Subqueries.
Subqueries in the FROM Clause.
Rewriting Subqueries as Joins.
Performing Multiple-Table Retrievals with UNION.
Multiple-Table Deletes and Updates.
Performing Transactions.
Using Transactions to Ensure Safe Statement Execution.
Using Transaction Savepoints.
Transaction Isolation.
Non-Transactional Approaches to Transactional Problems.
Foreign Keys and Referential Integrity.
Living Without Foreign Keys.
Using FULLTEXT Searches.
Natural Language FULLTEXT Searches.
Boolean Mode FULLTEXT Searches.
Query Expansion FULLTEXT Searches.
Configuring the FULLTEXT Search Engine.
New Features in MySQL 5.0.
Using Views.
Using Stored Procedures.
Using Triggers.
3. Working with Data in MySQL.
Categories of Data Values.
Numeric Values.
String Values.
Date and Time (Temporal) Values.
Spatial Values.
The NULL Value.
MySQL Data Types.
Overview of Data Types.
Defining Column Types in Table Definitions.
Specifying Column Default Values.
Numeric Data Types.
String Data Types.
Date and Time Data Types.
Spatial Data Types.
How MySQL Handles Invalid Data Values.
Working with Sequences.
General AUTO_INCREMENT Concepts.
AUTO_INCREMENT Handling Per Storage Engine.
Issues to Consider with AUTO_INCREMENT Columns.
Tips for Working with AUTO_INCREMENT Columns.
Generating Sequences Without AUTO_INCREMENT.
Choosing Data Types.
What Kind of Values Will the Column Hold?
Do Your Values Lie Within Some Particular Range?
What Are the Performance and Efficiency Issues?
Inter-Relatedness of Data Type Choice Issues.
Expression Evaluation and Type Conversion.
Writing Expressions.
Type Conversion.
4. Query Optimization.
Using Indexing.
Benefits of Indexing.
Costs of Indexing.
Choosing Indexes.
The MySQL Query Optimizer.
How the Optimizer Works.
Using EXPLAIN to Check Optimizer Operation.
Overriding Optimization.
Data Type Choices and Query Efficiency.
Loading Data Efficiently.
Scheduling and Locking Issues.
Changing Statement Scheduling Priorities.
Using Delayed Inserts.
Using Concurrent Inserts.
Locking Levels and Concurrency.
Optimization for Administrators.
Using MyISAM Key Caches.
Using the Query Cache.
Hardware Issues.
5. Introduction to MySQL Programming.
Why Write Your Own MySQL Programs?
APIs Available for MySQL.
The C API.
The Perl DBI API.
The PHP API.
Choosing an API.
Execution Environment.
Performance.
Development Time.
Portability.
6. Writing MySQL Programs Using C.
General Instructions for Building Client Programs.
Basic System Requirements.
Compiling and Linking Client Programs.
Connecting to the Server.
Handling Errors and Processing Command Options.
Checking for Errors.
Getting Connection Parameters at Runtime.
Incorporating Option-Processing into a MySQL Client Program.
Processing SQL Statements.
Handling Statements That Return No Result Set.
Handling Statements That Return a Result Set.
A General Purpose Statement Handler.
Alternative Approaches to Statement Processing.
mysql_store_result() and mysql_use_result() Compared.
Using Result Set Metadata.
Encoding Special Characters and Binary Data.
An Interactive Statement-Execution Program.
Writing Clients That Include SSL Support.
Using the Embedded Server Library.
Writing an Embedded Server Application.
Producing the Application Executable Binary.
Using Multiple-Statement Execution.
Using Server-Side Prepared Statements.
7. Writing MySQL Programs Using Perl DBI.
Perl Script Characteristics.
Perl DBI Overview.
DBI Data Types.
A Simple DBI Script.
Handling Errors.
Handling Statements That Return No Result Set.
Handling Statements That Return a Result Set.
Quoting Issues.
Placeholders and Prepared Statements.
Binding Query Results to Script Variables.
Specifying Connection Parameters.
Debugging.
Using Result Set Metadata.
Performing Transactions.
Putting DBI to Work.
Generating the Historical League Directory.
Sending Membership Renewal Notices.
Historical League Member Entry Editing.
Finding Historical League Members with Common Interests.
Putting the Historical League Directory Online.
Using DBI in Web Applications.
Setting Up Apache for CGI Scripts.
A Brief Introduction to CGI.pm.
Connecting to the MySQL Server from Web Scripts.
A Web-Based Database Browser.
A Grade-Keeping Project Score Browser.
Historical League Common-Interest Searching.
8. Writing MySQL Programs Using PHP.
PHP Overview.
Using Functions and Include Files.
A Simple Data-Retrieval Page.
Processing Statement Results.
Testing for NULL Values in Query Results.
Handling Errors.
Quoting Issues.
Placeholders and Prepared Statements.
Putting PHP to Work.
Entering Student Scores.
Creating an Interactive Online Quiz.
Historical League Online Member Entry Editing.
9. Introduction to MySQL Administration.
Overview of Administrative Duties.
General Administration.
Security.
Database Repair and Maintenance.
10. The MySQL Data Directory.
Location of the Data Directory.
Structure of the Data Directory.
How the MySQL Server Provides Access to Data.
How MySQL Represents Databases in the Filesystem.
How MySQL Represents Tables in the Filesystem.
How SQL Statements Map onto Table File Operations.
Operating System Constraints on Database and Table Naming.
Factors That Affect Maximum Table Size.
Implications of Data Directory Structure for System Performance.
MySQL Status and Log Files.
Relocating Data Directory Contents.
Relocation Methods.
Assessing the Effect of Relocation.
Relocating the Entire Data Directory.
Relocating Individual Databases.
Relocating Individual Tables.
Relocating the InnoDB Shared Tablespace.
Relocating Status and Log Files.
11. General MySQL Administration.
Securing a New MySQL Installation.
How the Grant Tables Are Set Up Initially.
Establishing Passwords for the Initial MySQL Accounts.
Setting Up Passwords for a Second Server.
Arranging for MySQL Server Startup and Shutdown.
Running the MySQL Server on Unix.
Running the MySQL Server on Windows.
Specifying Server Startup Options.
Stopping the Server.
Regaining Control of the Server When You Can't Connect to It.
Managing MySQL User Accounts.
Creating New Accounts and Granting Privileges.
Displaying Account Privileges.
Revoking Privileges and Removing Users.
Changing Passwords or Resetting Lost Passwords.
Dealing with Changes to Grant Table Structure.
Maintaining Log Files.
The Error Log.
The General Query Log.
The Binary Log and the Binary Log Index File.
The Update Log.
The Slow-Query Log.
The Relay Log and the Relay Log Index File.
Log File Expiration.
Tuning the Server.
Setting and Checking System Variable Values.
General Purpose System Variables.
Storage Engine Configuration.
Selecting Storage Engines.
Configuring the MyISAM Storage Engine.
Configuring the InnoDB Storage Engine.
Controlling How the Server Listens for Connections.
Enabling or Disabling LOCAL Capability for LOAD DATA.
Configuring Backward Compatibility for Password Handling.
Internationalization and Localization Issues.
Configuring Time Zone Support.
Selecting the Language for Error Messages.
Configuring Character Set Support.
Upgrading Older Tables to Enable MySQL 4.1 Character Set Support.
Running Multiple Servers.
General Multiple Server Issues.
Configuring and Compiling Different Servers.
Strategies for Specifying Startup Options.
Using mysqld_multi for Server Management.
Running Multiple Servers on Windows.
Setting Up Replication Servers.
How Replication Works.
Establishing a Master-Slave Replication Relationship.
Updating MySQL.
12. MySQL and Security.
Internal Security: Preventing Unauthorized Filesystem Access.
How to Steal Data.
Securing Your MySQL Installation.
External Security: Preventing Unauthorized Network Access.
Structure and Contents of the MySQL Grant Tables.
How the Server Controls Client Access.
A Privilege Puzzle.
Grant Table Risks to Avoid.
Setting Up MySQL Accounts Without GRANT Statements.
Setting Up Secure Connections.
13. Database Backups, Maintenance, and Repair.
Performing Database Maintenance with the Server Running.
Preventing Interactions Using Internal Locking.
Preventing Interactions Using External Locking.
General Preventive Maintenance.
Using the Server's Auto-Recovery Capabilities.
Scheduling Preventive Maintenance.
Making Database Backups.
Making Backups with mysqldump.
Making Binary Database Backups.
Backing Up InnoDB or BDB Tables.
Making Backups Using a Replication Slave.
Using a Backup to Rename a Database.
Copying Databases to Another Server.
Copying Databases Using a Backup File.
Copying Databases Using a Network Transfer.
Checking and Repairing Database Tables.
Using CHECK TABLE to Check Tables.
Using REPAIR TABLE to Repair Tables.
Using mysqlcheck to Check and Repair Tables.
Using myisamchk to Check and Repair Tables.
Using Backups for Data Recovery.
Recovering Entire Databases.
Recovering Individual Tables.
Re-Executing Statements in Binary Log Files.
Recovering InnoDB Tables That Have Foreign Key Relationships.
Coping with InnoDB or BDB Auto-Recovery Problems.
Appendix A. Obtaining and Installing Software.
Obtaining the sampdb Sample Database Distribution.
Obtaining MySQL and Related Software.
Choosing a Version of MySQL.
Installing MySQL on Unix.
Overview of Unix MySQL Installation.
Creating a Login Account for the MySQL User.
Obtaining and Installing a MySQL Distribution on Unix.
Post-Installation Steps.
Installing Perl DBI Support on Unix.
Installing Apache and PHP on Unix.
Installing MySQL on Windows.
Installing Perl DBI Support on Windows.
Installing Apache and PHP on Windows.
Installing Connector/ODBC on Windows.
Appendix B. Data Type Reference.
Numeric Types.
Integer Types.
Floating-Point Types.
Fixed-Point Type.
BIT Type.
String Types.
Binary String Types.
Non-Binary String Types.
ENUM and SET Types.
Date and Time Types.
Spatial Types.
Appendix C. Operator and Function Reference.
Operators.
Operator Precedence.
Grouping Operators.
Arithmetic Operators.
Comparison Operators.
Bit Operators.
Logical Operators.
Cast Operators.
Pattern-Matching Operators.
Functions.
Comparison Functions.
Cast Functions.
Numeric Functions.
String Functions.
Date and Time Functions.
Summary Functions.
Security and Compression Functions.
Advisory Locking Functions.
Spatial Functions.
Miscellaneous Functions.
Appendix D. System, Status, and User Variable Reference.
System Variables.
Session-Only System Variables.
Status Variables.
Statement Counter Status Variables.
InnoDB Status Variables.
Query Cache Status Variables.
SSL Status Variables.
User-Defined Variables.
Appendix E. SQL Syntax Reference.
SQL Statement Syntax.
Stored Routine Syntax.
Control Structure Statements.
Declaration Statements.
Cursor Statements.
Comment Syntax.
Appendix F. MySQL Program Reference.
Specifying Program Options.
Program Option Conventions.
Standard MySQL Program Options.
Option Files.
Environment Variables.
libmysqld.
myisamchk.
Usage.
Standard Options Supported by myisamchk.
Options Specific to myisamchk.
Variables for myisamchk.
myisampack.
Usage.
Standard Options Supported by myisampack.
Options Specific to myisampack.
mysql.
Usage.
Standard Options Supported by mysql.
Options Specific to mysql.
Variables for mysql.
mysql Commands.
mysql Prompt Definition Sequences.
mysql.server.
Usage.
Standard Options Supported by mysql.server.
mysql_config.
Usage.
Options Specific to mysql_config.
mysql_install_db.
Usage.
Options Specific to mysql_install_db.
mysqladmin.
Usage.
Standard Options Supported by mysqladmin.
Options Specific to mysqladmin.
Variables for mysqladmin.
mysqladmin Commands.
mysqlbinlog.
Usage.
Standard Options Supported by mysqlbinlog.
Options Specific to mysqlbinlog.
Variables for mysqlbinlog.
mysqlcheck.
Usage.
Standard Options Supported by mysqlcheck.
Options Specific to mysqlcheck.
mysqld.
Usage.
Standard Options Supported by mysqld.
Options Specific to mysqld.
Variables for mysqld.
mysqld_multi.
Usage.
Standard Options Supported by mysqld_multi.
Options Specific to mysqld_multi.
mysqld_safe.
Usage.
Options Specific to mysqld_safe.
Upgrading Tips.
mysqldump.
Usage.
Standard Options Supported by mysqldump.
Options Specific to mysqldump.
Data Format Options for mysqldump.
Variables for mysqldump.
mysqlhotcopy.
Usage.
Standard Options Supported by mysqlhotcopy.
Options Specific to mysqlhotcopy.
mysqlimport.
Usage.
Standard Options Supported by mysqlimport.
Options Specific to mysqlimport.
Data Format Options for mysqlimport.
mysqlshow.
Usage.
Standard Options Supported by mysqlshow.
Options Specific to mysqlshow.
perror.
Usage.
Standard Options Supported by perror.
Appendix G. C API Reference.
Compiling and Linking.
C API Data Types.
Scalar Data Types.
Non-Scalar Data Types.
Accessor Macros.
C API Functions.
Connection Management Routines.
Error-Reporting Routines.
Statement Construction and Execution Routines.
Result Set Processing Routines.
Information Routines.
Transaction Control Routines.
Multiple Result Set Routines.
Prepared Statement Routines.
Administrative Routines.
Threaded Client Routines.
Embedded Server Communication Routines.
Debugging Routines.
Appendix H. Perl DBI API Reference.
Writing Scripts.
DBI Methods.
DBI Class Methods.
Database Handle Methods.
Statement Handle Methods.
General Handle Methods.
MySQL-Specific Administrative Methods.
DBI Utility Functions.
DBI Attributes.
Database Handle Attributes.
General Handle Attributes.
MySQL-Specific Database Handle Attributes.
Statement Handle Attributes.
MySQL-Specific Statement Handle Attributes.
Dynamic Attributes.
DBI Environment Variables.
Appendix I. PHP and PEAR DB API Reference.
Writing PHP Scripts.
PEAR DB Module Classes.
PEAR DB Module Methods.
DB Class Methods.
DB_common Object Methods.
DB_result Object Methods.
DB_Error Object Methods.
Index.
Note: You will need the Free Adobe Acrobat Reader to view the file(s) for the book. If you do not already have Acrobat installed on your machine, click the "Get Acrobat Reader" button to download and install.
Click on the links below to display the PDF file in a new window. Right-click on the link and select Save As if you want to download it to your hard drive.
0672326736errata.pdf (49 KB)