Amazon.co.uk Review
The scene is set with a brief history of MySQL, explaining its position as a fast and generally free alternative to the fuller-featured commercial heavyweights like Oracle or DB2. Next comes an introduction to SQL, followed by three chapters on administration, covering configuration, data recovery, tuning, security and user management. There's a brief look at database design too. That accounts for around one third of the book. The rest is about programming with chapters on using MySQL from Perl, Python, PHP and Java, and a look at how to extend MySQL with user-defined functions written in C. The last part of the book is a reference section, covering SQL syntax and functions, along with the MySQL API in PHP, C, and Python.
This is an excellent book for getting started with MySQL as well as a convenient reference. It has a broad scope, which means it does not go deeply into the various topics. For example, those using PHP might be better off with a more specialist title like Web Database Applications with PHP and MySQL. On the other hand, Managing and Using MySQL is ideal for a general and highly accessible overview of what MySQL can do.--Tim Anderson
Geekboy, slashdot.org, July 2, 2002
Steve Mitchell, KCJava.org, August 17, 2002
Andrew Binstock, SD Times, Nov 2002
Paul Schneider, Compunotes
Peter MacIntyre, eweek, Feb 6, 2003
Product Description
MySQL is a popular and robust open source database product that supports key subsets of SQL on both Linux and Unix systems. MySQL is free for nonprofit use and costs a small amount for commercial use. Unlike commercial databases, MySQL is affordable and easy to use. This book includes introductions to SQL and to relational database theory. If you plan to use MySQL to build web sites or other Linux or Unix applications, this book teaches you to do that, and it will remain useful as a reference once you understand the basics. Ample tutorial material and examples are included throughout.
This book has all you need to take full advantage of this powerful database management system. It takes you through the whole process from installation and configuration to programming interfaces and database administration. This second edition has a greatly enhanced administration chapter that includes information on administrative tools, server configuration, server startup and shutdown, log file management, database backup and restore, and database administration and repair. In addition, a new chapter on security describes data, server, and client-server security, while a chapter on extending MySQL provides an overview of MySQL internals and describes the use of MySQL user-defined functions.
If you know C/C++, Java, Perl, PHP, or Python, you can write programs to interact with your MySQL database. In addition, you can embed queries and updates directly in an HTML file so that a web page becomes its own interface to the database. Managing and Using MySQL includes chapters on the programming language interfaces, and it also includes a complete reference section with specific function calls for each language.
Also included in the reference section are references to the SQL language, and details of the MySQL system variables, programs, and utilities. New to the second edition is a reference to the internal MySQL tables, which will be of particular interest to those who want to work extensively with MySQL security.
From the Publisher
About the Author
Tim King has been working with computers since the early 1980s, when he programmed games on his Commodore 64 computer and founded a computer club in his high school. He earned a bachelor's degree in computer science from the University of Minnesota Institute of Technology in 1991. While there, he taught Unix and vi classes and was the leader of a rag-tag group of vi devotees called the "VI Zombies." Presently, Tim is a software consultant in San Francisco, CA, specializing in database and web technologies. His favorite activity is snowboarding, but he also enjoys photography and reading. You can reach him at kingt@verio.com
George Reese has taken an unusual path into business software development. After earning a B.A. in philosophy from Bates College in Lewiston, Maine, George went off to Hollywood where he worked on television shows such as "The People's Court" and ESPN's "Up Close". The L.A. riots convinced him to return to Maine where he finally became involved with software development and the Internet. George has since specialized in the development of Internet-oriented Java enterprise systems and the strategic role of technology in business processes. He is the author of Database Programming with JDBC and Java, 2nd Edition and the world's first JDBC driver, the mSQL-JDBC driver for mSQL. He currently lives in Minneapolis, Minnesota with his wife Monique and three cats, Misty, Gypsy, and Tia. He makes a living as the National Practice Director of Technology Strategy for digital@jwt in Minneapolis.
Excerpted from Managing and Using MySQL by George Reese, Randy Jay Yarger, Tim King. Copyright © 2002. Reprinted by permission. All rights reserved.
Java is one of the simplest languages in which you can write MySQL applications. Its database access API, Java Database Connectivity (JDBC), is one of the more mature database-independent APIs for database access in common use. Most of what we cover in this chapter can be applied to Oracle, Sybase, MS SQL Server, mSQL, and any other database engine, as well as MySQL. In fact, almost none of the MySQL-specific information in this chapter has anything to do with coding. Instead, the "proprietary" information relates only to downloading MySQL support for JDBC and configuring the runtime environment. Everything else is largely independent of MySQL.
In this chapter, we assume you have a basic understanding of the Java programming language and Java concepts. If you do not already have this background, we strongly recommend taking a look at Learning Java, by Pat Niemeyer and Jonathan Knudsen (O'Reilly). For more details on how to build the sort of three-tier database applications we discussed in Chapter 8, take a look at Database Programming with JDBC and Java, by George Reese (O'Reilly).
The JDBC API
Like all Java APIs, JDBC is a set of classes and interfaces that work together to support a specific set of functionality. In the case of JDBC, this functionality is database access. The classes and interfaces that make up the JDBC API are thus abstractions from concepts common to database access for any kind of database. A Connection, for example, is a Java interface representing a database connection. Similarly, a ResultSet represents a result set of data returned from an SQL SELECT. Java combines the classes that form the JDBC API in the java.sql package, which Sun introduced in JDK 1.1.
The underlying details of database access naturally differ from vendor to vendor. JDBC does not actually deal with those details. Most of the classes in the java.sql package are in fact interfaces with no implementation details. Individual database vendors provide implementations of these interfaces in the form of something called a JDBC driver. As a database programmer, however, you need to know only a few details about the driver you are using--the rest you manage via the JDBC interfaces.
The first database-dependent thing you need to know is what drivers exist for your database. Different people provide different JDBC implementations for a variety of databases. As a database programmer, you should select a JDBC implementation that will provide the greatest stability and performance for your application. Though it may seem counterintuitive, JDBC implementations provided by the database vendors are generally at the bottom of the pack when it comes to stability and flexibility. As an open source project, however, MySQL relies on drivers provided by other developers in the community.
Sun has created four classifications of JDBC drivers based on their architectures. Each JDBC driver classification represents a trade-off between performance and flexibility.
Type 1
Type 1 drivers use a bridging technology to access a database. The JDBC-ODBC bridge that comes with JDK 1.2 is the most common example of this kind of driver. It provides a gateway to the ODBC API. Implementations of the ODBC API, in turn, perform the actual database access. Though useful for learning JDBC and quick testing, bridging solutions are rarely appropriate for production environments.
Type 2
Type 2 drivers are native API drivers. "Native API" means that the driver contains Java code that calls native C or C++ methods provided by the database vendor. In the context of MySQL, a Type 2 driver is one that uses MySQL's C API under the hood to talk to MySQL on behalf of your application. Type 2 drivers generally provide the best performance, but they require the installation of native libraries on clients that need to access the database. Applications using Type 2 drivers have a limited degree of portability.
Type 3
Type 3 drivers provide a client with a pure Java implementation of the JDBC API in which the driver uses a network protocol to talk to middleware on the server. This middleware, in turn, performs the actual database access. The middleware may or may not use JDBC for its database access. The Type 3 architecture is actually more of a benefit to driver vendors than application architects since it enables the vendor to write a single implementation and claim support for any database that has a JDBC driver. Unfortunately, it has weak performance and unpredictable stability.
Type 4
Using network protocols built into the database engine, Type 4 drivers talk directly to the database using Java sockets. This is a pure Java solution. Because these network protocols are almost never documented, most Type 4 drivers come from the database vendors. The open source nature of MySQL, however, has enabled several independent developers to write different Type 4 MySQL drivers.
Practically speaking, Type 2 and Type 4 drivers are the only viable choices for a production application. At an abstract level, the choice between Type 2 and Type 4 comes down to a single issue: is platform independence critical? By platform independence, we mean that the application can be bundled up into a single jar and run on any platform. Type 2 drivers have a hard time with platform independence since you need to package platform-specific libraries with the application. If the database access API has not been ported to a client platform, your application will not run on the platform. On the other hand, Type 2 drivers tend to perform better than Type 4 drivers.
Knowing the driver type provides only a starting point for making a decision about which JDBC driver to use in your application. The decision really comes down to knowing the drivers that exist for your database of choice and how they compare to each other. Table 13-1 lists the JDBC drivers available for MySQL. Of course, you can use any ODBC bridge to talk to MySQL as well--but we do not recommend it under any circumstance for MySQL developers.