2.9. MySQL Installation Using a Source Distribution

MySQL 5.0

2.9. MySQL Installation Using a Source Distribution

Before you proceed with an installation from source, first check whether our binary is available for your platform and whether it works for you. We put a great deal of effort into ensuring that our binaries are built with the best possible options.

To obtain a source distribution for MySQL, Section 2.1.3, “How to Get MySQL”.

MySQL source distributions are provided as compressed tar archives and have names of the form .tar.gz, where is a number like .

You need the following tools to build and install MySQL from source:

  • GNU to uncompress the distribution.

  • A reasonable tar to unpack the distribution. GNU tar is known to work. Some operating systems come with a pre-installed version of tar that is known to have problems. For example, the tar provided with early versions of Mac OS X tar, SunOS 4.x and Solaris 8 and earlier are known to have problems with long filenames. On Mac OS X, you can use the pre-installed gnutar program. On other systems with a deficient tar, you should install GNU tar first.

  • A working ANSI C++ compiler. gcc 2.95.2 or later, egcs 1.0.2 or later or egcs 2.91.66, SGI C++, and SunPro C++ are some of the compilers that are known to work. is not needed when using gcc. gcc 2.7.x has a bug that makes it impossible to compile some perfectly legal C++ files, such as . If you have only gcc 2.7.x, you must upgrade your gcc to be able to compile MySQL. gcc 2.8.1 is also known to have problems on some platforms, so it should be avoided if a new compiler exists for the platform.

    gcc 2.95.2 or later is recommended when compiling MySQL 3.23.x.

  • A good make program. GNU make is always recommended and is sometimes required. If you have problems, we recommend GNU make 3.75 or newer.

If you are using a version of gcc recent enough to understand the option, it is very important that you use this option. Otherwise, you may compile a binary that crashes randomly. We also recommend that you use and along with . When in doubt, do the following:

CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors \
       -fno-exceptions -fno-rtti" ./configure \
       --prefix=/usr/local/mysql --enable-assembler \
       --with-mysqld-ldflags=-all-static

On most systems, this gives you a fast and stable binary.

If you run into problems and need to file a bug report, please use the instructions in Section 1.8, “How to Report Bugs or Problems”.

2.9.1. Source Installation Overview

The basic commands that you must execute to install a MySQL source distribution are:

shell> 
shell> 
shell> .tar.gz | tar -xvf -
shell> 
shell> 
shell> 
shell> 
shell> 
shell> 
shell> 
shell> 
shell> 
shell> 
shell> 

If you start from a source RPM, do the following:

shell> .src.rpm

This makes a binary RPM that you can install. For older versions of RPM, you may have to replace the command rpmbuild with rpm instead.

Note: This procedure does not set up any passwords for MySQL accounts. After following the procedure, proceed to Section 2.10, “Post-Installation Setup and Testing”, for post-installation setup and testing.

