Building MySQL on Windows
Contents |
← Back to MySQL University main page
[edit] Building MySQL on Windows
- Date: 2007-09-21
- Presenter: Ignacio Galarza
- Scribe: MC Brown
- Attendees (please register by filling in your name below, and read the Instructions for Attendees):
- Davi Arnaut
- Dheryta
[edit] Presentation
[edit] Building MySQL on Windows
This presentation will demonstrate how I setup an environment for building MySQL on Windows. While not strictly necessary, installing and running the Windows build system in a virtual machine allows for a single source repository to be shared among multiple flavors of Windows and/or other operating systems. We will focus on using only free or open source tools in the build environment, specifically we'll be using: VMWare Server, Microsoft Visual Studio Express 2005, Microsoft Windows Platform SDK, KitWare CMake, GNUWin32 Bison and Red Hat CygWin.
- Configure the machine
- Build the Source
- Use the Source
[edit] Configure the machine
- Obtain MySQL Source
- Install build tools
[edit] Obtain MySQL Source
- Instructions
- Source is managed on the host system
[edit] Install build tools
- Microsoft Visual Studio Express 2005 - Download - Once it's installed you must register.
- Windows Server R2 Platform SDK Download - Manual Configuration -
- CMake Download Make sure to add CMake to the SYSTEM Path when prompted.
- GNUWin32 Bison - Download Make sure to add the installation directory to the path.
- CygWin - Download Make sure to add the Perl and Python modules.
[edit] Build the Source
- Open a CygWin window and navigate to the root of the source tree. The following examples assume you are in the source root and are using CygWin.
- Configure CMake
- Example
- Create Visual Studio Solution
- Example
- Build the Solution
[edit] Configure CMake
- win/configure.js is used to create the configuration file (win/configure.data) used by CMake.
- The configuration options are defined in win/README.
- The following .bashrc helper function is useful.
function win_con() {
cscript win/configure.js WITH_INNOBASE_STORAGE_ENGINE WITH_PARTITION_STORAGE_ENGINE WITH_ARCHIVE_STORAGE_ENGINE WITH_BLACKHOLE_STORAGE_ENGINE WITH_EXAMPLE_STORAGE_ENGINE WITH_FEDERATED_STORAGE_ENGINE __NT__
}
[edit] Example
$ win_con Microsoft (R) Windows Script Host Version 5.6 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. done!
[edit] Changing build option
- [Common CMake Tasks| http://forge.mysql.com/wiki/How_to_Build_MySQL_on_Windows/Presentation#Common_Tasks]
- The CMake cache normally stored in CMakeChache.txt is copied to win/vsNcache.txt (N = VS version). Sometimes it is necessary to remove this file then recreate the solution files.
[edit] Create the Visual Studio Solution
- CMake uses the files named CMakeLists.txt in each directory to create the solution/project files necessary to build the solution.
- Three batchfiles are provided to create Visual Studio solutions in the proper format.
- For VS2003 use win/build_vs71.bat
- For VS2005 use win/build_vs8.bat
- For VS2005 x64 use win/build_vs8_x64.bat
[edit] Example
$ win/build-vs8.bat
The system cannot find the file specified.
-- Check for working C compiler: cl
-- Check for working C compiler: cl -- works
-- Check size of void*
-- Check size of void* - done
-- Check for working CXX compiler: cl
-- Check for working CXX compiler: cl -- works
-- Configuring done
-- Generating done
-- Build files have been written to: r:/mysql-5.1-maint_win
1 file(s) copied.
[edit] Build the Solution
At this point, CMake has created the solution and all the project files necessary to build MySQL.
- Click Start -> Programs -> Visual Studio C++ Express Edition -> Microsoft Visual C++ 2005 Express Edition so start the IDE.
- Open the solution created by CMake. Click File -> Open -> Project/Soution (CTRL+SHIFT+O) and then browsing for the file MySQL.sln in the source root.
- Choose the configuration from the center drop down
- Click Build -> Build Solutin (F7) to start the build.
[edit] Use the Results
- Now let's do something with our resutls.
- Running the Testsuite
- Debugging
- Example
[edit] Running the Testsuite
The Microsoft IDE allows you to build different configurations of the source in the same build tree. This can be especially useful for mix-match release/debug client/server testing. mysql-test-run(mtr) will try to guess which configuration you want to test but it's best to be specific. mtr provides the --vs-config dir option to allow you to which configuration it should test. You can either specify the configuration name as a parameter to mtr on the command line(ie --vs-config=release) or by setting the MTR_VS_CONFIG environment variable (ie EXPORT MTR_VS_CONFIG=release).
[edit] Example
export MTR_BUILD_THREAD=51 export MTR_VS_CONFIG=release cd mysql-test ./mysql-test-run.pl --force --timer
[edit] Debugging
Debugging MySQL in the Visual Studio IDE can be a bit awkward but it's well worth the effort. If you haven't already now's the time to build the solution's Debug configuration. The following example is presented to illustrate a technique for basic debugging.
[edit] Example
- Start the mtr script
export MTR_VS_CONFIG=debug cd mysql-test $./mysql-test-run.pl --manual-debug alter_table Logging: ./mysql-test-run.pl --manual-debug alter_table 070801 16:12:20 [Note] z:\mysql-5.1-maint_win\sql\debug\mysqld.exe: Shutdown complete MySQL Version 5.1.21 Using binlog format 'mixed' Disable Instance manager - testing not supported on Windows Skipping ndbcluster, mysqld not compiled with ndbcluster Setting mysqld to support SSL connections Using MTR_BUILD_THREAD = 51 Using MASTER_MYPORT = 10510 Using MASTER_MYPORT1 = 10511 Using SLAVE_MYPORT = 10512 Using SLAVE_MYPORT1 = 10513 Using SLAVE_MYPORT2 = 10514 Killing Possible Leftover Processes Removing Stale Files Creating Directories Installing Master Database Installing Master Database ======================================================= TEST RESULT TIME (ms) ------------------------------------------------------- Start master in your debugger dir: z:/mysql-5.1-maint_win/mysql-test exe: z:/mysql-5.1-maint_win/sql/debug/mysqld.exe args: --no-defaults --basedir=z:/mysql-5.1-maint_win/mysql-test --character-sets-dir=z:/mysql-5.1-maint_win/sql/share/charsets --secure-file-priv=z:/mysql-5.1-maint_win/mysql-test/var --log-bin-trust-function-creators --default-character-set=latin1 --language=z:/mysql-5.1-maint_win/sql/share/english --tmpdir=z:/mysql-5.1-maint_win/mysql-test/var/tmp --pid-file=z:/mysql-5.1-maint_win/mysql-test/var/run/master.pid --port=10510 --socket=z:/mysql-5.1-maint_win/mysql-test/var/tmp/master.sock --datadir=z:/mysql-5.1-maint_win/mysql-test/var/master-data --log-output=table,file --log=z:/mysql-5.1-maint_win/mysql-test/var/log/master.log --log-slow-queries=z:/mysql-5.1-maint_win/mysql-test/var/log/master-slow.log --server-id=1 --loose-innodb_data_file_path=ibdata1:10M:autoextend --local-infile --loose-skip-innodb --loose-skip-ndbcluster --key_buffer_size=1M --sort_buffer=256K --max_heap_table_size=1M --ssl-ca=z:/mysql-5.1-maint_win/mysql-test/std_data/cacert.pem --ssl-cert=z:/mysql-5.1-maint_win/mysql-test/std_data/server-cert.pem --ssl-key=z:/mysql-5.1-maint_win/mysql-test/std_data/server-key.pem --gdb --skip-log-bin --core-file --open-files-limit=1024 Waiting ....
- Switch to the IDE and make sure the Debug configuration is selected.
- Set mysqld as the StartUp Project. Click mysqld in the Solution Explorer then click Project -> Set as StartUp Project.
- Open the mysqld Debugging Properties. Click Project -> Properties -> Debugging
- Set the Command Arguments and Working Directory output by mtr then click Apply -> OK
- Start the server in the debugger. Click Debug -> Start Debugging (F7)
- Set breakpoints. Optional.
- Switch to the CygWin window to see the results
Waiting .... main.alter_table [ pass ] 7960 ------------------------------------------------------- All 1 tests were successful. The servers were restarted 1 times Spent 7.96 seconds actually executing testcases
[edit] Questions
[edit] Questions asked before the session
- FIRST_QUESTION
- FIRST_ANSWER
- SECOND_QUESTION
- SECOND_ANSWER
- ...
- ...
[edit] Questions asked during the session
- FIRST_QUESTION
- FIRST_ANSWER
- SECOND_QUESTION
- SECOND_ANSWER
- ...
- ...
