2.9.6 Installing MySQL from Source on Windows
---------------------------------------------

* Menu:

* borland-c-plus-plus::          Borland C++

These instructions describe how to build binaries from source for MySQL
5.1 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 a binary distributions are available in
*Note windows-installation::.

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

   * CMake, which can be downloaded from http://www.cmake.org
     (http://www.cmake.org).  After installing, modify your path to
     include the cmake binary.

   * If compiling from 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
     (http://gnuwin32.sourceforge.net/packages/bison.htm).  Download
     the package labelled `Complete package, excluding sources'. After
     installing, modify your path to include the `bison' binary and
     ensure that this binary is accessible from Visual Studio.

   * 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://msdn.microsoft.com/platformsdk/
     (http://msdn.microsoft.com/platformsdk/).

   * Between 3GB and 5GB disk space.

   * Windows 2000, Windows XP, or newer version.

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'

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

  1. Obtain a source distribution packaged by MySQL AB. These are
     available from `http://dev.mysql.com/downloads/'.

  2. You can package a source distribution yourself from the latest
     BitKeeper developer source tree. For instructions on pulling the
     latest source files, see *Note installing-source-tree::.

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::.

Follow this procedure to build MySQL:

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

  2. Using a command shell, navigate to the work or BK root directory
     and run the following command:

          C:\workdir>win\configure OPTIONS

     The 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.

     For example:

          win\configure WITH_INNOBASE_STORAGE_ENGINE WITH_PARTITION_STORAGE_ENGINE MYSQL_SERVER_SUFFIX=-pro

  3. From the work or BK root directory, execute the
     `win\build-vs8.bat' or `win\build-vs71.bat' file, depending on the
     version of Visual Studio you have installed.

  4. From the work or BK root directory, execute the generated
     `mysql.sln' file. Visual Studio will load the solution and you can
     then click `Solution' > `Build' to build the solution.

  5. Test the server. The server built using the preceding instructions
     expects that the MySQL base directory and data directory are
     `C:\mysql' and `C:\mysql\data' 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 `--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.

  6. 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.

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 `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 `workdir' or BK root 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

Set up and start the server in the same way as for the binary Windows
distribution. See *Note windows-installation::.

File: manual.info,  Node: borland-c-plus-plus,  Prev: windows-source-build,  Up: windows-source-build

2.9.6.1 Borland C++
...................

You can compile the MySQL Windows source with Borland C++ 5.02. (The
Windows source includes only projects for Microsoft VC++, for Borland
C++ you have to do the project files yourself.)

One known problem with Borland C++ is that it uses a different
structure alignment than VC++. This means that you run into problems if
you try to use the default `libmysql.dll' libraries (that were compiled
using VC++) with Borland C++. To avoid this problem, only call
`mysql_init()' with `NULL' as an argument, not a pre-allocated `MYSQL'
structure.

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

2.9.7 Compiling MySQL Clients on Windows
----------------------------------------

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.