A more detailed version of the preceding description for installing MySQL from a source distribution follows:

  1. Add a login user and group for mysqld to run as:

    shell> 
    shell> 
    

    These commands add the group and the user. The syntax for useradd and groupadd may differ slightly on different versions of Unix, or they may have different names such as adduser and addgroup.

    You might want to call the user and group something else instead of . If so, substitute the appropriate name in the following steps.

  2. Pick the directory under which you want to unpack the distribution and change location into it.

  3. Obtain a distribution file using the instructions in Section 2.1.3, “How to Get MySQL”.

  4. Unpack the distribution into the current directory:

    shell> .tar.gz | tar xvf -
    

    This command creates a directory named .

    With GNU tar, no separate invocation of is necessary. You can use the following alternative command to uncompress and extract the distribution:

    shell> .tar.gz
    
  5. Change location into the top-level directory of the unpacked distribution:

    shell> 
    

    Note that currently you must configure and build MySQL from this top-level directory. You cannot build it in a different directory.

  6. Configure the release and compile everything:

    shell> 
    shell> 
    

    When you run configure, you might want to specify other options. Run ./configure --help for a list of options. Section 2.9.2, “Typical configure Options”, discusses some of the more useful options.

    If configure fails and you are going to send mail to a MySQL mailing list to ask for assistance, please include any lines from that you think can help solve the problem. Also include the last couple of lines of output from configure. To file a bug report, please use the instructions in Section 1.8, “How to Report Bugs or Problems”.

    If the compile fails, see Section 2.9.4, “Dealing with Problems Compiling MySQL”, for help.

  7. Install the distribution:

    shell> 
    

    If you want to set up an option file, use one of those present in the directory as a template. For example:

    shell> 
    

    You might need to run these commands as .

    If you want to configure support for tables, you should edit the file, remove the character before the option lines that start with , and modify the option values to be what you want. See Section 4.3.2, “Using Option Files”, and Section 14.2.3, “ Configuration”.

  8. Change location into the installation directory:

    shell> 
    
  9. If you haven't installed MySQL before, you must create the MySQL grant tables:

    shell> 
    

    If you run the command as , you should use the option as shown. The value of the option should be the name of the login account that you created in the first step to use for running the server. If you run the command while logged in as that user, you can omit the option.

    After using mysql_install_db to create the grant tables for MySQL, you must restart the server manually. The mysqld_safe command to do this is shown in a later step.

  10. Change the ownership of program binaries to and ownership of the data directory to the user that you run mysqld as. Assuming that you are located in the installation directory (), the commands look like this:

    shell> 
    shell> 
    shell> 
    

    The first command changes the owner attribute of the files to the user. The second changes the owner attribute of the data directory to the user. The third changes the group attribute to the group.

  11. If you want MySQL to start automatically when you boot your machine, you can copy to the location where your system has its startup files. More information can be found in the script itself; see also Section 2.10.2.2, “Starting and Stopping MySQL Automatically”.

  12. You can set up new accounts using the bin/mysql_setpermission script if you install the and Perl modules. For instructions, see Section 2.14, “Perl Installation Notes”.

After everything has been installed, you should test your distribution. To start the MySQL server, use the following command:

shell> 

If that command fails immediately and prints , you can find some information in the .err file in the data directory.

More information about mysqld_safe is given in Section 5.4.1, “mysqld_safe — MySQL Server Startup Script”.

Note: The accounts that are listed in the MySQL grant tables initially have no passwords. After starting the server, you should set up passwords for them using the instructions in Section 2.10, “Post-Installation Setup and Testing”.

2.9.2. Typical configure Options

The configure script gives you a great deal of control over how you configure a MySQL source distribution. Typically you do this using options on the configure command line. You can also affect configure using certain environment variables. See Appendix F, Environment Variables. For a list of options supported by configure, run this command:

shell> 

