Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 601 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
601
Dung lượng
2,38 MB
Nội dung
Sams Teach Yourself MySQL® in 10 Minutes By Chris Newman Publisher: Sams Pub Date: May 09, 2006 Print ISBN-10: 0-672-32863-1 Print ISBN-13: 978-0-672-32863-3 Pages: 288 Table of Contents | Index Sams Teach Yourself MySQL in 10 Minutes provides a no-fluff, just-the-answers guide to building and managing MySQL databases It is carefully organized and thoughtfully written to provide just the information that you need in order to gain a rapid working knowledge of MySQL Get up to speed quickly with Sams Teach Yourself MySQL in 10 Minutes Sams Teach Yourself MySQL® in 10 Minutes By Chris Newman Publisher: Sams Pub Date: May 09, 2006 Print ISBN-10: 0-672-32863-1 Print ISBN-13: 978-0-672-32863-3 Pages: 288 Table of Contents | Index Copyright About the Author Introduction Part 1: MySQL Foundations Lesson 1 Introducing MySQL Database Basics MySQL Components Summary Lesson 2 Using MySQL The mysql Client Executing SQL Statements Creating the Sample Tables Summary Part 2: Getting Started with SQL Lesson 3 Retrieving Data The SELECT Statement Summary Lesson 4 Filtering and Sorting Data The WHERE Clause The ORDER BY Clause Summary Lesson 5 Advanced Data Filtering Combining WHERE Clauses Limiting the Number of Rows Returned Summary Lesson 6 Numeric Operators and Functions Numeric Operators Numeric Functions Conditional Functions Summary Lesson 7 String Operators and Functions Using Operators with Strings String Functions Summary Lesson 8 Date Operators and Functions Date Operators Date Functions Summary Lesson 9 Summarizing Data Aggregate Functions Grouping Data Filtering Summary Data Summary Part 3: Advance SQL Lesson 10 Using Subqueries Understanding Subqueries Summary Lesson 11 Joining Tables Understanding Joins Summary Lesson 12 Creating Advanced Joins The JOIN Keyword Inner Joins Joining Multiple Tables Cross Joins Self-Joins Natural Joins Outer Joins Summary Lesson 13 Combining Queries Understanding Combined Queries Other Compound Operations Using Temporary Tables Summary Part 4: Creating a New Database Lesson 14 Creating and Modifying Tables Creating a New Database Character Sets and Collations Altering a Database Dropping a Database Managing Tables Temporary Tables Using a Query to Create a Table Storage Engines Altering Tables Dropping Tables Summary Lesson 15 Working with Data The INSERT Statement The DELETE Statement The UPDATE Statement The REPLACE Statement Loading Data from a File Why Use Transactions? Transactions in MySQL Autocommit Mode Rolling Back a Transaction Summary Lesson 16 Designing Your Database Relationships Normalization Naming Tables and Columns Data Types CHAR and VARCHAR Summary Lesson 17 Keys and Indexes Understanding Keys and Indexes Using Indexes in MySQL Summary Lesson 18 Managing User Access Understanding MySQL Authentication User Management Using Wildcards Summary Part 5: New Features in MySQL 5.0 Lesson 19 Views Understanding Views Summary Lesson 20 Stored Routines Understanding Stored Routines Summary Lesson 21 Triggers Understanding Triggers Using Triggers Summary Part 6: Interfacing with MySQL Lesson 22 Using ODBC Understanding ODBC Connecting to MyODBC Summary Lesson 23 Using MySQL with C The C Language API Summary Lesson 24 Using MySQL with PHP Using the mysql API Using the mysqli API Summary Lesson 25 Using MySQL with Perl The Perl DBI Using the MySQL DBD Summary Part 7: Appendix Appendix A Installing MySQL Obtaining MySQL Linux/UNIX Installation Windows Installation Appendix B Sample Table Scripts Index Copyright Sams Teach Yourself MySQLđ in 10 Minutes Copyright â 2006 by Sams Publishing 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 Library of Congress Catalog Card Number: 2005328631 Printed in the United States of America First Printing: May 2006 09 08 07 06 4 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized Sams Publishing 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 Sams Publishing 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@pearsoned.com ACQUISITIONS EDITOR Shelley Johnston DEVELOPMENT EDITOR Damon Jordan MANAGING EDITOR Charlotte Clapp PROJECT EDITOR Andy Beaster COPY EDITOR Krista Hansing INDEXER Juli Bess PROOFREADER Kathy Bidwell TECHNICAL EDITOR Adam DeFields PUBLISHING COORDINATOR Vanessa Evans INTERIOR DESIGNER Gary Adair COVER DESIGNER Aren Howell PAGE LAYOUT Nonie Ratcliff About the Author Chris Newman is a consultant programmer who specializes in database development with an Internet twist He has extensive commercial experience in using PHP to integrate various database systems, and he has produced a wide range of applications for an international client base A graduate of Keele University, Chris lives in Stoke-on-Trent, England, where he runs Lightwood Consultancy, Ltd., the company he founded in 1999 to further his interest in online database development Chris has served as a technical editor on several books from Sams, including PHP and MySQL Web Development (2004), Sams Teach Yourself PHP, MySQL, and Apache All in One (2004), and Red Hat Fedora Unleashed (2004) He is the author of Sams Teach Yourself PHP in 10 Minutes (2005) and SQLite (2004), and co-author of MySQL Phrasebook (2006) More information on Lightwood Consultancy, Ltd., is available at http://www.lightwood.net Chris can be contacted at chris@lightwood.net Acknowledgments I would like to thank the team at Sams Publishing for its ongoing support and guidance while writing this book Special thanks to Shelley Johnston, who hired me as a technical editor and then one day asked if I wanted to write Indeed I did! After six awesome years working together, Shelley is moving on, and I wish her every happiness We Want to Hear from You! DESCRIBE command error messages FROM clause INNER JOIN keyword JOIN keyword JOIN, ON keyword 2nd LEFT JOIN keyword LEFT OUTER JOIN keyword LIMIT clause limiting rows returned from queries skipping rows for queries NATURAL JOIN keyword ON clause, inner joins ORDER BY clause sorting on a single column sorting on multiple columns specifying sort orders RIGHT JOIN keyword RIGHT OUTER JOIN keyword SHOW COLUMNS command SHOW DATABASES command SHOW TABLES command syntax for tables lists, retrieving tables, creating WHERE clause AND operator BETWEEN operator filtering on an exact data value filtering on multiple values filtering on range of data values IN operator NOT operator operator precedence OR operator quotes around values selecting, MySQL databases (mysql client program) self-joins semantic errors, SELECT statement servers Linux/UNIX installation MySQL, C Language API connection ports SET PASSWORD command SHOW CHARACTER SET command SHOW COLUMNS command, SELECT statement SHOW CREATE VIEW command SHOW DATABASES command, SELECT statement SHOW DATABASES privilege SHOW FUNCTION STATUS command SHOW INDEXES command SHOW KEYS command SHOW PROCEDURE STATUS command SHOW TABLES command 2nd SHOW TRIGGERS command SHOW VIEW privilege SHOW WARNINGS command SHUTDOWN privilege SIN( ) function skipping, rows in queries (LIMIT clause) SMALLINT data type sort orders sorting columns, ORDER BY clause (SELECT statement) combined queries, UNION operator on multiple columns, ORDER BY clause (SELECT statement) on single columns, ORDER BY clause (SELECT statement) source code Linux/UNIX server installation MySQL splitting functions SQL (Structured Query Language) 2nd SQRT( ) function square roots, SQRT( ) function Standard binaries statements [See also names of specific statements.] MySQL databases, executing in (mysql client ptogram) terminating storage engines, tables stored functions [See functions.] stored routines creating creating functions dropping naming privileges showing procedures and functions variables strings comparison operators BETWEEN BINARY LIKE converting values to numbers delimiters functions complete listing of (MySQL.com) CONCAT WS( ) CONCAT( ) LOCATE( ) LOWER( ) LPAD( ) LTRIM( ) NULL values REPLACE( ) RPAD( ) RTRIM( ) SUBSTRING INDEX( ) SUBSTRING( ) TRIM( ) UPPER( ) Structured Query Language (SQL) 2nd subqueries (subselects) as calculated fields as tables correlated filtering by formatting outer queries syntax UPDATE command versus self-joins subselects [See subqueries (subselects).] SUBSTRING INDEX( ) function, string splitting SUBSTRING( ) function, string splitting subtraction (-) operator SUM( ) function, data aggregation summarizing data summary data, filtering (HAVING clause) SUPER privilege superusers Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] \T command (mysql), query output table joins Cartesian products cross equi inner multiple natural outer SELECT statement, FROM clause self-joins tables altering autoincrementing column calculated columns columns foreign keys naming conventions primary keys creating data autocommit mode DELETE command INSERT command loading from file REPLACE command transactions UPDATE command default values dropping foreign keys lists, retrieving (SELECT statement) multiple, joining names, case sensitivity relational databases data types naming tables and columns normalization relationships samples, installing scripts storage engines subqueries as calculated fields correlated filtering by outer queries using as temporary 2nd INTERSECT simulation MINUS simulation UNION simulation using queries to create viewing indexes views TAN( ) function TCP/IP port 2nd temporary tables 2nd TEMPTABLE algorithm TERMINATED BY command terminating queries terminating statements test suites, Linux/UNIX server installation TEXT data types text, data types time Coordinated Universal Time (UTC) data types formatting (DATE FORMAT( ) function) functions CONVERT TZ( ) CURDATE( ) DATE FORMAT( ) EXTRACT( ) FROM UNIXTIME( ) NOW( ) UNIX TIMESTAMP( ) UTC DATE( ) UTC TIME( ) UTC TIMESTAMP( ) representational formats zone support TIMEDIFF( ) function, time difference computations times, storing values in columns TIMESTAMP data types TINYBLOB data type TINYINT data type TINYTEXT data type transactions, databases MySQL reasons for using rolling back triggers creating audit trail data-maintenance database operations disabling dropping privileges showing information trigonometric functions ACOS( ) ASIN( ) ATAN( ) COS( ) DEGREES( ) RADIANS( ) SIN( ) TAN( ) TRIM( ) function, string trimming trimming functions LTRIM( ) RTRIM( ) TRIM( ) TRUE value, conditional functions TRUNCATE( ) function type conversions, strings to numbers Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] UNION ALL operators, combined queries UNION operators combined queries simulating in temporary tables UNIQUE constraint, tables UNIX data source FROM UNIXTIME( ) function MySQL components MySQL installation binary version Linux RPM packages source code UNIX TIMESTAMP( ) function UNIX TIMESTAMP( ) function unix_socket argument unsigned values, data types UPDATE command, data manipulation UPDATE privilege UPDATE trigger updates, views UPPER( ) function, string uppercase/lowercase conversion USAGE privilege user argument user switch, mysql client program usernames, wildcards users access authentication databases ALTER DATABASE command character sets collations DROP DATABASE command management creating user passing on privileges passwords privileges revoking privileges wildcards deleting user viewing privileges UTC DATE( ) function UTC TIME( ) function UTC TIMESTAMP( ) function Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] validation, dates values, quotes usage variable character data types variables, stored functions viewing MySQL databases, connection status (mysql client program) views algorithms altering cascading creating dropping finding underlying query text naming privileges showing tables updating Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] Web access websites, MySQL 2nd date functions listing numeric functions listing Sams Publishing string functions listing WHERE clause 2nd AND operator BETWEEN operator filtering on an exact data value filtering on multiple values filtering on range of data values IN operator NOT operator operator precedence OR operator quotes around values wildcards granting privileges deleting users viewing usernames Windows MySQL components MySQL installation Windows Essentials, MySQL installation WITH GRANT OPTION command ... Installing MySQL Obtaining MySQL Linux/UNIX Installation Windows Installation Appendix B Sample Table Scripts Index Copyright Sams Teach Yourself MySQL in 10 Minutes Copyright â 2006 by Sams Publishing All rights reserved.. .Sams Teach Yourself MySQL in 10 Minutes By Chris Newman Publisher: Sams Pub Date: May 09, 2006 Print ISBN -10: 0-672-32863-1 Print ISBN- 13: 978-0-672-32863-3... Using MySQL with PHP Using the mysql API Using the mysqli API Summary Lesson 25 Using MySQL with Perl The Perl DBI Using the MySQL DBD Summary Part 7: Appendix Appendix A Installing MySQL Obtaining MySQL