If you ever wanted to start using the open source MySQL server application on your computer, this article is for you. It will show you how to obtain, install, configure, and test the MySQL server on your system, whether you are running UNIX or Windows. It is excerpted from My SQL The Complete Reference by Vikram Vaswani (McGraw-Hill/Osborne, 2003; ISBN: 0072224770).
ONE OF THE NICER things about MySQL is the fact that it’s an open-source application licensed under the General Public License (GPL); users are encouraged to download, modify, and use it free of charge. This open licensing policy has played an important role in MySQL’s widespread acceptance and popularity in the developer community; according to statistics published on the MySQL web site, MySQL is in use at more than 4 million sites worldwide, with more than 25,000 copies of the MySQL database server downloaded every day!
In this chapter, I’m going to help add to those numbers, by taking you through the process of obtaining, installing, configuring, and testing the MySQL server on your workstation. This chapter covers installation of both binary and source versions on UNIX and Microsoft Windows, and it also explains the differences between the MySQL server versions available, with a view to helping you select the right one for your needs.
The first order of business is to drop by the official MySQL web site (http://www.mysql.com/downloads/mysql.html) and get yourself a copy of the last stable release of the software. This isn’t necessarily as easy as it sounds—like ice-cream, MySQL comes in many flavors, and you’ll need to select the one that’s most appropriate for your needs.
You’ll need to make two primary decisions when selecting which MySQL distribution to download and use:
Choosing which version to install
Choosing between binary and source distributions
Choosing Which Version to Install
MySQL AB currently makes the following two versions of the MySQL database server available on its web site:
MySQL Standard This is the standard version of the MySQL database server, which includes support for both the regular, non-transactional tables and the newer, transaction-safe tables. It is suited for production environments requiring a stable, flexible, and robust database engine.
MySQL Max This version includes the feature set of the standard version, together with newer, more experimental capabilities. It is not always best suited for production environments, since it usually includes a fair share of not-completely-stable enhancements.
Both these versions of MySQL are licensed under the GPL and may be freely downloaded and used under the terms of that license.
In most cases, MySQL Standard is the version you should use—it’s the version used in all the examples in this book, and it’s stable, feature-rich, and well-suited for most common applications. You should select MySQL Max only if that version includes new features that you need or are keen to try out—or if you’re a geek with a penchant for living life on the bleeding edge all the time.
Choosing Between Binary and Source Distributions
MySQL AB makes both source and binary distributions of the MySQL database server available for download on its web site. As of this writing, binary distributions are available for Linux, Solaris, FreeBSD, Mac OS X, Windows 95/98/2000/XP/NT/ ME, HP-UX, IBM AIX, SCO OpenUNIX, and SGI Irix, and source distributions are available for both Windows and UNIX platforms.
In most cases, it’s preferable to use a precompiled binary distribution rather than a source distribution—MySQL AB puts in a lot of time and effort to create binary distributions for various platforms, and using these distributions is generally considered a Good Idea. These precompiled binary distributions are also easier to install than source
Pay It Forward It should be noted that, in addition to the two versions discussed in the section “Choosing Which Version to Install,” MySQL AB also offers two other versions of the MySQL database server, MySQL Pro and MySQL Classic, which are licensed commercially and are therefore not freely available for download.
What’s the difference between the two? MySQL Pro includes support for transactions (with the exception of the licensing terms, it is identical in every way to MySQL Standard), while MySQL Classic does not. If you’re interested in purchasing a commercial license for these versions of the MySQL database server, drop by http://order.mysql.com and find out more about what your greenbacks buy you.
distributions, and they are optimized by MySQL’s developers to ensure maximum performance on the target systems.
That said, for a number of possible reasons, a source distribution might work better for you than a binary distribution:
You’d like to recompile MySQL with compile-time options different from the defaults provided by the MySQL team. (For example, you might like to use a different value for the installation path.)
You’d like to compile a smaller, lighter version of MySQL that doesn’t include all the features (and overhead) of the standard binary distribution.
You’d like to enable support for newer, experimental features that are disabled by default in the standard binaries.
You’d like to view or make modifications to the source code of the application.
You have waaaaay too much time on your hands, and you’d like to impress the pretty girl next door with your deep and profound knowledge of MySQL’s internals. By the way, according to surveys, only six percent of MySQL users are women.
If you’re new to MySQL, I’d recommend that you go with a binary distribution— source distributions are typically used only by experienced developers who either need to tweak MySQL’s default values for their own purposes or who are interested in studying the source code to see how it works. Such users usually also have the time, inclination, and expertise to diagnose and troubleshoot compilation and configuration issues that may arise during the installation process.
Once you’ve figured out which version of MySQL you need, point your browser to http://www.mysql.com/downloads/mysql.html and select the appropriate file from the choices available. The MySQL software is also mirrored on a number of other sites around the world, and you can obtain a list of mirrors from http://www.mysql .com/downloads/mirrors.html You can make your download more efficient by selecting the site that is geographically closest to you. Once your download is complete, save it to a directory on your hard drive and skip to the section titled “Installing and Configuring MySQL,” a bit later in this chapter.
What’s in a Name? You’ve probably noticed that MySQL distributions are named using a particular naming scheme—for example, mysql-4.0.9-gamma.tar.gz. The numbers in the file name indicate the version number of the software, with the additional suffix indicating the stability level of the software (alpha, beta, or gamma).
Note that we will assume, throughout this chapter, that you are using MySQL version 4.0.15, and that all your downloads are saved in the /tmp (UNIX) or c:\temp (Windows) directory, and I will reference that directory in subsequent instructions.
Installing and Configuring MySQL
Once you’ve got yourself a copy of MySQL, it’s time to install and configure it for your specific platform. This section includes information on how to do just that, for both Windows and UNIX platforms, using both binary and source distributions.
It should be noted at the outset that this section is designed merely to provide an overview and general guide to the process of installing and configuring MySQL. It is not intended as a replacement for the installation documentation that ships with MySQL. If you encounter difficulties installing or configuring the various programs described here, drop by the MySQL web site or search the mailing lists for detailed troubleshooting information and advice.