Some of the more commonly used configure options are described here:

  • To compile just the MySQL client libraries and client programs and not the server, use the option:

    shell> 
    

    If you have no C++ compiler, some client programs such as mysql cannot be compiled because they require C++.. In this case, you can remove the code in configure that tests for the C++ compiler and then run ./configure with the option. The compile step should still try to build all clients, but you can ignore any warnings about files such as . (If make stops, try make -k to tell it to continue with the rest of the build even if errors occur.)

  • If you want to build the embedded MySQL library (), use the option.

  • If you don't want your log files and database directories located under , use a configure command something like one of these:

    shell> 
    shell> 
               
    

    The first command changes the installation prefix so that everything is installed under rather than the default of . The second command preserves the default installation prefix, but overrides the default location for database directories (normally ) and changes it to .

    You can also specify the installation directory and data directory locations at server startup time by using the and options. These can be given on the command line or in an MySQL option file, although it is more common to use an option file. See Section 4.3.2, “Using Option Files”.

  • If you are using Unix and you want the MySQL socket file location to be somewhere other than the default location (normally in the directory or ), use a configure command like this:

    shell> 
               
    

    The socket filename must be an absolute pathname. You can also change the location of at server startup by using a MySQL option file. See Section A.4.5, “How to Protect or Change the MySQL Unix Socket File”.

  • If you want to compile statically linked programs (for example, to make a binary distribution, to get better performance, or to work around problems with some Red Hat Linux distributions), run configure like this:

    shell> 
               
    
  • If you are using gcc and don't have or installed, you can tell configure to use gcc as your C++ compiler:

    shell> 
    

    When you use gcc as your C++ compiler, it does not attempt to link in or . This may be a good thing to do even if you have those libraries installed. Some versions of them have caused strange problems for MySQL users in the past.

    The following list indicates some compilers and environment variable settings that are commonly used with each one.

    • gcc 2.7.2:

      CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors"
      
    • egcs 1.0.3a:

      CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors \
      -fno-exceptions -fno-rtti"
      
    • gcc 2.95.2:

      CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro \
      -felide-constructors -fno-exceptions -fno-rtti"
      
    • 2.90.29 or newer:

      CFLAGS="-O3 -mpentiumpro -mstack-align-double" CXX=gcc \
      CXXFLAGS="-O3 -mpentiumpro -mstack-align-double \
      -felide-constructors -fno-exceptions -fno-rtti"
      

    In most cases, you can get a reasonably optimized MySQL binary by using the options from the preceding list and adding the following options to the configure line:

    --prefix=/usr/local/mysql --enable-assembler \
    --with-mysqld-ldflags=-all-static
    

    The full configure line would, in other words, be something like the following for all recent gcc versions:

    CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro \
    -felide-constructors -fno-exceptions -fno-rtti" ./configure \
    --prefix=/usr/local/mysql --enable-assembler \
    --with-mysqld-ldflags=-all-static
    

    The binaries we provide on the MySQL Web site at http://dev.mysql.com/downloads/ are all compiled with full optimization and should be perfect for most users. See Section 2.1.2.5, “MySQL Binaries Compiled by MySQL AB”. There are some configuration settings you can tweak to build an even faster binary, but these are only for advanced users. See Section 7.5.4, “How Compiling and Linking Affects the Speed of MySQL”.

    If the build fails and produces errors about your compiler or linker not being able to create the shared library (where is a version number), you can work around this problem by giving the option to configure. In this case, configure does not build a shared library.

  • By default, MySQL uses the (cp1252 West European) character set. To change the default set, use the option:

    shell> 
    

    may be one of , , , , , , , , , , , , , , , , , , , , , , , or . See Section 5.11.1, “The Character Set Used for Data and Sorting”. (Additional character sets might be available. Check the output from ./configure --help for the current list.)

    The default collation may also be specified. MySQL uses the collation by default. To change this, use the option:

    shell> 
    

    To change both the character set and the collation, use both the and options. The collation must be a legal collation for the character set. (Use the statement to determine which collations are available for each character set.)

    Warning: If you change character sets after having created any tables, you must run myisamchk -r -q --set-collation= on every table. Your indexes may be sorted incorrectly otherwise. This can happen if you install MySQL, create some tables, and then reconfigure MySQL to use a different character set and reinstall it.

    With the configure option , you can define which additional character sets should be compiled into the server. is one of the following:

    • A list of character set names separated by spaces

    • to include all character sets that can't be dynamically loaded

    • to include all character sets into the binaries

    Clients that want to convert characters between the server and the client should use the statement. See Section 13.5.3, “ Syntax”, and Section 10.4, “Connection Character Sets and Collations”.

  • To configure MySQL with debugging code, use the option:

    shell> 
    

    This causes a safe memory allocator to be included that can find some errors and that provides output about what is happening. See Section E.1, “Debugging a MySQL Server”.

  • If your client programs are using threads, you must compile a thread-safe version of the MySQL client library with the configure option. This creates a library with which you should link your threaded applications. See Section 22.2.15, “How to Make a Threaded Client”.

  • It is possible to build MySQL 5.0 with large table support using the option, beginning with MySQL 5.0.4.

    This option causes the variables that store table row counts to be declared as rather than . This enables tables to hold up to approximately 1.844E+19 ((232)2) rows rather than 232 (~4.295E+09) rows. Previously it was necessary to pass to the compiler manually in order to enable this feature.

  • See Section 2.13, “Operating System-Specific Notes”, for options that pertain to particular operating systems.

  • See Section 5.9.7.2, “Using SSL Connections”, for options that pertain to configuring MySQL to support secure (encrypted) connections.

