1. Trang chủ
  2. » Công Nghệ Thông Tin

MySQL, 4th edition

1,3K 179 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 1.326
Dung lượng 7,7 MB

Nội dung

www.it-ebooks.info MySQL Fourth Edition www.it-ebooks.info ® Developer’s Library ESSENTIAL REFERENCES FOR PROGRAMMING PROFESSIONALS Developer’s Library books are designed to provide practicing programmers with unique, high-quality references and tutorials on the programming languages and technologies they use in their daily work All books in the Developer’s Library are written by expert technology practitioners who are especially skilled at organizing and presenting information in a way that’s useful for other programmers Key titles include some of the best, most widely acclaimed books within their topic areas: PHP & MySQL Web Development Python Essential Reference Luke Welling & Laura Thomson ISBN 978-0-672-32916-6 David Beazley ISBN-13: 978-0-672-32862-6 MySQL Programming in Objective-C Paul DuBois ISBN-13: 978-0-672-32938-8 Stephen G Kochan ISBN-13: 978-0-321-56615-7 Linux Kernel Development PostgreSQL Robert Love ISBN-13: 978-0-672-32946-3 Korry Douglas ISBN-13: 978-0-672-33015-5 Developer’s Library books are available at most retail and online bookstores, as well as by subscription from Safari Books Online at safari.informit.com Developer’s Library informit.com/devlibrary www.it-ebooks.info MySQL ® Fourth Edition Paul DuBois Upper Saddle River, NJ • Boston • Indianapolis • San Francisco New York • Toronto • Montreal • London • Munich • Paris • Madrid Cape Town • Sydney • Tokyo Singapore Mexico City www.it-ebooks.info MySQL đ Fourth Edition Acquisitions Editor Mark Taber Copyright © 2009 by Pearson Education, Inc All rights reserved No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher No patent liability is assumed with respect to the use of the information contained herein Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions Nor is any liability assumed for damages resulting from the use of the information contained herein Development Editor Michael Thurston ISBN-13: 978-0-672-32938-8 ISBN-10: 0-672-32938-7 Indexer Cheryl Lenser Library of Congress Cataloging-in-Publication Data DuBois, Paul, 1956MySQL / Paul DuBois — 4th ed p cm Includes index ISBN 978-0-672-32938-8 (pbk.) SQL (Computer program language) MySQL (Electronic resource) Database management I Title QA76.73.S67D588 2009 005.13’3—dc22 2008030855 Printed in the United States of America First Printing August 2008 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized Pearson cannot attest to the accuracy of this information Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied The information provided is on an “as is” basis The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book Bulk Sales Pearson offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales For more information, please contact U.S Corporate and Government Sales 1-800-382-3419 corpsales@pearsontechgroup.com For sales outside of the U.S., please contact International Sales international@pearson.com www.it-ebooks.info Managing Editor Kristy Hart Project Editor Jovana San Nicolas-Shirley Proofreaders Leslie Joseph Water Crest Publishing Technical Editors Stephen Frein Tim Boronczyk Publishing Coordinator Vanessa Evans Cover Designer Gary Adair Compositor Jake McFarland Contents at a Glance Introduction I: General MySQL Use Getting Started with MySQL 13 Using SQL to Manage Data 101 Data Types 201 Stored Programs 289 Query Optimization 303 II: Using MySQL Programming Interfaces Introduction to MySQL Programming 341 Writing MySQL Programs Using C 359 Writing MySQL Programs Using Perl DBI 435 Writing MySQL Programs Using PHP 527 III: MySQL Administration 10 Introduction to MySQL Administration 579 11 The MySQL Data Directory 585 12 General MySQL Administration 609 13 Access Control and Security 699 14 Database Maintenance, Backups, and Replication 737 IV: Appendixes A Obtaining and Installing Software 777 B C D E F Data Type Reference 797 Operator and Function Reference 813 System, Status, and User Variable Reference 889 SQL Syntax Reference 937 MySQL Program Reference 1037 Note: Appendixes G, H, and I are located online and are accessible either by registering this book at informit.com/register or by visiting www.kitebird.com/mysql-book G C API Reference 1121 H Perl DBI API Reference 1177 I PHP API Reference 1207 Index 1225 www.it-ebooks.info Table of Contents 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 10 Additional Resources 11 I: General MySQL Use Getting Started with MySQL 13 1.1 How MySQL Can Help You 13 1.2 A Sample Database 17 1.2.1 The U.S Historical League 17 1.2.2 The Grade-Keeping Project 20 1.2.3 How the Sample Database Applies to You 20 1.3 Basic Database Terminology 21 1.3.1 Structural Terminology 21 1.3.2 Query Language Terminology 22 1.3.3 MySQL Architectural Terminology 24 1.4 A MySQL Tutorial 25 1.4.1 Obtaining the Sample Database Distribution 26 1.4.2 Preliminary Requirements 27 1.4.3 Establishing and Terminating Connections to the MySQL Server 28 1.4.4 Executing SQL Statements 30 1.4.5 Creating a Database 33 1.4.6 Creating Tables 34 www.it-ebooks.info Contents 1.4.7 Adding New Rows 53 1.4.8 Resetting the sampdb Database to a Known State 57 1.4.9 Retrieving Information 58 1.4.10 Deleting or Updating Existing Rows 91 1.5 Tips for Interacting with mysql 93 1.5.1 Simplifying the Connection Process 93 1.5.2 Issuing Statements with Less Typing 95 1.6 Where to Now? 100 Using SQL to Manage Data 101 2.1 The Server SQL Mode 102 2.2 MySQL Identifier Syntax and Naming Rules 103 2.3 Case Sensitivity in SQL Statements 106 2.4 Character Set Support 107 2.4.1 Specifying Character Sets 108 2.4.2 Determining Character Set Availability and Current Settings 109 2.4.3 Unicode Support 111 2.5 Selecting, Creating, Dropping, and Altering Databases 112 2.5.1 Selecting Databases 112 2.5.2 Creating Databases 113 2.5.3 Dropping Databases 114 2.5.4 Altering Databases 114 2.6 Creating, Dropping, Indexing, and Altering Tables 114 2.6.1 Storage Engine Characteristics 114 2.6.2 Creating Tables 122 2.6.3 Dropping Tables 135 2.6.4 Indexing Tables 136 2.6.5 Altering Table Structure 141 2.7 Obtaining Database Metadata 144 2.7.1 Obtaining Metadata with SHOW 145 2.7.2 Obtaining Metadata with INFORMATION_SCHEMA 147 2.7.3 Obtaining Metadata from the Command Line 149 2.8 Performing Multiple-Table Retrievals with Joins 150 2.8.1 The Inner Join 152 2.8.2 Qualifying References to Columns from Joined Tables 153 2.8.3 Left and Right (Outer) Joins 154 www.it-ebooks.info vii viii Contents 2.9 Performing Multiple-Table Retrievals with Subqueries 158 2.9.1 Subqueries with Relative Comparison Operators 159 2.9.2 IN and NOT IN Subqueries 160 2.9.3 ALL, ANY, and SOME Subqueries 161 2.9.4 EXISTS and NOT EXISTS Subqueries 162 2.9.5 Correlated Subqueries 163 2.9.6 Subqueries in the FROM Clause 163 2.9.7 Rewriting Subqueries as Joins 164 2.10 Performing Multiple-Table Retrievals with UNION 165 2.11 Using Views 169 2.12 Multiple-Table Deletes and Updates 173 2.13 Performing Transactions 174 2.13.1 Using Transactions to Ensure Safe Statement Execution 176 2.13.2 Using Transaction Savepoints 180 2.13.3 Transaction Isolation 180 2.13.4 Non-Transactional Approaches to Transactional Problems 182 2.14 Foreign Keys and Referential Integrity 185 2.14.1 Creating and Using Foreign Keys 187 2.14.2 Living Without Foreign Keys 192 2.15 Using FULLTEXT Searches 194 2.15.1 Natural Language FULLTEXT Searches 196 2.15.2 Boolean Mode FULLTEXT Searches 197 2.15.3 Query Expansion FULLTEXT Searches 199 2.15.4 Configuring the FULLTEXT Search Engine 200 Data Types 201 3.1 Data Value Categories 203 3.1.1 Numeric Values 203 3.1.2 String Values 204 3.1.3 Date and Time (Temporal) Values 213 3.1.4 Spatial Values 213 3.1.5 Boolean Values 213 3.1.6 The NULL Value 214 3.2 MySQL Data Types 214 3.2.1 Overview of Data Types 215 3.2.2 Specifying Column Types in Table Definitions 217 3.2.3 Specifying Column Default Values 218 www.it-ebooks.info Contents 3.2.4 Numeric Data Types 219 3.2.5 String Data Types 226 3.2.6 Date and Time Data Types 242 3.2.7 Spatial Data Types 250 3.3 How MySQL Handles Invalid Data Values 252 3.4 Working with Sequences 254 3.4.1 General AUTO_INCREMENT Properties 254 3.4.2 Storage Engine-Specific AUTO_INCREMENT Properties 256 3.4.3 Issues to Consider with AUTO_INCREMENT Columns 259 3.4.4 Tips for Working with AUTO_INCREMENT Columns 260 3.4.5 Generating Sequences Without AUTO_INCREMENT 262 3.5 Expression Evaluation and Type Conversion 264 3.5.1 Writing Expressions 265 3.5.2 Type Conversion 272 3.6 Choosing Data Types 280 3.6.1 What Kind of Values Will the Column Hold? 282 3.6.2 Do Your Values Lie Within Some Particular Range? 285 3.6.3 Inter-Relatedness of Data Type Choice Issues 286 Stored Programs 289 4.1 Compound Statements and Statement Delimiters 290 4.2 Stored Functions and Procedures 292 4.2.1 Privileges for Stored Functions and Procedures 294 4.2.2 Stored Procedure Parameter Types 295 4.3 Triggers 296 4.4 Events 298 4.5 Security for Stored Programs and Views 300 Query Optimization 303 5.1 Using Indexing 304 5.1.1 Benefits of Indexing 304 5.1.2 Costs of Indexing 307 5.1.3 Choosing Indexes 308 5.2 The MySQL Query Optimizer 311 5.2.1 How the Optimizer Works 312 5.2.2 Using EXPLAIN to Check Optimizer Operation 316 5.3 Choosing Data Types for Efficient Queries 322 www.it-ebooks.info ix ... documentation team at Sun Microsystems Acknowledgments Acknowledgments are presented here by edition Fourth Edition My technical reviewers, Stephen Frein and Tim Boronczyk, identified many points... continued thanks and gratitude for her encouragement and support throughout this effort Third Edition The third edition enjoyed careful technical review by Zak Greant and Chris Newman Their efforts improved... deserves special credit for her support during yet more revision and rewriting Second Edition For the second edition, the technical reviewers once again played a crucial role in finding errors

Ngày đăng: 12/03/2019, 13:43

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN