| Preface |
|
xi | |
| 1 Using the mysql Client Program |
|
1 | (24) |
|
1.1 Setting Up a MySQL User Account |
|
|
2 | (2) |
|
1.2 Creating a Database and a Sample Table |
|
|
4 | (2) |
|
1.3 What to Do if mysql Cannot Be Found |
|
|
6 | (2) |
|
1.4 Specifying mysql Command Options |
|
|
8 | (5) |
|
1.5 Executing SQL Statements Interactively |
|
|
13 | (2) |
|
1.6 Executing SQL Statements Read from a File or Program |
|
|
15 | (2) |
|
1.7 Controlling mysql Output Destination and Format |
|
|
17 | (5) |
|
1.8 Using User-Defined Variables in SQL Statements |
|
|
22 | (3) |
| 2 Writing MySQL-Based Programs |
|
25 | (80) |
|
2.1 Connecting, Selecting a Database, and Disconnecting |
|
|
29 | (13) |
|
|
|
42 | (9) |
|
2.3 Writing Library Files |
|
|
51 | (14) |
|
2.4 Executing Statements and Retrieving Results |
|
|
65 | (14) |
|
2.5 Handling Special Characters and NULL Values in Statements |
|
|
79 | (10) |
|
2.6 Handling Special Characters in Identifiers |
|
|
89 | (2) |
|
2.7 Identifying NULL Values in Result Sets |
|
|
91 | (4) |
|
2.8 Techniques for Obtaining Connection Parameters |
|
|
95 | (8) |
|
2.9 Conclusion and Words of Advice |
|
|
103 | (2) |
| 3 Selecting Data from Tables |
|
105 | (22) |
|
3.1 Specifying Which Columns and Rows to Select |
|
|
106 | (2) |
|
3.2 Naming Query Result Columns |
|
|
108 | (4) |
|
3.3 Sorting Query Results |
|
|
112 | (1) |
|
3.4 Removing Duplicate Rows |
|
|
113 | (1) |
|
3.5 Working with NULL Values |
|
|
114 | (2) |
|
3.6 Writing Comparisons Involving NULL in Programs |
|
|
116 | (1) |
|
3.7 Using Vies to Simplify Table Access |
|
|
117 | (2) |
|
3.8 Selecting Data from Multiple Tables |
|
|
119 | (2) |
|
3.9 Selecting Rows from the Beginning, End, or Middle of Query Results |
|
|
121 | (3) |
|
3.10 What to Do When LIMIT Requires the "Wrong" Sort Order |
|
|
124 | (1) |
|
3.11 Calculating LIMIT Values from Expressions |
|
|
125 | (2) |
| 4 Table Management |
|
127 | (12) |
|
|
|
127 | (1) |
|
4.2 Saving a Query Result in a Table |
|
|
128 | (3) |
|
4.3 Creating Temporary Tables |
|
|
131 | (2) |
|
4.4 Generating Unique Table Names |
|
|
133 | (2) |
|
4.5 Checking or Changing a Table Storage Engine |
|
|
135 | (1) |
|
4.6 Copying a Table Using mysqldump |
|
|
136 | (3) |
| 5 Working with Strings |
|
139 | (40) |
|
|
|
140 | (4) |
|
5.2 Choosing a String Data Type |
|
|
144 | (2) |
|
5.3 Setting the Client Connection Character Set |
|
|
146 | (2) |
|
5.4 Writing String Literals |
|
|
148 | (2) |
|
5.5 Checking or Changing a String's Character Set or Collation |
|
|
150 | (3) |
|
5.6 Converting the Lettercase of a String |
|
|
153 | (2) |
|
5.7 Controlling Case Sensitivity in String Comparisons |
|
|
155 | (3) |
|
5.8 Pattern Matching with SQL Patterns |
|
|
158 | (2) |
|
5.9 Pattern Matching with Regular Expressions |
|
|
160 | (5) |
|
5.10 Breaking Apart or Combining Strings |
|
|
165 | (3) |
|
5.11 Searching for Substrings |
|
|
168 | (1) |
|
5.12 Using Full-Text Searches |
|
|
169 | (4) |
|
5.13 Using a Full-Text Search with Short Words |
|
|
173 | (2) |
|
5.14 Requiring or Prohibiting Full-Text Search Words |
|
|
175 | (2) |
|
5.15 Performing Full-Text Phrase Searches |
|
|
177 | (2) |
| 6 Working with Dates and Times |
|
179 | (54) |
|
6.1 Choosing a Temporal Data Type |
|
|
180 | (2) |
|
6.2 Using Fractional Seconds Support |
|
|
182 | (1) |
|
6.3 Changing MySQL's Date Format |
|
|
183 | (4) |
|
6.4 Setting the Client Time Zone |
|
|
187 | (2) |
|
6.5 Shifting Temporal Values Between Time Zones |
|
|
189 | (1) |
|
6.6 Determining the Current Date or Time |
|
|
190 | (1) |
|
6.7 Using TIMESTAMP or DATETIME to Track Row-Modification Times |
|
|
191 | (3) |
|
6.8 Extracting Parts of Dates or Times |
|
|
194 | (5) |
|
6.9 Synthesizing Dates or Times from Component Values |
|
|
199 | (2) |
|
6.10 Converting Between Temporal Values and Basic Units |
|
|
201 | (4) |
|
6.11 Calculating Intervals Between Dates or Times |
|
|
205 | (5) |
|
6.12 Adding Date or Time Values |
|
|
210 | (5) |
|
|
|
215 | (1) |
|
6.14 Finding the First Day, Last Day, or Length of a Month |
|
|
216 | (3) |
|
6.15 Calculating Dates by Substring Replacement |
|
|
219 | (1) |
|
6.16 Finding the Day of the Week for a Date |
|
|
220 | (1) |
|
6.17 Finding Dates for Any Weekday of a Given Week |
|
|
221 | (3) |
|
6.18 Performing Leap-Year Calculations |
|
|
224 | (3) |
|
6.19 Canonizing Not-Quite-ISO Date Strings |
|
|
227 | (1) |
|
6.20 Selecting Rows Based on Temporal Characteristics |
|
|
228 | (5) |
| 7 Sorting Query Results |
|
233 | (38) |
|
7.1 Using ORDER BY to Sort Query Results |
|
|
234 | (4) |
|
7.2 Using Expressions for Sorting |
|
|
238 | (1) |
|
7.3 Displaying One Set of Values While Sorting by Another |
|
|
239 | (4) |
|
7.4 Controlling Case Sensitivity of String Sorts |
|
|
243 | (3) |
|
|
|
246 | (4) |
|
7.6 Sorting by Substrings of Column Values |
|
|
250 | (1) |
|
7.7 Sorting by Fixed-Length Substrings |
|
|
250 | (4) |
|
7.8 Sorting by Variable-Length Substrings |
|
|
254 | (4) |
|
7.9 Sorting Hostnames in Domain Order |
|
|
258 | (3) |
|
7.10 Sorting Dotted-Quad IP Values in Numeric Order |
|
|
261 | (2) |
|
7.11 Floating Values to the Head or Tail of the Sort Order |
|
|
263 | (3) |
|
7.12 Defining a Custom Sort Order |
|
|
266 | (1) |
|
|
|
267 | (4) |
| 8 Generating Summaries |
|
271 | (36) |
|
8.1 Basic Summary Techniques |
|
|
273 | (6) |
|
8.2 Creating a View to Simplify Using a Summary |
|
|
279 | (1) |
|
8.3 Finding Values Associated with Minimum and Maximum Values |
|
|
280 | (2) |
|
8.4 Controlling String Case Sensitivity for MIN() and MAX() |
|
|
282 | (1) |
|
8.5 Dividing a Summary into Subgroups |
|
|
283 | (4) |
|
8.6 Summaries and NULL Values |
|
|
287 | (3) |
|
8.7 Selecting Only Groups with Certain Characteristics |
|
|
290 | (1) |
|
8.8 Using Counts to Determine Whether Values Are Unique |
|
|
291 | (1) |
|
8.9 Grouping by Expression Results |
|
|
292 | (1) |
|
8.10 Summarizing Noncategorical Data |
|
|
293 | (3) |
|
8.11 Finding Smallest or Largest Summary Values |
|
|
296 | (2) |
|
8.12 Date-Based Summaries |
|
|
298 | (2) |
|
8.13 Working with Per-Group and Overall Summary Values Simultaneously |
|
|
300 | (3) |
|
8.14 Generating a Report That Includes a Summary and a List |
|
|
303 | (4) |
| 9 Using Stored Routines, Triggers, and Scheduled Events |
|
307 | (28) |
|
9.1 Creating Compound-Statement Objects |
|
|
310 | (2) |
|
9.2 Using Stored Functions to Encapsulate Calculations |
|
|
312 | (2) |
|
9.3 Using Stored Procedures to "Return" Multiple Values |
|
|
314 | (1) |
|
9.4 Using Triggers to Implement Dynamic Default Column Values |
|
|
315 | (2) |
|
9.5 Using Triggers to Simulate Function-Based Indexes |
|
|
317 | (3) |
|
9.6 Simulating TIMESTAMP Properties for Other Date and Time Types |
|
|
320 | (2) |
|
9.7 Using Triggers to Log Changes to a Table |
|
|
322 | (3) |
|
9.8 Using Events to Schedule Database Actions |
|
|
325 | (2) |
|
9.9 Writing Helper Routines for Executing Dynamic SQL |
|
|
327 | (1) |
|
9.10 Handling Errors Within Stored Programs |
|
|
328 | (4) |
|
9.11 Using Triggers to Preprocess or Reject Data |
|
|
332 | (3) |
| 10 Working with Metadata |
|
335 | (32) |
|
10.1 Determining the Number of Rows Affected by a Statement |
|
|
337 | (3) |
|
10.2 Obtaining Result Set-Metadata |
|
|
340 | (10) |
|
10.3 Determining Whether a Statement Produced a Result Set |
|
|
350 | (1) |
|
10.4 Using Metadata to Format Query Output |
|
|
350 | (4) |
|
10.5 Listing or Checking Existence of Databases or Tables |
|
|
354 | (2) |
|
10.6 Accessing Table Column Definitions |
|
|
356 | (5) |
|
10.7 Getting ENUM and SET Column Information |
|
|
361 | (2) |
|
10.8 Getting Server Metadata |
|
|
363 | (1) |
|
10.9 Writing Applications That Adapt to the MySQL Server Version |
|
|
364 | (3) |
| 11 Importing and Exporting Data |
|
367 | (42) |
|
11.1 Importing Data with LOAD DATA and mysqlimport |
|
|
371 | (12) |
|
|
|
383 | (1) |
|
11.3 Exporting Query Results from MySQL |
|
|
383 | (2) |
|
11.4 Importing and Exporting NULL Values |
|
|
385 | (2) |
|
11.5 Writing Your Own Data Export Programs |
|
|
387 | (5) |
|
11.6 Converting Datafiles from One Format to Another |
|
|
392 | (1) |
|
11.7 Extracting and Rearranging Datafile Columns |
|
|
393 | (3) |
|
11.8 Exchanging Data Between MySQL and Microsoft Excel |
|
|
396 | (2) |
|
11.9 Exporting Query Results as XML |
|
|
398 | (3) |
|
11.10 Importing XML into MySQIY |
|
|
401 | (3) |
|
11.11 Guessing Table Structure from a Datafile |
|
|
404 | (5) |
| 12 Validating and Reformatting Data |
|
409 | (36) |
|
12.1 Using the SQL Mode to Reject Bad Input Values |
|
|
410 | (1) |
|
12.2 Validating and Transforming Data |
|
|
411 | (4) |
|
12.3 Using Pattern Matching to Validate Data |
|
|
415 | (2) |
|
12.4 Using Patterns to Match Broad Content Types |
|
|
417 | (1) |
|
12.5 Using Patterns to Match Numeric Values |
|
|
418 | (2) |
|
12.6 Using Patterns to Match Dates or Times |
|
|
420 | (4) |
|
12.7 Using Patterns to Match Email Addresses or URLs |
|
|
424 | (1) |
|
12.8 Using Table Metadata to Validate Data |
|
|
425 | (3) |
|
12.9 Using a Lookup Table to Validate Data |
|
|
428 | (3) |
|
12.10 Converting Two-Digit Year Values to Four-Digit Norm |
|
|
431 | (1) |
|
12.11 Performing Validity Checking on Date or Time Subparts |
|
|
432 | (3) |
|
12.12 Writing Date-Processing Utilities |
|
|
435 | (5) |
|
12.13 Importing Non-ISO Date Values |
|
|
440 | (1) |
|
12.14 Exporting Dates Using Non-ISO Formats |
|
|
441 | (1) |
|
|
|
442 | (3) |
| 13 Generating and Using Sequences |
|
445 | (28) |
|
13.1 Creating a Sequence Column and Generating Sequence Values |
|
|
446 | (3) |
|
13.2 Choosing the Definition for a Sequence Column |
|
|
449 | (2) |
|
13.3 The Effect of Row Deletions on Sequence Generation |
|
|
451 | (2) |
|
13.4 Retrieving Sequence Values |
|
|
453 | (4) |
|
13.5 Renumbering an Existing Sequence |
|
|
457 | (3) |
|
13.6 Extending the Range of a Sequence Column |
|
|
460 | (1) |
|
13.7 Reusing Values at the Top of a Sequence |
|
|
460 | (1) |
|
13.8 Ensuring That Rows Are Renumbered in a Particular Order |
|
|
461 | (1) |
|
13.9 Sequencing an Unsequenced Table |
|
|
462 | (2) |
|
13.10 Managing Multiple Auto-Increment Values Simultaneously |
|
|
464 | (1) |
|
13.11 Using Auto-Increment Values to Associate Tables |
|
|
465 | (2) |
|
13.12 Using Sequence Generators as Counters |
|
|
467 | (4) |
|
13.13 Generating Repeating Sequences |
|
|
471 | (2) |
| 14 Using Joins and Subqueries |
|
473 | (38) |
|
14.1 Finding Matches Between Tables |
|
|
474 | (8) |
|
14.2 Finding Mismatches Between Tables |
|
|
482 | (5) |
|
14.3 Identifying and Removing Mismatched or Unattached Rows |
|
|
487 | (3) |
|
14.4 Comparing a Table to Itself |
|
|
490 | (4) |
|
14.5 Producing Master-Detail Lists and Summaries |
|
|
494 | (3) |
|
14.6 Enumerating a Many-to-Many Relationship |
|
|
497 | (4) |
|
14.7 Finding Per-Group Minimum or Maximum Values |
|
|
501 | (3) |
|
14.8 Using a Join to Fill or Identify Holes in a List |
|
|
504 | (3) |
|
14.9 Using a Join to Control Query Sort Order |
|
|
507 | (2) |
|
14.10 Referring to Join Output Column Names in Programs |
|
|
509 | (2) |
| 15 Statistical Techniques |
|
511 | (38) |
|
15.1 Calculating Descriptive Statistics |
|
|
512 | (3) |
|
15.2 Per-Group Descriptive Statistics |
|
|
515 | (2) |
|
15.3 Generating Frequency Distributions |
|
|
517 | (3) |
|
15.4 Counting Missing Values |
|
|
520 | (2) |
|
15.5 Calculating Linear Regressions or Correlation Coefficients |
|
|
522 | (3) |
|
15.6 Generating Random Numbers |
|
|
525 | (2) |
|
15.7 Randomizing a Set of Rows |
|
|
527 | (2) |
|
15.8 Selecting Random Items from a Set of Rows |
|
|
529 | (2) |
|
15.9 Calculating Successive-Row Differences |
|
|
531 | (2) |
|
15.10 Finding Cumulative Sums and Running Averages |
|
|
533 | (5) |
|
|
|
538 | (3) |
|
15.12 Computing Team Standings |
|
|
541 | (8) |
| 16 Handling Duplicates |
|
549 | (16) |
|
16.1 Preventing Duplicates from Occurring in a Table |
|
|
550 | (2) |
|
16.2 Dealing with Duplicates When Loading Rows into a Table |
|
|
552 | (4) |
|
16.3 Counting and Identifying Duplicates |
|
|
556 | (4) |
|
16.4 Eliminating Duplicates from a Table |
|
|
560 | (5) |
| 17 Performing Transactions |
|
565 | (12) |
|
17.1 Choosing a Transactional Storage Engine |
|
|
566 | (1) |
|
17.2 Performing Transactions Using SQL |
|
|
567 | (2) |
|
17.3 Performing Transactions from Within Programs |
|
|
569 | (2) |
|
17.4 Using Transactions in Perl Programs |
|
|
571 | (2) |
|
17.5 Using Transactions in Ruby Programs |
|
|
573 | (1) |
|
17.6 Using Transactions in PHP Programs |
|
|
574 | (1) |
|
17.7 Using Transactions in Python Programs |
|
|
575 | (1) |
|
17.8 Using Transactions in Java Programs |
|
|
576 | (1) |
| 18 Introduction to MySQI on the Web |
|
577 | (28) |
|
18.1 Basic Principles of Web Page Generation |
|
|
579 | (2) |
|
18.2 Using Apache to Run Web Scripts |
|
|
581 | (10) |
|
18.3 Using Tomcat to Run Web Scripts |
|
|
591 | (5) |
|
18.4 Encoding Special Characters in Web Output |
|
|
596 | (9) |
| 19 Generating Web Content from Query Results |
|
605 | (42) |
|
19.1 Displaying Query Results as Paragraphs |
|
|
606 | (2) |
|
19.2 Displaying Query Results as Lists |
|
|
608 | (10) |
|
19.3 Displaying Query Results as Tables |
|
|
618 | (4) |
|
19.4 Displaying Query Results as Hyperlinks |
|
|
622 | (4) |
|
19.5 Creating Navigation Indexes from Database Content |
|
|
626 | (5) |
|
19.6 Storing Images or Other Binary Data |
|
|
631 | (7) |
|
19.7 Serving Images or Other Binary Data |
|
|
638 | (3) |
|
|
|
641 | (2) |
|
19.9 Serving Query Results for Download |
|
|
643 | (4) |
| 20 Processing Web Input with MySQL |
|
647 | (78) |
|
20.1 Writing Scripts That Generate Web Forms |
|
|
650 | (3) |
|
20.2 Creating Single-Pick Form Elements from Database Content |
|
|
653 | (16) |
|
20.3 Creating Multiple-Pick Form Elements from Database Content |
|
|
669 | (5) |
|
20.4 Loading Database Content into a Form |
|
|
674 | (5) |
|
20.5 Collecting Web Input |
|
|
679 | (10) |
|
20.6 Validating Web Input |
|
|
689 | (2) |
|
20.7 Storing Web Input in a Database |
|
|
691 | (3) |
|
20.8 Processing File Uploads |
|
|
694 | (6) |
|
20.9 Performing Web-Based Database Searches |
|
|
700 | (3) |
|
20.10 Generating Previous-Page and Next-Page Links |
|
|
703 | (5) |
|
20.11 Generating "Click to Sort" Table Headings |
|
|
708 | (4) |
|
20.12 Web Page Access Counting |
|
|
712 | (4) |
|
20.13 Web Page Access Logging |
|
|
716 | (1) |
|
20.14 Using MySQL for Apache Logging |
|
|
717 | (8) |
| 21 Using MySQL-Based Web Session Management |
|
725 | (32) |
|
21.1 Using MySQL-Based Sessions in Perl Applications |
|
|
728 | (6) |
|
21.2 Using MySQL-Based Storage in Ruby Applications |
|
|
734 | (4) |
|
21.3 Using MySQL-Based Storage with the PHP Session Manager |
|
|
738 | (10) |
|
21.4 Using MySQL for Session-Backing Store with Tomcat |
|
|
748 | (9) |
| 22 Server Administration |
|
757 | (26) |
|
22.1 Configuring the Server |
|
|
757 | (3) |
|
22.2 Managing the Plug-In Interface |
|
|
760 | (2) |
|
22.3 Controlling Server Logging |
|
|
762 | (6) |
|
22.4 Rotating or Expiring Logfiles |
|
|
s765 | |
|
22.5 Rotating Log Tables or Expiring Log Table Rows |
|
|
768 | (1) |
|
22.6 Monitoring the MySQL Server |
|
|
769 | (11) |
|
22.7 Creating and Using Backups |
|
|
780 | (3) |
| 23 Security |
|
783 | (22) |
|
23.1 Understanding the mysql.user Table |
|
|
784 | (1) |
|
23.2 Managing User Accounts |
|
|
785 | (5) |
|
23.3 Implementing a Password Policy |
|
|
790 | (3) |
|
23.4 Checking Password Strength |
|
|
793 | (1) |
|
|
|
794 | (1) |
|
23.6 Assigning Yourself a New Password |
|
|
795 | (1) |
|
23.7 Resetting an Expired Password |
|
|
795 | (1) |
|
23.8 Finding and Fixing Insecure Accounts |
|
|
796 | (4) |
|
23.9 Disabling Use of Accounts with Pre-4.1 Passwords |
|
|
800 | (1) |
|
23.10 Finding and Removing Anonymous Accounts |
|
|
801 | (1) |
|
23.11 Modifying "Any Host" and "Many Host" Accounts |
|
|
802 | (3) |
| Index |
|
805 | |