2.9.3. Installing from the Development Source Tree

Caution: You should read this section only if you are interested in helping us test our new code. If you just want to get MySQL up and running on your system, you should use a standard release distribution (either a binary or source distribution).

To obtain our most recent development source tree, first download and install the BitKeeper free client if you do not have it. The client can be obtained from http://www.bitmover.com/bk-client.shar.

To install the BitKeeper client on Unix, use these commands:

shell> 
shell> 
shell> 
shell> 

To install the BitKeeper client on Windows, use these instructions:

  1. Download and install Cygwin from http://cygwin.com.

  2. Make sure gcc and make have been installed under Cygwin. You can test this by issuing which gcc and which make commands. If either one is not installed, run Cygwin's package manager, select gcc, make, or both, and install them.

  3. Under Cygwin, execute these commands:

    shell> 
    shell> 
    

    Then edit the and change the line that reads to this:

    $(CC) $(CFLAGS) -o sfio sfio.c -lz
    

    Now run the make command and set the path:

    shell> 
    shell> 
    

The BitKeeper free client is shipped with its source code. The only documentation available for the free client is the source code itself.

After you have installed the BitKeeper client, you can access the MySQL development source tree:

  1. Change location to the directory you want to work from, and then use the following command to make a local copy of the MySQL 5.0 branch:

    shell> 
    

    In the preceding example, the source tree is set up in the subdirectory of your current directory.

    The initial download of the source tree may take a while, depending on the speed of your connection. Please be patient.

  2. You need GNU make, autoconf 2.58 (or newer), automake 1.8, libtool 1.5, and m4 to run the next set of commands. Even though many operating systems come with their own implementation of make, chances are high that the compilation fails with strange error messages. Therefore, it is highly recommended that you use GNU make (sometimes named gmake) instead.

    Fortunately, a large number of operating systems ship with the GNU toolchain preinstalled or supply installable packages of these. In any case, they can also be downloaded from the following locations:

    To configure MySQL 5.0, you also need GNU bison 1.75 or later. Older versions of bison may report this error:

    sql_yacc.yy:#####: fatal error: maximum table size (32767) exceeded
    

    Note: The maximum table size is not actually exceeded; the error is caused by bugs in older versions of bison.

    The following example shows the typical commands required to configure a source tree. The first command changes location into the top-level directory of the tree; replace with the appropriate directory name.

    shell> 
    shell> 
    shell> 
    shell> 
    shell> 
    shell> 
    

    Or you can use BUILD/autorun.sh as a shortcut for the following sequence of commands:

    shell> 
    shell> 
    shell> 
    shell> 
    shell> 
    

    The command lines that change directory into the and directories are used to configure the and Berkeley DB () storage engines. You can omit these command lines if you to not require or support.

    If you get some strange errors during this stage, verify that you really have libtool installed.

    A collection of our standard configuration scripts is located in the subdirectory. You may find it more convenient to use the script than the preceding set of shell commands. To compile on a different architecture, modify the script by removing flags that are Pentium-specific.

  3. When the build is done, run make install. Be careful with this on a production machine; the command may overwrite your live release installation. If you have another installation of MySQL, we recommend that you run ./configure with different values for the , , and options than those used for your production server.

  4. Play hard with your new installation and try to make the new features crash. Start by running make test. See Section 24.1.2, “MySQL Test Suite”.

  5. If you have gotten to the make stage, but the distribution does not compile, please enter the problem into our bugs database using the instructions given in Section 1.8, “How to Report Bugs or Problems”. If you have installed the latest versions of the required GNU tools, and they crash trying to process our configuration files, please report that also. However, if you execute and get a error or a similar problem, do not report it. Instead, make sure that all the necessary tools are installed and that your variable is set correctly so that your shell can find them.

  6. After initially copying the repository with sfioball to obtain the source tree, you should use update periodically to update your local copy. To do this any time after you have set up the repository, use this command:

    shell> 
    
  7. You can examine the change history for the tree with all the diffs by viewing the file in the source tree and looking at the descriptions listed there. To examine a particular changeset, you would have to use the sfioball command to extract two particular revisions of the source tree, and then use an external diff command to compare them. If you see some funny diffs or code that you have a question about, do not hesitate to send email to the MySQL mailing list. See Section 1.7.1, “MySQL Mailing Lists”. Also, if you think you have a better idea on how to do something, send an email message to the list with a patch.

