2.4.15.6 Installing MySQL from Source on Windows
................................................

* Menu:

* windows-source-build-cmake::   Building MySQL from the Standard Source Distribution
* windows-vc-plus-plus-build::   Building MySQL from a Windows Source Distribution
* windows-source-install::       Installing MySQL from a Source Build on Windows
* windows-source-testbuild::     Testing a Windows Source Build
* windows-bitkeeper-build::      Creating a Windows Source Package from the BitKeeper Repository

This section does not apply to MySQL Enterprise Server users.

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
Microsoft 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 binary distributions are available in *note
windows-installation::.

To build MySQL on Windows from source, you must satisfy the following
system, compiler, and resource requirements:

   * Windows 2000, Windows XP, or newer version. Windows Vista is not
     supported until Microsoft certifies Visual Studio 2005 on Vista.

   * To build from the standard source distribution, you will need
     CMake, which can be downloaded from `http://www.cmake.org'. After
     installing, modify your path to include the `cmake' binary.

   * Microsoft Visual C++ 2005 Express Edition, Visual Studio .Net 2003
     (7.1), or Visual Studio 2005 (8.0) compiler system.

   * If you are using Visual C++ 2005 Express Edition, you must also
     install an appropriate Platform SDK. More information and links to
     downloads for various Windows platforms is available from
     `http://www.microsoft.com/downloads/details.aspx?familyid=0baf2b35-c656-4969-ace8-e4c0c0716adb/'.

   * If you are compiling from a BitKeeper tree or making changes to
     the parser, you need `bison' for Windows, which can be downloaded
     from `http://gnuwin32.sourceforge.net/packages/bison.htm'.
     Download the package labeled `Complete package, excluding
     sources'. After installing the package, modify your path to
     include the `bison' binary and ensure that this binary is
     accessible from Visual Studio.

   * Cygwin might be necessary if you want to run the test script or
     package the compiled binaries and support files into a Zip
     archive. (Cygwin is needed only to test or package the
     distribution, not to build it.) Cygwin is available from
     `http://cygwin.com'.

   * 3GB to 5GB of disk space.

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

