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

1787 the definitive guide to MySQL 5, 3rd edition

785 85 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 785
Dung lượng 11,24 MB

Nội dung

www.it-ebooks.info 5351fm_final.qxd 8/26/05 6:12 PM Page i The Definitive Guide to MySQL5 Third Edition Michael Kofler Translated By David Kramer www.it-ebooks.info 5351fm_final.qxd 8/26/05 6:12 PM Page ii The Definitive Guide to MySQL Copyright © 2005 by Michael Kofler All rights reserved No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher ISBN (pbk): 1-59059-535-1 Printed and bound in the United States of America Trademarked names may appear in this book Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark Lead Editor: Jason Gilmore Translator and Editor: David Kramer Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis, Jason Gilmore, Jonathan Hassell, Chris Mills, Dominic Shakeshaft, Jim Sumser Associate Publisher: Grace Wong Project Manager: Beth Christmas Copy Edit Manager: Nicole LeClerc Assistant Production Director: Kari Brooks-Copony Production Editor: Laura Cheu Compositor: Linda Weidemann, Wolf Creek Press Proofreader: April Eddy Artist: Kinetic Publishing Services, LLC Interior Designer: Van Winkle Design Group Cover Designer: Kurt Krames Manufacturing Manager: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013 Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or visit http://www.springeronline.com For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710 Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com The information in this book is distributed on an “as is” basis, without warranty Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress 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 information contained in this work The source code for this book is available to readers at http://www.apress.com in the Source Code section www.it-ebooks.info 5351fm_final.qxd 8/26/05 6:12 PM Page iii Contents at a Glance About the Author xxiii About the Translator xxv Preface xxvii PART ■■■ Introduction ■CHAPTER What Is MySQL? ■CHAPTER ■CHAPTER The Test Environment 17 Introductory Example (An Opinion Poll with PHP) 47 PART ■■■ Administrative Tools and User Interfaces ■CHAPTER mysql, mysqladmin, and mysqldump 61 ■CHAPTER MySQL Administrator and MySQL Query Browser 71 ■CHAPTER phpMyAdmin 87 ■CHAPTER Microsoft Office, OpenOffice/StarOffice 117 PART ■■■ Fundamentals ■CHAPTER Database Design 137 ■CHAPTER An Introduction to SQL 189 ■CHAPTER 10 SQL Recipes 217 ■CHAPTER 11 Access Administration and Security 263 ■CHAPTER 12 GIS Functions 299 ■CHAPTER 13 Stored Procedures and Triggers 317 ■CHAPTER 14 Administration and Server Configuration 345 iii www.it-ebooks.info 5351fm_final.qxd iv 8/26/05 6:12 PM Page iv ■CONTENTS AT A GLANCE PART ■■■ Programming ■CHAPTER 15 PHP 403 ■CHAPTER 16 Perl 481 ■CHAPTER 17 Java (JDBC and Connector/J) 507 ■CHAPTER 18 C 527 ■CHAPTER 19 Visual Basic 6/VBA 545 ■CHAPTER 20 Visual Basic NET and C# 573 PART ■■■ Reference ■CHAPTER 21 SQL Reference 599 ■CHAPTER 22 MySQL Tools and Options 667 ■CHAPTER 23 API Reference 693 PART ■■■ Appendixes ■APPENDIX A Glossary 723 ■APPENDIX B The Files for this Book 729 ■APPENDIX C Bibliography 731 ■INDEX 733 www.it-ebooks.info 5351fm_final.qxd 8/26/05 6:12 PM Page v Contents About the Author xxiii About the Translator xxv Preface xxvii PART ■CHAPTER ■■■ Introduction What Is MySQL? What Is a Database? Relations, Database Systems, Servers, and Clients Relational Versus Object-Oriented Database Systems Tables, Records, Fields, Queries, SQL, Index, Keys MySQL Features of MySQL Limitations of MySQL MySQL Version Numbers Alpha, Beta, Gamma, Production (Generally Available) MySQL Functions Ordered by Version Number MySQL Licensing 11 Rights and Duties with Respect to the GPL 11 Use of MySQL with an Open Source License 12 Use of MySQL with a Commercial License 12 Commercial Licenses for Client Libraries (Connector/ODBC, Connector/J, etc.) 13 Client Licenses for the PHP Project, F(L)OSS Exception 14 MySQL Version Names 14 Support Contracts 15 Alternatives to MySQL 16 Summary 16 ■CHAPTER The Test Environment 17 Windows or Unix/Linux? 17 MySQL in Practice (Public Internet Server) 17 Development Environment 18 Installation Under Windows 18 v www.it-ebooks.info 5351fm_final.qxd vi 8/26/05 6:12 PM Page vi ■CONTENTS Installing Apache 2.0 18 Installing MySQL 5.0 20 Installing PHP 5.0 23 Installing Perl 25 Installation Under SUSE Linux 9.3 27 Installing Apache 2, PHP 5, and Perl 27 Installing MySQL 5.0 30 Installation Under Red Hat Enterprise Linux 31 Installing Apache 31 Installing MySQL 32 Compiling PHP 33 Installing Perl 5.8 36 Compiling the MySQL Developer Version (Linux) 36 Installing Bitkeeper 37 Downloading the MySQL Developer Version 37 Compiling MySQL 37 Setting Up the mysql Database for Managing Access Privileges 37 Configuration Files and Init-V Scripts 37 Starting the MySQL Server 38 Configuring Apache 38 Configuration Files 38 Elementary Settings 39 Access Privileges for Individual Directories (.htaccess) 40 Configuring PHP 43 Configuring MySQL 45 Launching the MySQL Server 45 ■CHAPTER Introductory Example (An Opinion Poll with PHP) 47 Overview 47 Assumptions 47 Database Development 48 Executing the mysql Command-Line Interpreter 49 Setting Up the Database 50 Creating Tables 50 Why Make It Complicated, When It Could Be So Much Easier? 52 The Questionnaire 53 Questionnaire Evaluation and Displaying Results 53 The mysql Interface Versus the mysqli Interface 54 Establishing a Connection to the Database 54 Evaluating the Data and Storing It in the Database 54 Displaying the Survey Results 55 Program Code (results.php) 55 The Resulting HTML Code 57 Ideas for Improvements 57 www.it-ebooks.info 5351fm_final.qxd 8/26/05 6:12 PM Page vii ■CONTENTS PART ■CHAPTER ■■■ Administrative Tools and User Interfaces mysql, mysqladmin, and mysqldump 61 mysql 61 Launching mysql 62 mysql Options 63 Using mysql Interactively 64 Tips for Using mysql Under Unix/Linux 66 Tips for Using mysql Under Windows 67 Processing SQL Files with mysql 69 mysqladmin 70 mysqldump 70 ■CHAPTER MySQL Administrator and MySQL Query Browser 71 Installation 71 Establishing a Connection 72 MySQL Administrator 73 Server Information 74 Service Control 74 Startup Variables 75 User Administration 75 Server Connections 78 Health 78 Server Logs 78 Backup 78 Restore 80 Replication Status 81 Catalogs 81 MySQL Query Browser 82 Input and Execution of SQL Commands 82 Changing Data in SELECT Results 84 History and Bookmarks for SQL Commands 84 Executing Several Commands at Once (Scripts) 84 Stored Procedures 85 MySQL Help 85 www.it-ebooks.info vii 5351fm_final.qxd viii 8/26/05 6:12 PM Page viii ■CONTENTS ■CHAPTER phpMyAdmin 87 Installation and Configuration 87 Installing phpMyAdmin Files 88 Configuring phpMyAdmin 88 config Authentication 89 http and Cookie Authentication 91 User Management, Securing MySQL 94 Securing MySQL 94 Creating New Users 95 Creating and Editing Databases 98 Creating a Database 98 Editing Existing Tables 100 Setting Foreign Key Rules 100 Documenting the Database Structure 101 Viewing, Inserting, and Editing Data 102 Executing SQL Commands 104 Import and Export 105 Database Backup (SQL File) 106 Exporting Tables (CSV Text File) 107 Importing a Database or Tables (SQL File) 107 Inserting Table Data (Text File) 108 Server Administration 109 Auxiliary Functions 110 Creating a Database for phpMyAdmin 110 SQL Bookmarks and History 111 Saving Information on Relations 111 Creating a PDF Relational Diagram 113 Transformations (Alternative Representation of Column Contents) 115 ■CHAPTER Microsoft Office, OpenOffice/StarOffice 117 Installing Connector/ODBC 117 Setting Up ODBC Data Sources 118 Microsoft Access 120 Importing and Exporting Tables 122 Converter: Access ➤ MySQL (exportsql.txt) 123 Microsoft Excel 125 Importing Data with MS Query 125 Connector/J Installation 127 Connector/J 127 Installation 127 www.it-ebooks.info 5351fm_final.qxd 8/26/05 6:12 PM Page ix ■CONTENTS OpenOffice/StarOffice Base 128 Creating a Connection to a MySQL Database 128 Tables 130 Queries 131 Forms, Reports, and Additional Functions 132 OpenOffice/StarOffice Data Source View 133 Establishing a Data Source 134 Importing Data 134 PART ■CHAPTER ■■■ Fundamentals Database Design 137 Further Reading 137 Table Types 138 MyISAM Tables 138 InnoDB Tables 139 HEAP Tables 140 Temporary Tables 141 Other Table Types 141 Table Files 142 MySQL Data Types 142 Integers (xxxINT) 142 Fixed-Point Numbers (DECIMAL) 144 Date and Time (DATE, TIME, DATETIME, TIMESTAMP) 145 Character Strings (CHAR, VARCHAR, xxxTEXT) 147 Binary Data (xxxBLOB and BIT) 151 Options and Attributes 152 Tips and Tricks on Database Design 153 Rules for Good Database Design 153 Tips for Naming 153 Tips on the Design Process 153 Normalization Rules 154 A First Attempt 155 The First Normal Form 155 Second Normal Form 156 Third Normal Form 158 Normalization Theory 159 Managing Hierarchies 160 Hierarchy Problems 161 Building the Hierarchy Tree 162 Searching for Lower-Ranked Categories in the categories Table 164 Searching for Higher-Ranked Categories in the categories Table 165 www.it-ebooks.info ix 5351idx_final.qxd 738 8/26/05 11:37 PM Page 738 ■INDEX glacier database, 309 GLENGTH, 305 GLOBAL, 608, 644 global privileges, 275 global variables, 608 glossary, 723–727 GPL, 11 GRANT, 288, 628 Grant-Option privilege, 275 grant tables, 276 GROUP BY, 201 functions, 661 GROUP BY WITH ROLLUP, 204 GROUP_CONCAT, 202 GUIs, 61 htaccess files (Apache), 40, 462 HTML create tables (mysql), 367 htmlentities (PHP), 425 htmlspecialchars (PHP), 422, 425 htpasswd, 41 http authentication (phpMyAdmin), 91 httpd.conf file, 38, 462 ■I ■H HANDLER, 630 handlers (stored procedures), 333 hard drive partitions used directly (InnoDB), 388 HAVING, 196 headers (PHP) , 462, 467, 477 HEAP, 622 HEAP tables, 140, 674 Hello World C, 527, 531 Java, 508 Perl, 26 stored procedures, 318 HELP, 630 hexadecimal numbers BLOB, 601 SQL, 602 HexCode function (VB), 559 HexCodeStr function (VB), 559 hierarchies, 160–166 logical order, 162 managing data with PHP, 446 among messages (myforum sample database), 184 stored procedures, 338 realization with tables, 167 HIGH_PRIORITY, 639 host (Unix/Linux command), 283 Host n.n.n.n is not allowed to connect … (error), 293 host name, 266 user table, 278 with or without domain name, 281 host table, 285 hostname (Unix/Linux command), 283 hostname bin.index file, 370 hostname bin.nnn file, 370 hostname relay files, 381 hostname slow.log file, 373 hostname.err file, 372 hostname.log file, 372 hot backup, ib_arch_log_n file, 392 ib_logfilen file, 390 iconv functions (PHP), 461 IF, 218, 232, 234 IF-THEN, 331 IGNORE (INSERT), 631 IGNORE (SELECT), 624 IGNORE INDEX, 308 IGNORE … LINES, 633 ignore_space mode, 351 images displaying with PHP, 467 storing in MySQL (PHP), 464 importing Access tables, 120 CSV files, 363 databases/tables, 105 mysqlimport, 364 phpMyAdmin, 105 text files, 360, 632 IMPORT TABLESPACE, 616 IN, 196, 239, 328, 640 IN BOOLEAN MODE, 249 INDEX, 622 indexes, 5, 173 add (ALTER TABLE), 212 analyze table, 618 creating, 211, 621 deactivating temporarily, 616 deleting, 627 displaying list of, 648 full-text, 248 InnoDB tables, 174 primary, 168 spatial (GIS), 308 UNIQUE, 175 ini files, 347, 669 INFILE, 632 information_schema tables, 215 INNER JOIN, 199 INNODB, 622 InnoDB tables, 139, 174, 345 locking, 253–255, 258–260 managing, 386–393 options, 677 replication, 382 status, 648 transactions, 255–261 tuning, 392 www.it-ebooks.info 5351idx_final.qxd 8/26/05 11:37 PM Page 739 ■INDEX innodb_additional_mem_pool_size (mysqld configuration), 393 innodb_buffer_pool_size (mysqld), 392 innodb_data_file_path (mysqld), 387 innodb_data_home (mysqld), 387 innodb_fast_shutdown configuration, 677 innodb_file_io_threads configuration, 678 innodb_file_per_table (mysqld), 387 innodb_flush_log_at_trx_commit (mysqld), 391 innodb_flush_method (mysqld), 392 innodb_log_archive (mysqld), 392 innodb_log_buffer_size (mysqld configuration), 393 innodb_log_files_in_group (mysqld), 391 innodb_log_file_size (mysqld), 391 innodb_log_group_home_dir (mysqld), 391 innodb_open_files (mysqld), 677 innodb_thread_concurrency configuration, 678 INOUT, 328 INSERT, 206, 630, 631 INSERT INTO … SELECT, 234, 631 INSERT INTO SELECT, 205 INSERT SELECT, 243 insertRow method (Java), 521 insert_id (PHP), 413 insserv command (SUSE), 29 installing Apache Red Hat, 31 SUSE, 27 Windows, 19 Connector/ODBC, 117 MySQL Red Hat, 32 SUSE, 30 Windows, 20 Perl Red Hat, 36 SUSE, 27 Windows, 25 PHP Red Hat, 33 SUSE, 27 Windows, 23 INT, 142 integer types, 142 integrity rules, 172, 173 Interbase, 16 INTERIORRINGN, 306, 311 INTERSECT, 201 INTERSECTS, 308 invalid records, searching for, 241 IO_THREAD, 650 IS NULL, 605 ISAM, 622 isAutoIncrement method (Java), 520 ISCLOSED, 305 IsDBNull method (ADO.NET), 583 is_null (MYSQL_BIND), 538 ISNULL, 196 isNullable method (Java), 520 isolation (ACID), 255 isolation level, 260 ISP administration, 397 backups, 398 database upload, 399 phpMyAdmin configuration, 88 ISSUER (GRANT), 629 ITERATE, 332 ■J Java, 127, 507 connection problems, 515 Unicode, 519 java.sql package, 512 javac, 509 javax.sql package, 514 JDBC, 127, 509, 706 JDK, 507 JOIN, 197 join_buffer_size (mysqld), 395 ■K keys See indexes KEY, 622 key_buffer_size (mysqld), 395 KILL, 632 ■L language (mysqld), 350, 673 LastInsertedID function (VB), 557 LAST_INSERT_ID, 143, 207, 581 ldd, 531 LEAVE, 332 LEFT JOIN, 197 LENGTH, 217 lengths (PHP), 414 libmySQL.dll library, 570 libmysqlclient (C API), 527 license (GPL), 11 LIKE, 220, 605 LIMIT, 192, 244, 641 DELETE, 209, 625 FOUND_ROWS, 192 limit access privileges with REVOKE, 638 LINES TERMINATED BY, 362, 633, 643 LINESTRING, 302 linked tables, 166 Access, 122 phpMyAdmin, 111 linking (C programming) 529 LOAD DATA, 361, 632 LOAD DATA FROM MASTER, 379, 634 LOAD DATA LOCAL, 632 LOAD INDEX INTO CACHE, 634 LOAD TABLE FROM MASTER, 634 LoadFromFile method (ADO), 557 LoadModule (Apache option), 23, 35, 39 www.it-ebooks.info 739 5351idx_final.qxd 740 8/26/05 11:37 PM Page 740 ■INDEX load_defaults (C), 533 LOCAL, 608, 632 local-infile (mysqld), 673 localhost host name, 278 problems in Unix/Linux, 282 LOCALTIMESTAMP, 656 LOCK TABLE, 254, 634 locking, 7, 253, 634 InnoDB tables, 253–255, 258–260 log (mysqld), 372 log-bin (mysqld), 369, 377 log-error (mysqld), 372 log files, 372 log-queries-not-using-indexes (mysqld), 373 log-slow-queries (mysqld), 373 log-update (mysqld), 369 logging, 368 administration of logging files, 373 binary format, 369 deleting files, 636 errors, 372 InnoDB, 390 logins, 372 restoring databases, 371 login logging, 372 LONGBLOB, 151 LongReadLen (Perl), 491 LONGTEXT, 147 LongTruncOK (Perl), 701 long_query_time (mysqld), 373 LOOP, 332, 335, 341 loops, for SPs, 325, 331–335, 338 loose-xxx (mysqld), 671 LOW_PRIORITY, 631 LOW PRIORITY WRITE, 254, 635 lower_case_table_names (mysqld), 600, 672 ■M magic_quotes_gpc (PHP option), 43, 430 makefile (C programming), 530 many-to-many relations, 168 master.info file, 380, 619, 649 master/slave replication, 374 master system setup, 376 master-xxx (mysqld), 675 MATCH, 248 MAX, 661 max-allowed-packet (mysqld), 679 Max version, 14 maxdb mode, 351 maximum-xxx (mysqld), 671 max_binlog_size (mysqld), 371 max_connections (mysqld), 395 max_connections column (user table), 280 max_execution_time (PHP option), 44, 468 max_heap_table_size (mysqld), 674 max_input_time (PHP option), 44, 468 max_questions column (user table), 280 max_updates column (user table), 280 max_user_connections column (user table), 280 MBR, 304 MBRCONTAINS, 306, 315 MBRDISJOINT, 306 MBREQUALS, 306 MBRINTERSECT, 306 MBROERLAP, 306 MBRTOUCHES, 306 MBRWITHIN, 306 mbstring functions (PHP), 461 mbstring warning (phpMyAdmin), 90 MDAC, 546 MEDIUMBLOB, 151 MEDIUMINT, 142 MEDIUMTEXT, 147 memory management, 394 memory_limit (PHP option), 44, 468 MERGE, 622 metadata, 214, 520 microseconds, 146 Microsoft SQL Server, converting to MySQL, 567 microtime (PHP), 456 migration, 358 MIME file type (PHP example), 469 MIN, 661 MINUS, 201 MM.MySQL, 509 model (database), MODIFY, 617 more_results (PHP), 415 moveToInsertRow method (Java), 521 MS Query, 125 mssql mode, 351 mssql2mysql, 568 MULTIPOINT, 302 MULTIPOLYGON, 302 multi_query (PHP), 415, 471 MULTI_RESULTS mode (C), 535 MULTI_STATEMENTS mode (C), 535 my.cnf file, 669 my.ini file, 669 mybackup, 355 MYD files, 142, 689 MyDb class (PHP example), 419 myforum (sample database), 183 MYI files, 142, 689 MyISAM tables, 138, 383–385, 622 myisam-recover (mysqld), 673 myisamchk, 383, 689 myisampack, 385, 690 mylibrary (sample database), 137, 154 ADO/VB example, 559 author/title search (PHP), 439 category management (PHP), 446 CGI-Perl example, 497–505 deleting invalid records, 496 schema, 180 storing book titles (PHP), 427 stored procedures, 336 VBMySQLDirect example, 571 www.it-ebooks.info 5351idx_final.qxd 8/26/05 11:37 PM Page 741 ■INDEX mylibrary-find.pl sample script, 497 mylibrary-simpleinput.pl sample script, 500 MyODBC See Connector/ODBC MySQL, 5–16, 49 character set variables, 219 cluster, 141 compilation (Linux), 36 configuration assistant, 20 configuration files, 669 installing Red Hat, 32 SUSE, 30 Windows, 20 license, 11, 12 logging, 368 memory management, 394 options reference, 672 security (configuration assistant), 21 service (Windows 2000/XP), 22 starting/stopping/restarting, 347 tuning, 393 update from 4.n to 5.0, 359 versions of, 8, 9, 14, 36, 141 mysql (command interpreter), 49, 61–70 backup file, reading in, 69 batch mode, 366 character set problems, 67, 68 configuration file, 669 HTML create tables, 367 interactive mode, 64 options, 63 restore backup files, 355 SQL processing files, 69 syntax, 681 tips, 66, 67 MySQL Adminstrator, 71, 73 MySQL Control Center, 71 mysql db, 276 mysql interface (PHP), 403 MySQL operators, 605 MySQL Query Browser, 71, 82, 320 MySQL tools, 667–691 MySql.Data.dll file, 574 mysql323 mode, 351 mysql40 mode, 351 mysqladmin, 70, 346 changing password, 290 syntax, 683 mysqlbinlog, 370 MySqlCommand class (ADO.NET), 580 MySqlCommandBuilder class (ADO.NET), 585 MySqlConnection class (Connector/Net), 575 mysqld See MySQL MySqlDataAdapter class (ADO.NET, 585 MySqlDataReader class (ADO.NET), 583 MySqlDateTime data type (ADO.NET), 584 MySQLDirect NET provider (ADO.NET), 574 MySQLDriverCS provider (ADO.NET), 574 mysqldump, 70, 352, 366 creating a backup, 205 example, 398 syntax, 684 mysqld_safe, 679 MySqlException class (ADO.NET), 580 mysqlhotcopy, 356 mysqli class (PHP), 411, 697 mysqli interface (PHP), 410 mysqlimport, 364, 687 mysqli_connect_error (PHP), 412 mysqli_init (PHP), 412 mysqli_result class (PHP), 413 mysqli_stmt class (PHP), 416 MySQLNet provider (ADO.NET), 574 MySqlParameter class (ADO.NET), 581 mysqlshow, 688 MySqlTransaction class (ADO.NET), 589 mysql_affected_rows (C), 533 mysql_affected_rows (PHP), 405, 695 MYSQL_BIND (C), 538 mysql_bind_param (C), 538 mysql_change_db (C), 715, 716 mysql_change_user (C), 715, 716 mysql_change_user (PHP), 693 mysql_characterset_name (C), 716 mysql_client_encoding (PHP), 694 mysql_close (C), 532 mysql_close (PHP), 405, 693 mysql_connect (PHP), 404, 693 mysql_convert_table_format, 213 mysql_create_db (PHP), 693 mysql_data_seek (C), 718 mysql_data_seek (PHP), 695 mysql_db_query (PHP), 405, 694 mysql_drop_db (PHP), 693 mysql_errno (C), 544 mysql_errno (PHP), 693 mysql_error (C), 544 mysql_error (PHP), 693 mysql_execute (C), 538 mysql_fetch_array (PHP), 406, 695 mysql_fetch_assoc (PHP), 406 mysql_fetch_field (PHP), 408, 696 mysql_fetch_length (PHP), 696 mysql_fetch_lengths (C), 543 mysql_fetch_object (PHP), 406, 695 mysql_fetch_row (C), 533 mysql_fetch_row (PHP), 406, 695 mysql_field_flags (PHP), 408, 696 mysql_field_len (PHP), 696 mysql_field_name (PHP), 408, 696 mysql_field_table (PHP), 696 mysql_field_type (PHP), 696 mysql_fix_extensions, 681 mysql_fix_privileges, 680 mysql_fix_privilege_tables, 359 mysql_free_result (C), 534 mysql_free_result (PHP), 407, 695 www.it-ebooks.info 741 5351idx_final.qxd 742 8/26/05 11:37 PM Page 742 ■INDEX mysql_get_client_info (C), 716 mysql_get_host_info (C), 716 mysql_get_proto_info (C), 716 mysql_get_server_info (C), 716 mysql_get_xxx_info (PHP), 694 mysql_hex_string (C), 719 mysql_info (PHP), 405 mysql_init (C), 532 mysql_insertid (Perl), 484, 492 mysql_insert_id (C), 533 mysql_insert_id (PHP), 405, 695 mysql_install_db, 37, 268, 281, 680 mysql_kill (C), 717 mysql_list_dbs (PHP), 693 mysql_list_fields (PHP), 693 mysql_list_tables (PHP), 693 mysql_more_results (C), 536 mysql_next_result (C), 536 mysql_num_fields (PHP), 406, 695 mysql_num_rows (C), 718 mysql_num_rows (PHP), 40, 6956 mysql_options (C), 532 mysql_pconnect (PHP), 693 mysql_ping (C), 715, 716 mysql_query (C), 533 mysql_query (PHP), 694 mysql_query_test (PHP example), 409 mysql_query_unbuffered (PHP), 694 mysql_read_default_file (Perl), 482 mysql_read_default_group (Perl), 482 mysql_real_connect (C), 532 mysql_real_escape_string (C), 542 mysql_real_query (C), 543 MYSQL_RES (C), 533 mysql_result (PHP), 406, 695 mysql_row_seek (C), 718 mysql_row_tell (C), 718 mysql_select_db (PHP), 405, 693 mysql_set_server_option (C), 535 mysql_shutdown (C), 717 mysql_stat (C), 716 mysql_stat (PHP), 694 MYSQL_STMT (C), 538 mysql_stmt_bind_result (C), 540 mysql_stmt_data_seek (C), 540 mysql_stmt_fetch, 540 mysql_stmt_init (C), 538 mysql_stmt_num_rows (C), 540 mysql_stmt_prepare (C), 538 mysql_stmt_result_metadata (C), 540 mysql_stmt_store_result (C), 540 mysql_store_result (C), 533 mysql_store_result (Perl), 492 mysql_thread_id (C), 716 mysql_thread_id (PHP), 694 MYSQL_TIME (C), 540 mysql_unbuffered_query (PHP), 408 mysql_use_result (C), 533 mysql_use_result (Perl), 492 mysql_warning_count (C), 544 my_print_defaults, 671 my_ulonglong (C), 533 ■N named pipes, 264, 348, 673 naming rules, 599 NATURAL JOIN, 200 NDB tables, 141 net (Windows command), 22 NEW (trigger code), 342 NewRow method (ADO.NET), 585 next key locks, 259, 261 next method (Java), 518 NextResult method (ADO.NET), 584 next_result (PHP), 415 NO ACTION, 171 normal forms, 154, 155, 243 normalization, 154, 162 NOT NULL, 622 notee (mysql), 682 NOW, 656 no_zero_date mode, 351 no_zero_in_date mode, 351 NULL, 622 ADO, 556 ADO.NET, 583 C programming, 534 comparison, 196 import/export, 361 Java, 519 operators, 605 Perl, 490, 491 numbers, 602 NUMERIC, 144 NUMGEOMETRIES, 306 NUMINTERIORRINGS, 306 NUMPOINTS, 305 num_or_NULL (PHP example), 437 num_rows (PHP), 413 ■O object-oriented databases, object names, 599 object privileges, 275 ODBC, 117, 545 ODBC data provider (ADO.NET), 573 OdbcCommand class (ADO.NET), 578 OdbcConnection class (ADO.NET), 578 OdbcDataReader class (ADO.NET), 578 OGC, 300 OLAP, 234 OLD (trigger code), 342 old-passwords (mysqld), 291, 673 OLE-DB, 546 ON DELETE, 171 ON DUPLICATE KEY UPDATE, 631 ON UPDATE, 171 one-to-one relations, 166 www.it-ebooks.info 5351idx_final.qxd 8/26/05 11:37 PM Page 743 ■INDEX only_full_group_by mode, 351 Open method (ADO), 553 open source, 11 OPEN, 334 opengeodb database, 312 OpenGIS, 300 OpenOffice Base, 128 data source view, 133 optimization database design, 162 queries, 176 server, 393 speed InnoDB, 392 MySQL, 393 PHP, 455 replication, 375 tables, 636 OPTIMIZE TABLE, 383, 636 Options Indexes (Apache option), 40 oracle mode, 351 ORDER BY, 193, 641 UPDATE, 208, 651 DELETE, 209, 625 ORDER BY … COLLATE, 194 ORDER BY RAND, 246 OUT, 328 OUTFILE, 642 OVERLAPS, 308 ■P PACK_KEYS, 623 parameters (SPs), 328 passwords, 266 changing, 290 encryption since Version 4.1, 290 forgotten root password, 272 setting root password, 269 user table, 278 password file (MySQL access), 418 password protection for web directories, 40 pattern matching, 220, 605 performance estimating, 176 InnoDB, 392, 394 replication, 375 tables, 173 Perl, 481 backups at ISP, 399 DBI, 481, 700 error-handling, 494 establishing database connection, 482 evaluating record list, 485 executing SQL commands, 483 installing Red Hat, 36 SUSE, 27 Windows, 25 persistent connection, 483 Unicode, 493 upload to ISP, 399 persistent connections, 483, 693 PHP API reference, 693, 697 backup at ISP, 398 character strings and BLOBs, 424 configuring, 43 create form, 433 date and time, 425 error search (MyDb class), 421 extensions, 44 file download, 477 file upload, 466, 478 insert linked records, 427 installing Red Hat, 33 SUSE, 27 Windows, 23 Magic Quotes, 43, 430 mylibrary store title (example), 427 MySQL extension configuration (Windows), 24 mysql interface, 403, 410 NULL, 426 pagewise representation of results, 439 random server selection (replication), 382 recursion example, 449 self-compilation (Red Hat), 33 speed optimization, 455 stored procedures, 471 storing images, 464 Unicode, 461 upload to ISP, 399 php.ini file, 43 configuration for file transfer, 468 Unicode, 462 phpinfo (PHP), 24, 29 PHPIniDir (Apache option), 39 phpMyAdmin, 87–116 administration, 109, 398 authentication variants, 88 auxiliary functions, 110 configuring, 88-91 creating new users, 95 database creation and editing, 98 executing SQL commands, 104 foreign key rules, 100 importing/exporting databases, 105 installing, 88 PDF diagram, 113 security, 90 text import, 108 transformations, 115 user management, 94 viewing and editing data, 102 ping (mysqladmin), 346 pipes_as_concat mode, 351 pivot tables, 234 www.it-ebooks.info 743 5351idx_final.qxd 744 8/26/05 11:37 PM Page 744 ■INDEX POINT, 302 POINTN, 305 POLYGON, 302 port (mysqld), 348 port 3306, 294, 297, 513 postal codes (opengeodb database), 312 postgresql mode, 351 PostgreSQL, 16 post_max_size (PHP option), 44, 468 POW (example), 314 ppm (Perl package manager), 26 Prepare method (ADO.NET), 581 prepare statements ADO.NET, 581 C, 538 Java, 522 Perl, 484 PHP, 415 prepareStatement method (Java), 522 primary index, 5, 155 168 primary key, , 155, 168, 175 PRIMARY KEY, 622 PrintError (Perl), 494 privileges global vs object-related, 275 list of, 273 user table, 280 Pro version, 14 proc table, 322 PROCEDURE, 636 Process privilege, 275 PROCESSLIST, 649 procs_priv table, 287 Production version, programming (SQL), 230 Prompt (ODBC option), 551 PURGE MASTER LOGS, 636 ■Q qq (Perl), 490 queries, analysis of execution, 627 distinct values only, 191 logging slow, 373 optimization, 176 SELECT, 190, 638 SQL conditions, 195 subSELECT, 237, 238 query cache, 396 query method (PHP), 413 query optimization, 176 QUICK option (DELETE), 625 quoting character strings Perl, 490 PHP, 424 SQL, 600 VB, 559 ■R R-tree index, 308 radial search, 313 RaiseError (Perl), 494 RAND, 246 random numbers, 246 random sort order, 246 RDBMS, READ COMMITTED, 260 READ LOCAL LOCK, 254, 635 READ LOCK, 254, 635 Read method (ADO.NET), 583 READ UNCOMMITTED, 260 read-only (mysqld), 378 readline library, 66 read_buffer_size (mysqld), 395 read_rnd_buffer_size (mysqld), 395 REAL, 144 real_as_float mode, 351 real_connect (PHP), 412 records See data records Recordset class (ADO), 553, 554 record_buffer (mysqld), 395 recursion, 328 recursive relations, 167 Red Hat, localhost problems with, 282 Red Hat Enterprise Linux, 31 REFERENCES, 622 referential integrity, 170 REGEXP, 221, 605 rehash (mysql), 682 relational databases, relations, 111, 166, 167 relay files, 381 relay-log-purge (mysqld), 381 RELEASE_LOCK, 254 RELATED, 308 remove (mysqld), 22 RENAME AS, 617 RENAME TABLE, 636 REPAIR TABLE, 383, 637 REPEAT-UNTIL, 331 REPEATABLE READ, 260 REPLACE, 624, 637 replicate-xxx (mysqld), 675 replication, 374–383, 636, 648–650 alter slave configuration, 619 InnoDB tables, 382 interrupt logging, 645 REQUIRE (GRANT), 629 RESET MASTER, 637 RESET QUERY CACHE, 397, 637 RESET SLAVE, 637 RESTORE TABLE, 637 RESTRICT, 171 ResultSet class (Java) , 512, 518, 520 ResultSetMetaData class (Java), 520 RETURNS, 329 REVOKE, 288, 638 www.it-ebooks.info 5351idx_final.qxd 8/26/05 11:37 PM Page 745 ■INDEX RLIKE, 221, 605 ROLLBACK, 256, 638 rollback method PHP, 418, 494 Java, 522 Rollback method (ADO.NET), 589 ROLLBACK TO SAVEPOINT, 257, 638 ROLLUP (GROUP BY), 204 root password forgotten, 272 setting, 269 ROUND, 237, 314 rows (Perl), 487, 492 runtime environment (Java), 127 ■S safe_mysqld, 679 safe-user-create (mysqld), 673 SAP DB, 16 SAVEPOINT, 638 SaveToFile method (ADO), 557 schema (database), 180–184 See also database design security, 265, 288, 628 default settings, 267 first aid, 268 operating-system-level, 295 replication, 375 restoring default state (Unix/Linux), 268 secure installation, 269 two-tiered access control, 273 MySQL update from 4.n to 5.0, 359 SECURITY DEFINER, 325 SECURITY INVOKER, 325 SEC_TO_TIME, 224 SELECT, 638–644 analysis of query execution, 627 example, 190 EXPLAIN, 627 FOR UPDATE, 259 INTO, 642 INTO DUMPFILE, 643 INTO OUTFILE, 364, 642 LOCK IN SHARE MODE, 259 pagewise results (PHP), 439 SQL_CALC_FOUND_ROWS, 192 storing result in table, 233, 623 subSELECTs, 237, 238, 315 UNION, 200, 644 selection conditions (SQL), 640 selectrow_array (Perl), 486, 502 SELinux MySQL server, 33 PHP, 404, 411, 482 semicolon (mysql), 603 SERIAL, 611 SERIALIZABLE, 260 server See MySQL server id (mysqld), 377 server tuning, 393 server-side cursor (ADO), 554 ServerName (Apache option), 39 SESSION, 608, 644 SET, 151, 229, 330, 491, 644 SET AUTOCOMMIT, 257, 645 SET CHARACTER SET, 220, 645 SET FOREIGN_KEY_CHECKS, 645 SET NAMES, 67, 68, 220, 645 SET PASSWORD, 645 SET SQL_LOG_BIN, 645 SET SQL_QUERY_CACHE, 645 SET TRANSACTION ISOLATION LEVEL, 260, 645 setAutoCommit method (Java), 522 setBinaryStream method (Java), 523 setBlob/-Clob method (Java), 523 setBytes method (Java), 523 setCharacterStream method (Java), 523 setDatabaseName method (Java), 514 setServerName method (Java), 514 setURL method (Java), 514 setXxx method (Java), 522 SHARE MODE, 259 shared lock, 259 shared memory, 264, 3481 SHOW, 214 SHOW BINLOG EVENTS, 646 SHOW CHARACTER SET, 194, 646 SHOW COLLATION, 149, 194, 646 SHOW COLUMNS TYPES, 646 SHOW COLUMNS, 214, 646 SHOW CREATE DATABASE, 647 SHOW CREATE FUNCTION, 324, 647 SHOW CREATE PROCEDURE, 324, 647 SHOW CREATE TABLE, 210, 647 SHOW CREATE VIEW, 180, 647 SHOW DATABASES, 214, 647 SHOW ENGINES, 647 SHOW ERRORS, 647 SHOW FIELDS, 646 SHOW FUNCTION STATUS, 324, 648 SHOW GRANTS, 289, 648 SHOW INDEX, 648 SHOW INNODB STATUS, 648 SHOW KEYS, 214 SHOW LOGS, 648 SHOW MASTER LOGS, 648 SHOW MASTER STATUS, 648 SHOW PRIVILEGES, 648 SHOW PROCEDURE STATUS, 324, 649 SHOW PROCESSLIST, 649 SHOW SLAVE HOSTS, 649 SHOW SLAVE STATUS, 649 SHOW STATUS, 649 SHOW TABLE STATUS, 386, 649 SHOW TABLE TYPES, 649 SHOW TABLES, 214, 650 SHOW VARIABLES, 607, 650 www.it-ebooks.info 745 5351idx_final.qxd 746 8/26/05 11:37 PM Page 746 ■INDEX Show View privilege, 180 SHOW WARNINGS, 362, 650 skip-grant-tables (mysqld), 272, 295, 673 skip-host-cache (mysqld), 295, 673 skip-name-resolve (mysqld), 673 skip-networking (mysqld), 293, 297, 348, 673 skip-show-database (mysqld), 673 skip-xxx (mysqld), 671 slave_compressed_protocol (mysqld), 675 slave-skip-errors (mysqld), 675 SLAVE START, 650 SLAVE STOP, 650 slave system setup, 378 slow query log, 373 SMALLINT, 142 snapshot, 377 socket (mysqld), 348, 667, 672 socket files, 264, 292, 348 SOME, 238, 641 sort_buffer (mysqld), 395 sorting records, 193, 246 source (mysql), 65, 682 SP Administrator (PHP example), 472 SPACE, 163, 655 SPATIAL INDEX, 308, 622 spatial search, 313 special characters, 600 speed optimization InnoDB, 392 MySQL, 393 PHP, 455 replication, 375 SPs See stored procedures SQL (Structured Query Language), 5, 189–216 character strings, 217 command overview, 611 command reference, 614 compatibility, 6, 350 functions reference, 652 programming, 230 syntax, 599 SQL mode, 145, 350 SQL SECURITY DEFINER, 325 SQL SECURITY INVOKER, 325 SQL Server (Microsoft), converting to MySQL converter, 567 SQL variables, 231 SQL_BIG_RESULT, 639 SQL_BUFFER_RESULT, 639 SQL_CACHE, 639 SQL_CALC_FOUND_ROWS, 192, 639 SQL_LOG_BIN variable, 381, 645 SQL_NO_CACHE, 639 SQL_QUOTE_SHOW_CREATE, 647 SQL_SMALL_RESULT, 639 sql_string (PHP example), 437 SQL_THREAD, 650 SQRT, 314 SRID, 304 SSL encryption, 629 ssl_set (PHP), 412 Standard version, 14 StarOffice, 128, 133 START TRANSACTION, 650 STARTPOINT, 305 Statement class (Java), 512, 516 static MyISAM tables, 138 status (mysql), 65 STATUS, 649 STD, 661 STDDEV, 661 stored procedures (SPs), 6, 317–340 administration, 322 backup/restore, 325, 355, 474, 477 calling, 327 changing, 323 creating/ deleting, 323 determining code, 324 examples, 336 implementation, 322 language elements, 325 listing, 324 mysqldump, 355 parameters, 328 PHP, 471 recursion, 328 security, 325 SQL mode, 351 syntax, 325 store_result (PHP), 415, 417 STRAIGHT_JOIN, 199, 639 Stream class (ADO), 557 streaming ResultSet (Java), 520 strict_all_tables mode, 351 strict_transactions_tables mode, 351 strmov (C), 542 structure See database design Structured Query Language See SQL structured variables, 608 STR_TO_DATE, 659 SUBJECT (GRANT), 629 subSELECTs, 237, 238, 314, 641 SUBSTRING, 217 SUM, 234, 661 Super privilege, 342, 275 support, 15 SUSE Linux localhost problems with, 282 test environment installation, 27 sync-binlog (mysqld), 675 SYSDATE, 656 system DSNs, 118 system security, 295 system variables, 607, 650, 671 ■T tables altering, 212, 614–618 adding/deleting columns, 212 backing up, 205, 618 www.it-ebooks.info 5351idx_final.qxd 8/26/05 11:37 PM Page 747 ■INDEX change type (table driver), 617 check internal errors, 619 compressing, 385 copying, 233 creating, 210, 621 deleting, 213, 627 enabling access, 289 importing/exporting, 120, 360 locking, 634 optimizing, 636 options, 622 renaming, 617, 636 repairing, 385, 637 restoring backups, 637 table files, 142, 383 shrinking, 385 types, 138 tablespace files, 377, 386–391, 393 tables_priv table, 286 table_cache (mysqld), 395 TCP/IP protocol, 282, 264, 348 tee (mysql), 682 TEMPORARY, 621 temporary tables, 141, 246, 621 test databases, created by users, 268 TEXT, 147 text files, importing, 360, 632 threads (discussion forums), 184 threads (MySQL subprocesses) , 632, 649 time, 145, 222, 556, 602, 656 time zones, 227, 349 TIMESTAMP, 145 ADO, 556 avoiding changes with UPDATE, 226 INSERT, UPDATE, 631 Perl, 489, 490 Unix, 225 TIME_FORMAT, 222 TINYBLOB, 151 TINYINT, 142 TINYTEXT, 147 tmp_table_size (mysqld), 395 TOUCHES, 308, 311 trace (Perl), 495 transactions, 6, 255 ADO.NET, 589 isolation level, 260 Java, 522 logging, 390 Perl, 494 PHP, 409, 418 replication, 382 TRIGGER, 341 triggers, 6, 318, 341–343 TRUE, 609 TRUNCATE, 650 tuning (server tuning), 393 tx_isolation variable, 261 TYPE, 622 ■U UCS-2 character set, 148 UDFs, 296, 620 Unicode, ADO, 556 C, 542 Java, 519 LOAD DATA, 361 mysql (command interpreter), 67, 68 MySQL, 149 Perl, 493 PHP, 461 UTF-8 vs UCS-2, 148 VB, 55, 5596 UNION, 200, 644 UNIQUE, 175, 622 unique_checks variable, 393 UNIX_TIMESTAMP, 225, 490, 656 UNLOCK TABLES, 254, 651 UNSIGNED, 152 updatable_views_with_limit (mysqld), 179 UPDATE, 207 default values, 631 DELETE, 208, 651 LIMIT, 208, 651 ORDER BY, 208, 651 several tables, 208, 243, 651 syntax, 651 update log, 369 Update method (ADO.NET), 585 UpdateDataSet method (ADO.NET), 587 updateXxx method (Java), 521 upload_max_filesize (PHP option), 44, 468 uploading to ISP, 397 Usage privilege, 274 USE, 651 use_result (PHP), 415 users creating, 271, 288 mysql.user table, 277 test databases created by, 268 user-defined functions, 296, 620 user DSNs, 118 user interface, 61 user name, 265, 278 user table (access protection), 277 user variables, 607, 644 USING (DELETE command), 626 UTC (Coordinated Universal Time), 227, 656 utf8_decode (PHP), 461 utf8_encode (PHP), 461 UTM format, 300 ■V VALUES, 630, 631 VARCHAR, 147 variables, 230, 329, 607, 644 VARIABLES, 650 VB (Visual Basic), 548, 556, 559 www.it-ebooks.info 747 5351idx_final.qxd 748 8/26/05 11:37 PM Page 748 ■INDEX WITHIN, 308 WKB format, 300, 301 WKT format, 300, 301 WRITE LOCK, 254, 635 VB.NET (Visual Basic.NET), 573 VBA, 548 VBMySQLDirect library, 570 version number, views, 178 Visual Basic.NET (VB.NET), 573 Visual Basic (VB), 548, 556, 559 ■X ■W wasNull method (Java), 519 web directory protection (.htaccess), 40 Well-Known Text format, 300, 301 WHERE, 195 WHILE-DO, 332 Windows installation, 18 Windows service (MySQL), 22 WinMySQLadmin, 71 X function (GIS), 304 X509 standard, 629 XML files creating with mysqldump, 687 exporting, 366, 368 ■Y Y function (GIS), 304 ■Z zip codes (opengeodb database), 312 www.it-ebooks.info 5351idx_final.qxd 8/26/05 11:37 PM Page 749 www.it-ebooks.info 5351idx_final.qxd 8/26/05 11:37 PM Page 750 www.it-ebooks.info 5351idx_final.qxd 8/26/05 11:37 PM Page 751 www.it-ebooks.info 5351idx_final.qxd 8/26/05 11:37 PM Page 752 forums.apress.com FOR PROFESSIONALS BY PROFESSIONALS™ JOIN THE APRESS FORUMS AND BE PART OF OUR COMMUNITY You’ll find discussions that cover topics of interest to IT professionals, programmers, and enthusiasts just like you If you post a query to one of our forums, you can expect that some of the best minds in the business—especially Apress authors, who all write with The Expert’s Voice™—will chime in to help you Why not aim to become one of our most valuable participants (MVPs) and win cool stuff? Here’s a sampling of what you’ll find: DATABASES PROGRAMMING/BUSINESS Data drives everything Share information, exchange ideas, and discuss any database programming or administration issues Unfortunately, it is Talk about the Apress line of books that cover software methodology, best practices, and how programmers interact with the “suits.” INTERNET TECHNOLOGIES AND NETWORKING WEB DEVELOPMENT/DESIGN Try living without plumbing (and eventually IPv6) Talk about networking topics including protocols, design, administration, wireless, wired, storage, backup, certifications, trends, and new technologies Ugly doesn’t cut it anymore, and CGI is absurd Help is in sight for your site Find design solutions for your projects and get ideas for building an interactive Web site JAVA SECURITY We’ve come a long way from the old Oak tree Hang out and discuss Java in whatever flavor you choose: J2SE, J2EE, J2ME, Jakarta, and so on Lots of bad guys out there—the good guys need help Discuss computer and network security issues here Just don’t let anyone else know the answers! MAC OS X TECHNOLOGY IN ACTION All about the Zen of OS X OS X is both the present and the future for Mac apps Make suggestions, offer up ideas, or boast about your new hardware Cool things Fun things It’s after hours It’s time to play Whether you’re into LEGO® MINDSTORMS™ or turning an old PC into a DVR, this is where technology turns into fun OPEN SOURCE WINDOWS Source code is good; understanding (open) source is better Discuss open source technologies and related topics such as PHP, MySQL, Linux, Perl, Apache, Python, and more No defenestration here Ask questions about all aspects of Windows programming, get help on Microsoft technologies covered in Apress books, or provide feedback on any Apress Windows book HOW TO PARTICIPATE: Go to the Apress Forums site at http://forums.apress.com/ Click the New User link www.it-ebooks.info ... PM Page i The Definitive Guide to MySQL5 Third Edition Michael Kofler Translated By David Kramer www.it-ebooks.info 5351fm_final.qxd 8/26/05 6:12 PM Page ii The Definitive Guide to MySQL Copyright... in This Third Edition? This edition is an extensive revision of the second edition Most of the changes relate to changes in the MySQL server from version 4.1 to version 5.0 But there is also... most important administrative tools and user interfaces: mysql, mysqladmin, mysqldump; the programs MySQL Administrator, MySQL Query Browser; and finally phpMyAdmin The latter program is particularly

Ngày đăng: 06/03/2019, 15:15