You can also browse changesets, comments, and source code online. To browse this information for MySQL 5.0, go to http://mysql.bkbits.net:8080/mysql-5.0.

2.9.4. Dealing with Problems Compiling MySQL

All MySQL programs compile cleanly for us with no warnings on Solaris or Linux using gcc. On other systems, warnings may occur due to differences in system include files. See Section 2.9.5, “MIT-pthreads Notes”, for warnings that may occur when using MIT-pthreads. For other problems, check the following list.

The solution to many problems involves reconfiguring. If you do need to reconfigure, take note of the following:

  • If configure is run after it has previously been run, it may use information that was gathered during its previous invocation. This information is stored in . When configure starts up, it looks for that file and reads its contents if it exists, on the assumption that the information is still correct. That assumption is invalid when you reconfigure.

  • Each time you run configure, you must run make again to recompile. However, you may want to remove old object files from previous builds first because they were compiled using different configuration options.

To prevent old configuration information or object files from being used, run these commands before re-running configure:

shell> 
shell> 

Alternatively, you can run make distclean.

The following list describes some of the problems when compiling MySQL that have been found to occur most often:

  • If you get errors such as the ones shown here when compiling , you probably have run out of memory or swap space:

    Internal compiler error: program cc1plus got fatal signal 11
    Out of virtual memory
    Virtual memory exhausted
    

    The problem is that gcc requires a huge amount of memory to compile with inline functions. Try running configure with the option:

    shell> 
    

    This option causes to be added to the compile line if you are using gcc and if you are using something else. You should try the option even if you have so much memory and swap space that you think you can't possibly have run out. This problem has been observed to occur even on systems with generous hardware configurations, and the option usually fixes it.

  • By default, configure picks c++ as the compiler name and GNU c++ links with . If you are using gcc, that behavior can cause problems during configuration such as this:

    configure: error: installation or configuration problem:
    C++ compiler cannot create executables.
    

    You might also observe problems during compilation related to g++, , or .

    One cause of these problems is that you may not have g++, or you may have g++ but not , or . Take a look at the file. It should contain the exact reason why your C++ compiler didn't work. To work around these problems, you can use gcc as your C++ compiler. Try setting the environment variable to . For example:

    shell> 
    

    This works because gcc compiles C++ source files as well as g++ does, but does not link in or by default.

    Another way to fix these problems is to install g++, , and . However, we recommend that you not use or with MySQL because this only increases the binary size of mysqld without providing any benefits. Some versions of these libraries have also caused strange problems for MySQL users in the past.

  • If your compile fails with errors such as any of the following, you must upgrade your version of make to GNU make:

    making all in mit-pthreads
    make: Fatal error in reader: Makefile, line 18:
    Badly formed macro assignment
    

    Or:

    make: file `Makefile' line 18: Must be a separator (:
    

    Or:

    pthread.h: No such file or directory
    

    Solaris and FreeBSD are known to have troublesome make programs.

    GNU make 3.75 is known to work.

  • If you want to define flags to be used by your C or C++ compilers, do so by adding the flags to the and environment variables. You can also specify the compiler names this way using and . For example:

    shell> 
    shell> 
    shell> 
    shell> 
    shell> 
    

    See Section 2.1.2.5, “MySQL Binaries Compiled by MySQL AB”, for a list of flag definitions that have been found to be useful on various systems.

  • If you get errors such as those shown here when compiling mysqld, configure did not correctly detect the type of the last argument to , , or :

    cxx: Error: mysqld.cc, line 645: In this statement, the referenced
         type of the pointer value ''length'' is ''unsigned long'',
         which is not compatible with ''int''.
    new_sock = accept(sock, (struct sockaddr *)&cAddr, &length);
    

    To fix this, edit the file (which is generated by configure). Look for these lines:

    /* Define as the base type of the last arg to accept */
    #define SOCKET_SIZE_TYPE XXX
    

    Change to or , depending on your operating system. (You must do this each time you run configure because configure regenerates .)

  • The file is generated from . Normally, the build process does not need to create because MySQL comes with a pre-generated copy. However, if you do need to re-create it, you might encounter this error:

    "sql_yacc.yy", line  fatal: default action causes potential...
    

    This is a sign that your version of yacc is deficient. You probably need to install bison (the GNU version of yacc) and use that instead.

  • On Debian Linux 3.0, you need to install instead of the default if you want to compile MySQL with Berkeley DB support.

  • If you need to debug mysqld or a MySQL client, run configure with the option, and then recompile and link your clients with the new client library. See Section E.2, “Debugging a MySQL Client”.

  • If you get a compilation error on Linux (for example, SuSE Linux 8.1 or Red Hat Linux 7.3) similar to the following one, you probably do not have g++ installed:

    libmysql.c:1329: warning: passing arg 5 of `gethostbyname_r' from
    incompatible pointer type
    libmysql.c:1329: too few arguments to function `gethostbyname_r'
    libmysql.c:1329: warning: assignment makes pointer from integer
    without a cast
    make[2]: *** [libmysql.lo] Error 1
    

    By default, the configure script attempts to determine the correct number of arguments by using g++ (the GNU C++ compiler). This test yields incorrect results if g++ is not installed. There are two ways to work around this problem:

    • Make sure that the GNU C++ g++ is installed. On some Linux distributions, the required package is called ; on others, it is named gcc-c++.

    • Use gcc as your C++ compiler by setting the environment variable to gcc:

      export CXX="gcc"
      

    You must run configure again after making either of those changes.

2.9.5. MIT-pthreads Notes

This section describes some of the issues involved in using MIT-pthreads.

On Linux, you should not use MIT-pthreads. Use the installed LinuxThreads implementation instead. See Section 2.13.1, “Linux Notes”.

If your system does not provide native thread support, you should build MySQL using the MIT-pthreads package. This includes older FreeBSD systems, SunOS 4.x, Solaris 2.4 and earlier, and some others. See Section 2.1.1, “Operating Systems Supported by MySQL”.

MIT-pthreads is not part of the MySQL 5.0 source distribution. If you require this package, you need to download it separately from http://www.mysql.com/Downloads/Contrib/pthreads-1_60_beta6-mysql.tar.gz

After downloading, extract this source archive into the top level of the MySQL source directory. It creates a new subdirectory named .

  • On most systems, you can force MIT-pthreads to be used by running configure with the option:

    shell> 
    

    Building in a non-source directory is not supported when using MIT-pthreads because we want to minimize our changes to this code.

  • The checks that determine whether to use MIT-pthreads occur only during the part of the configuration process that deals with the server code. If you have configured the distribution using to build only the client code, clients do not know whether MIT-pthreads is being used and use Unix socket file connections by default. Because Unix socket files do not work under MIT-pthreads on some platforms, this means you need to use or with a value other than when you run client programs.

  • When MySQL is compiled using MIT-pthreads, system locking is disabled by default for performance reasons. You can tell the server to use system locking with the option. This is needed only if you want to be able to run two MySQL servers against the same data files, but that is not recommended, anyway.

  • Sometimes the pthread command fails to bind to a socket without any error message (at least on Solaris). The result is that all connections to the server fail. For example:

    shell> 
    mysqladmin: connect to server at '' failed;
    error: 'Can't connect to mysql server on localhost (146)'
    

    The solution to this problem is to kill the mysqld server and restart it. This has happened to us only when we have forcibly stopped the server and restarted it immediately.

  • With MIT-pthreads, the system call isn't interruptible with (break). This is noticeable only when you run mysqladmin --sleep. You must wait for the call to terminate before the interrupt is served and the process stops.

  • When linking, you might receive warning messages like these (at least on Solaris); they can be ignored:

    ld: warning: symbol `_iob' has differing sizes:
        (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
    file /usr/lib/libc.so value=0x140);
        /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
    ld: warning: symbol `__iob' has differing sizes:
        (file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
    file /usr/lib/libc.so value=0x140);
        /my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
    
  • Some other warnings also can be ignored:

    implicit declaration of function `int strtoll(...)'
    implicit declaration of function `int strtoul(...)'
    
  • We have not been able to make work with MIT-pthreads. (This is not necessary, but may be of interest to some.)

2.9.6. Installing MySQL from Source on Windows

These instructions describe how to build binaries from source for MySQL 5.0 on Windows. Instructions are provided for building binaries from a standard source distribution or from the BitKeeper tree that contains the latest development source.

Note: The instructions here are strictly for users who want to test MySQL on Windows from the latest source distribution or from the BitKeeper tree. For production use, MySQL AB does not advise using a MySQL server built by yourself from source. Normally, it is best to use precompiled binary distributions of MySQL that are built specifically for optimal performance on Windows by MySQL AB. Instructions for installing a binary distributions are available in Section 2.3, “Installing MySQL on Windows”.

To build MySQL on Windows from source, you need the following compiler and resources available on your Windows system:

  • Visual Studio .Net 2003 (7.1) compiler system

  • Between 3GB and 5GB disk space.

  • Windows XP, Windows 2000 or higher.

The exact system requirements can be found here: http://msdn.microsoft.com/vstudio/Previous/2003/sysreqs/default.aspx

You also need a MySQL source distribution for Windows. There are two ways to obtain a source distribution:

  1. Obtain a Windows source distribution packaged by MySQL AB for the particular version of MySQL in which you are interested. These are available from http://dev.mysql.com/downloads/.

  2. You can package a source distribution yourself from the latest BitKeeper developer source tree. If you plan to do this, you must create the package on a Unix system and then transfer it to your Windows system. (Some of the configuration and build steps require tools that work only on Unix.) The BitKeeper approach thus requires:

If you are using a Windows source distribution, you can go directly to Section 2.9.6.1, “Building MySQL Using VC++”. To build from the BitKeeper tree, proceed to Section 2.9.6.2, “Creating a Windows Source Package from the Latest Development Source”.

If you find something not working as expected, or you have suggestions about ways to improve the current build process on Windows, please send a message to the mailing list. See Section 1.7.1, “MySQL Mailing Lists”.

2.9.6.1. Building MySQL Using VC++

Note: VC++ workspace files for MySQL 4.1 and above are compatible with Microsoft Visual Studio 7.1 and tested by MySQL AB staff before each release.

Follow this procedure to build MySQL:

  1. Create a work directory (for example, ).

  2. Unpack the source distribution in the aforementioned directory using WinZip or another Windows tool that can read files.

  3. Start Visual Studio .Net 2003 (7.1).

  4. From the File menu, select Open Solution....

  5. Open the solution you find in the work directory.

  6. From the Build menu, select Configuration Manager....

  7. In the Active Solution Configuration pop-up menu, select the configuration to use. You likely want to use one of nt (normal server, not for Windows 98/ME), Max nt (more engines and features, not for 98/ME) or Debug configuration.

  8. From the Build menu, select Build Solution.

  9. Debug versions of the programs and libraries are placed in the and directories. Release versions of the programs and libraries are placed in the and directories.

  10. Test the server. The server built using the preceding instructions expects that the MySQL base directory and data directory are and by default. If you want to test your server using the source tree root directory and its data directory as the base directory and data directory, you need to tell the server their pathnames. You can either do this on the command line with the and options, or by placing appropriate options in an option file. (See Section 4.3.2, “Using Option Files”.) If you have an existing data directory elsewhere that you want to use, you can specify its pathname instead.

  11. Start your server from the or directory, depending on which server you built or want to use. The general server startup instructions are in Section 2.3, “Installing MySQL on Windows”. You must adapt the instructions appropriately if you want to use a different base directory or data directory.

  12. When the server is running in standalone fashion or as a service based on your configuration, try to connect to it from the mysql interactive command-line utility that exists in your or directory.

When you are satisfied that the programs you have built are working correctly, stop the server. Then install MySQL as follows:

  1. Create the directories where you want to install MySQL. For example, to install into , use these commands:

    C:\> 
    C:\> 
    C:\> 
    C:\> 
    C:\> 
    

    If you want to compile other clients and link them to MySQL, you should also create several additional directories:

    C:\> 
    C:\> 
    C:\> 
    C:\> 
    

    If you want to benchmark MySQL, create this directory:

    C:\> 
    

    Benchmarking requires Perl support. See Section 2.14, “Perl Installation Notes”.

  2. From the directory, copy into the directory the following directories:

    C:\> 
    C:\workdir> 
    C:\workdir> 
    C:\workdir> 
    C:\workdir> 
    

    If you want to compile other clients and link them to MySQL, you should also copy several libraries and header files:

    C:\workdir> 
    C:\workdir> 
    C:\workdir> 
    C:\workdir> 
    C:\workdir> 
    C:\workdir> 
    C:\workdir> 
    C:\workdir> 
    

    If you want to benchmark MySQL, you should also do this:

    C:\workdir> 
    

Set up and start the server in the same way as for the binary Windows distribution. See Section 2.3, “Installing MySQL on Windows”.

2.9.6.2. Creating a Windows Source Package from the Latest Development Source

To create a Windows source package from the current BitKeeper source tree, use the instructions here. This procedure must be performed on a system running a Unix or Unix-like operating system because some of the configuration and build steps require tools that work only on Unix. For example, the following procedure is known to work well on Linux.

  1. Copy the BitKeeper source tree for MySQL 5.0. For instructions on how to do this, see Section 2.9.3, “Installing from the Development Source Tree”.

  2. Configure and build the distribution so that you have a server binary to work with. One way to do this is to run the following command in the top-level directory of your source tree:

    shell> 
    
  3. After making sure that the build process completed successfully, run the following utility script from top-level directory of your source tree:

    shell> 
    

    This script creates a Windows source package to be used on your Windows system. You can supply different options to the script based on your needs. It accepts the following options:

    • Display a help message.

    • Print information about script operations, do not create package.

    • Specify the temporary location.

    • The suffix name for the package.

    • Directory name to copy files (intermediate).

    • Do not print verbose list of files processed.

    • Create package instead of package.

    By default, make_win_src_distribution creates a Zip-format archive with the name -win-src.zip, where represents the version of your MySQL source tree.

  4. Copy or upload the Windows source package that you have just created to your Windows machine. To compile it, use the instructions in Section 2.9.6.1, “Building MySQL Using VC++”.

2.9.7. Compiling MySQL Clients on Windows

In your source files, you should include before :

#include <my_global.h>
#include <mysql.h>

includes any other files needed for Windows compatibility (such as ) if you compile your program on Windows.

You can either link your code with the dynamic library, which is just a wrapper to load in on demand, or link with the static library.

The MySQL client libraries are compiled as threaded libraries, so you should also compile your code to be multi-threaded.