There are three solutions available for building from the source code
on Windows:

   * Build from the standard MySQL source distribution. For this you
     will need CMake and Visual C++ Express Edition or Visual Studio.
     Using this method you can select the storage engines that are
     included in your build. To use this method, see *note
     windows-source-build-cmake::.

   * Build from the MySQL Windows source distribution. The Windows
     source distribution includes ready-made Visual Studio solution
     files that enable support for all storage engines (except `NDB').
     To build using using method you only need Visual C++ Express
     Edition or Visual Studio. To use this method, see *note
     windows-vc-plus-plus-build::.

   * Build directly from the BitKeeper source repository. For this you
     will need CMake, Visual C++ Express Edition or Visual Studio, and
     `bison'. For this method you need to create the distribution on a
     Unix system and then copy the generated files to your Windows build
     environment. To use this method, see *note
     windows-bitkeeper-build::.

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 `win32' mailing list. See *note mailing-lists::.

File: manual.info,  Node: windows-source-build-cmake,  Next: windows-vc-plus-plus-build,  Prev: windows-source-build,  Up: windows-source-build

2.4.15.7 Building MySQL from the Standard Source Distribution
.............................................................

This section does not apply to MySQL Enterprise Server users.

You can build MySQL on Windows by using a combination of `cmake' and
Microsoft Visual Studio .NET 2003 (7.1), Micrsofot Visual Studio 2005
(8.0) or Microsoft Visual C++ 2005 Express Edition. You must have the
appropriate Microsoft Platform SDK installed.

*Note*:

To compile from the source code usin CMake you must use the standard
source distribution (for example, `mysql-5.0.45.tar.gz').  You build
from the same distribution as used to build MySQL on Unix, Linux and
other platforms. Do _not_ use the Windows Source distributions as they
do not contain the necessary configuration script and other files.

Follow this procedure to build MySQL:

  1. If you are installing from a packaged source distribution, create
     a work directory (for example, `C:\workdir'), and unpack the source
     distribution there using `WinZip' or another Windows tool that can
     read `.zip' files. This directory is the work directory in the
     following instructions.

  2. If you are installing from a BitKeeper tree, the root directory of
     that tree is the work directory in the following instructions.

  3. Using a command shell, navigate to the work directory and run the
     following command:

          C:\workdir>win\configure OPTIONS

     These options are available:

        * `WITH_INNOBASE_STORAGE_ENGINE': Enable the `InnoDB' storage
          engine.

        * `WITH_PARTITION_STORAGE_ENGINE': Enable user-defined
          partitioning.

        * `WITH_ARCHIVE_STORAGE_ENGINE': Enable the `ARCHIVE' storage
          engine.

        * `WITH_BLACKHOLE_STORAGE_ENGINE': Enable the `BLACKHOLE'
          storage engine.

        * `WITH_EXAMPLE_STORAGE_ENGINE': Enable the `EXAMPLE' storage
          engine.

        * `WITH_FEDERATED_STORAGE_ENGINE': Enable the `FEDERATED'
          storage engine.

        * `__NT__': Enable support for named pipes.

        * `MYSQL_SERVER_SUFFIX=SUFFIX': Server suffix, default none.

        * `COMPILATION_COMMENT=COMMENT': Server comment, default
          "Source distribution".

        * `MYSQL_TCP_PORT=PORT': Server port, default 3306.

        * `DISABLE_GRANT_OPTIONS': Disables the the `--bootstrap',
          `--skip-grant-tables', and `--init-file' options for
          `mysqld'. This option is available as of MySQL 5.0.36.

     For example (type the command on one line):

          C:\workdir>win\configure WITH_INNOBASE_STORAGE_ENGINE »
                       WITH_PARTITION_STORAGE_ENGINE MYSQL_SERVER_SUFFIX=-pro

  4. From the work directory, execute the `win\build-vs8.bat' or
     `win\build-vs71.bat' file, depending on the version of Visual
     Studio you have installed. The script invokes CMake, which
     generates the `mysql.sln' solution file you will need to build
     MySQL using Visual Studio..

     You can also use `win\build-vs8_x64.bat' to build the 64-bit
     version of MySQL. However, you cannot build the 64-bit version
     with Visual Studio Express Edition. You must use Visual Studio
     2005 (8.0) or higher.

  5. From the work directory, open the generated `mysql.sln' file with
     Visual Studio and select the proper configuration using the
     `Configuration' menu. The menu provides `Debug', `Release',
     `RelwithDebInfo', `MinRelInfo' options. Then select `Solution' >
     `Build' to build the solution.

     The build process will take some time. Please be patient.

     Remember the configuration that you use in this step. It is
     important later when you run the test script because that script
     needs to know which configuration you used.

  6. You should test you build before installation. See *note
     windows-source-testbuild::.

  7. To install, use the instructions in *note windows-source-install::.

File: manual.info,  Node: windows-vc-plus-plus-build,  Next: windows-source-install,  Prev: windows-source-build-cmake,  Up: windows-source-build

2.4.15.8 Building MySQL from a Windows Source Distribution
..........................................................

This section does not apply to MySQL Enterprise Server users.

The Windows source distribution includes the necessary solution file
and the `vcproj' files required to build each component. Using this
method you are not able to select the storage engines that are included
in your build.

*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, `C:\workdir').

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

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

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

  5. Open the `mysql.sln' 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), `Max nt' (more engines and features), or `Debug'
     configuration.

  8. From the `Build' menu, select `Build Solution'.

  9. Debug versions of the programs and libraries are placed in the
     `client_debug' and `lib_debug' directories. Release versions of
     the programs and libraries are placed in the `client_release' and
     `lib_release' directories.

 10. You should test you build before installation. See *note
     windows-source-testbuild::.

 11. To install, use the instructions in *note windows-source-install::.

File: manual.info,  Node: windows-source-install,  Next: windows-source-testbuild,  Prev: windows-vc-plus-plus-build,  Up: windows-source-build

2.4.15.9 Installing MySQL from a Source Build on Windows
........................................................

When you are satisfied that the program you have built is working
correctly, stop the server. Now you can install the distribution. There
are two ways to do this, either by using the supplied installation
script or by copying the files individually by hand.

To use the script method you must have Cygwin installed as the script
is a Shell script. To execute the installation process, run the
`make_win_bin_dist' script in the `scripts' directory of the MySQL
source distribution (see *note make-win-bin-dist::). This is a shell
script, so you must have Cygwin installed if you want to use it. It
creates a Zip archive of the built executables and support files that
you can unpack to your desired installation location.

It is also possible to install MySQL by copying directories and files
manually:

  1. Create the directories where you want to install MySQL.  For
     example, to install into `C:\mysql', use these commands:

          C:\> mkdir C:\mysql
          C:\> mkdir C:\mysql\bin
          C:\> mkdir C:\mysql\data
          C:\> mkdir C:\mysql\share
          C:\> mkdir C:\mysql\scripts

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

          C:\> mkdir C:\mysql\include
          C:\> mkdir C:\mysql\lib
          C:\> mkdir C:\mysql\lib\debug
          C:\> mkdir C:\mysql\lib\opt

     If you want to benchmark MySQL, create this directory:

          C:\> mkdir C:\mysql\sql-bench

     Benchmarking requires Perl support. See *note perl-support::.

  2. From the work directory, copy into the `C:\mysql' directory the
     following directories:

          C:\> cd \workdir
          C:\workdir> copy client_release\*.exe C:\mysql\bin
          C:\workdir> copy client_debug\mysqld.exe C:\mysql\bin\mysqld-debug.exe
          C:\workdir> xcopy scripts\*.* C:\mysql\scripts /E
          C:\workdir> xcopy share\*.* C:\mysql\share /E

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

          C:\workdir> copy lib_debug\mysqlclient.lib C:\mysql\lib\debug
          C:\workdir> copy lib_debug\libmysql.* C:\mysql\lib\debug
          C:\workdir> copy lib_debug\zlib.* C:\mysql\lib\debug
          C:\workdir> copy lib_release\mysqlclient.lib C:\mysql\lib\opt
          C:\workdir> copy lib_release\libmysql.* C:\mysql\lib\opt
          C:\workdir> copy lib_release\zlib.* C:\mysql\lib\opt
          C:\workdir> copy include\*.h C:\mysql\include
          C:\workdir> copy libmysql\libmysql.def C:\mysql\include

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

          C:\workdir> xcopy sql-bench\*.* C:\mysql\bench /E

After installation, set up and start the server in the same way as for
binary Windows distributions. See *note windows-installation::.

File: manual.info,  Node: windows-source-testbuild,  Next: windows-bitkeeper-build,  Prev: windows-source-install,  Up: windows-source-build

2.4.15.10 Testing a Windows Source Build
........................................

You should test the server that you have built from source before using
the distribution.

To test the server you need to run the built `mysqld'. By default,
using the source build examples, the MySQL base directory and data
directory are `C:\mysql' and `C:\mysql\data'. 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
`--basedir' and `--datadir' options, or by placing appropriate options
in an option file. (See *note option-files::.) If you have an existing
data directory elsewhere that you want to use, you can specify its
pathname instead.

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.

You can also run the standard test script, `mysql-test-run.pl'. This
script is written in Perl, so you'll need either Cygwin or ActiveState
Perl to run it. You may also need to install the modules required by
the script. To run the test script, change location into the
`mysql-test' directory under the work directory, set the `MTR_VS_CONFIG'
environment variable to the configuration you selected earlier (or use
the `--vs-config' option), and invoke `mysql-test-run.pl'. For example
(using Cygwin and the `bash' shell):

     shell> `cd mysql-test'
     shell> `export MTS_VS_CONFIG=debug'
     shell> `./mysqltest-run.pl --force --timer'
     shell> `./mysqltest-run.pl --force --timer --ps-protocol'

File: manual.info,  Node: windows-bitkeeper-build,  Prev: windows-source-testbuild,  Up: windows-source-build

2.4.15.11 Creating a Windows Source Package from the BitKeeper Repository
.........................................................................

This section does not apply to MySQL Enterprise Server users.

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 *note installing-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> ./BUILD/compile-pentium-max

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

          shell> ./scripts/make_win_src_distribution

     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. See *note make-win-src-distribution::, for a
     list of allowable options.

     By default, `make_win_src_distribution' creates a Zip-format
     archive with the name `mysql-VERSION-win-src.zip', where VERSION
     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 *note windows-vc-plus-plus-build::.

File: manual.info,  Node: windows-client-compiling,  Prev: windows-source-build,  Up: installing-source

2.4.15.12 Compiling MySQL Clients on Windows
............................................

This section does not apply to MySQL Enterprise Server users.

In your source files, you should include `my_global.h' before `mysql.h':

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

`my_global.h' includes any other files needed for Windows compatibility
(such as `windows.h') if you compile your program on Windows.

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

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

