Obtaining MySQL Software - MySQL Cookbook (2007)

MySQL Cookbook (2007)

Appendix A. Obtaining MySQL Software

Most of the table definitions and programs discussed in this book are available online so that you can avoid typing them in yourself. To run the examples, you’ll also need access to MySQL, of course, as well as the appropriate MySQL-specific interfaces for the programming languages that you want to use. This appendix describes what software you need and where to get it.

Obtaining Sample Source Code and Data

The examples in this book are based on source code and sample data from two distributions named recipes and mcb-kjv that are available at the MySQL Cookbook companion web site (see Preface). Visit the site at this address:

http://www.kitebird.com/mysql-cookbook/

The recipes distribution is the primary source of examples. It’s available as a compressed tar file (recipes.tar.gz) or as a ZIP file (recipes.zip). Either distribution format when unpacked creates a directory named recipes.

The recipes distribution contains programs as shown in the book, but in many cases also includes implementations in additional languages. For example, a script shown in the book using Python may be available in the recipes distribution in Perl, Ruby, PHP, or Java as well. This may save you some translation effort should you want to convert a program as shown in the book to a different language.

The Kitebird site provides access to the mcb-kjv distribution, which contains the text of the King James Version of the Bible, formatted suitably for loading into MySQL. It’s used in Chapter 5, as the source of a reasonably large body of text for examples that demonstrate FULLTEXTsearches, and occasionally elsewhere in the book. This distribution is provided separately from the recipes distribution due to its size. It’s available as a compressed tar file (mcb-kjv.tar.gz) or as a ZIP file (mcb-kjv.zip). Either distribution format when unpacked creates a directory namedmcb-kjv.

The mcb-kjv distribution was derived from KJV text originally obtained from the Unbound Bible site (http://www.unboundbible.org). I have restructured that text to be more usable for the examples in this book. The mcb-kjv distribution includes notes that describe the modifications that I made.

Obtaining MySQL and Related Software

If you’re going to access a MySQL server run by somebody else, you need only the MySQL client software on your own machine. To run your own server, you’ll need a full MySQL distribution.

To write your own MySQL-based programs, you’ll need to communicate with the server through a language-specific API. The Perl, Ruby, PHP, and Python interfaces rely on the MySQL C API client library to handle the low-level client-server protocol. For Perl, Ruby, and Python, you must install the C client library and header files first. PHP includes the MySQL client support files, but must be compiled with MySQL support enabled or you won’t be able to use it. The Java JDBC driver for MySQL implements the client-server protocol itself, so it does not require the MySQL C client library.

You may not need to install the client software yourself—it might already have been built and installed for you by others. This is a common situation if you have an account with an Internet Service Provider (ISP) for computing services such as a web server that is already enabled to provide access to MySQL. Under such circumstances, the MySQL libraries and header files will already have been installed by the ISP staff.

MySQL

Visit the following site to obtain a MySQL distribution:

http://dev.mysql.com/

MySQL distributions include installation instructions, and the MySQL Reference Manual also provides extensive installation information. The manual is available online at the MySQL site and in printed form from MySQL Press.

If you need to install the MySQL C client library and header files, they’re available if you install MySQL from a source distribution, or if you install MySQL using a binary (precompiled) distribution other than an RPM binary distribution. Under Linux, you have the option of installing MySQL using RPM files, but be aware that the client library and header files are not installed unless you install the development RPM. (There are separate RPM files for the server, the standard client programs, and the development libraries and header files.) If you don’t install the development RPM, you’ll join the many Linux users who’ve asked, “I installed MySQL, but I cannot find the libraries or header files; where are they?”

Perl Support

General Perl information is available at:

http://www.perl.org/

Perl software can be obtained from the Comprehensive Perl Archive Network (CPAN):

http://cpan.perl.org/

To write MySQL-based Perl programs, you’ll need the DBI module and the MySQL-specific DBD module, DBD::mysql.

To install these modules under Unix, it may be easiest to let Perl itself help you. For example, to install DBI and DBD::mysql, run the following commands (you’ll probably need to do this as root):

#perl -MCPAN -e shell

cpan> install DBI

cpan> install DBD::mysql

If the last command complains about failed tests, use force install DBD::mysql instead. Under ActiveState Perl for Windows, you can use the ppm utility:

C:\>ppm

ppm> install DBI

ppm> install DBD-mysql

You can use the CPAN shell or ppm to install other Perl modules mentioned in this book as well.

Ruby Support

To obtain Ruby itself, visit:

http://www.ruby-lang.org/

The Ruby DBI module is available at RubyForge:

http://rubyforge.org/projects/ruby-dbi/

You’ll need at least version 0.1.1 of Ruby DBI to be able to use all the features described in this book, such as option file support and SQLSTATE support.

The Ruby DBI driver for MySQL requires the mysql-ruby module, available from the Ruby Application Archive:

http://raa.ruby-lang.org/project/mysql-ruby/

The PageTemplate package used in Chapter 18 can be obtained from RubyForge:

http://rubyforge.org/projects/pagetemplate/

If you plan to use session support as described in Chapter 20, you’ll need the mysql-session package, available from the Ruby Application Archive:

http://raa.ruby-lang.org/project/mysql-session/

For mysql-session, obtain the package, unpack it, and install its mysqlstore.rb and sqlthrow.rb files in some directory that your Ruby interpreter searches when looking for library files.

PHP Support

PHP software distributions and installation instructions are available here:

http://www.php.net/

PHP source distributions include the MySQL client library, so you need not obtain it separately. However, you’ll need to enable MySQL support explicitly when you configure the distribution. If you use a binary distribution, be sure that it includes MySQL support.

PHP includes a pear command-line utility that you can run to install various PEAR modules. Run it without arguments for a help message. To install the PEAR DB module for database access support, use this command:

#pear install DB

The Smarty template package used in Chapter 18, can be obtained from the Smarty site:

http://smarty.php.net/

Python Support

Python software distributions and installation instructions are available here:

http://www.python.org/

MySQLdb, the DB-API driver module that provides MySQL support, is available at SourceForge:

http://sourceforge.net/projects/mysql-python/

Java Support

You’ll need a Java compiler to build and run Java programs. The javac and jikes compilers are two possible choices. On many systems, you’ll find these installed already. Otherwise, you can get a compiler as part of the Java Software Development Kit (SDK). If no SDK is installed on your system, versions are available for Solaris, Linux, and Windows at Sun’s Java site:

http://java.sun.com/j2se/

Several Java drivers are available that provide MySQL connectivity for the JDBC interface. This book assumes the use of MySQL Connector/J, which is available here:

http://dev.mysql.com/downloads/

Web Servers

In the web programming chapters, this book uses Apache for Perl, Ruby, PHP, and Python scripts, and Tomcat for JavaServer Pages scripts. Apache and Tomcat both are available from the Apache Software Group; visit the following sites:

http://httpd.apache.org/

http://tomcat.apache.org/

The Apache Jakarta Project site provides access to the Jakarta implementation of the JSP Standard Tag Library that is used in this book for writing JSP pages:

http://jakarta.apache.org/taglibs/

For information about configuring Apache and Tomcat to run MySQL-based scripts, see Recipes and .