Setup Debug Environment for MySQL 5.5 in VS2008

When learning database engine, it’s always helpful to look at MySQL to see how it works. Here are the steps to setup the debug environment for Visual Studio.

My Environment: Win7 64bit, VS2008, mysql–5.5.23, CMake 2.8, bison–2.4.1

  • Download packages
    1. Download MySQL source at http://www.mysql.com/downloads/mysql
    2. Download CMake 2.8 at http://www.cmake.org/files/v2.8/cmake-2.8.6-win32-x86.exe
    3. Download Bison 2.4.1 at http://en.sourceforge.jp/projects/sfnet_gnuwin32/downloads/bison/2.4.1/bison-2.4.1-setup.exe
  • Install packages
    1. When unzip MySQL, installing CMake, bison. Make sure to NOT put them under a directory including Space (e.g. Don’t put it under “Program Files”). Otherwise, you will encounter error like:
      • “CMake Error at C:/Program Files/cmake–2.8/Modules/CheckTypeSize.cmake:82 (try_compile): Cannot copy output executable”.

      My practice is to create a DevTools folder and install CMake, bison under it.

    2. After installing CMake, bison, make sure to add their bin executable to the PATH environment variable. CMake will automatically add it if you specify the option when installing. You still need to add C:\DevTools\GunWin32\bin for Bison.
  • Build
    1. Go to the unzipped MySQL source directory
    2. type command below. This will automatically generate the MySQL.sln:
      • cmake . -G “Visual Studio 9 2008”
    3. Open MySQL.sln. Setup mysqld as startup project. Then hit build.
  • Run
    1. Run mysqld, this is the mysql server daemon. Now in command line, go to client\Debug\ .
    2. In the shell, type:
      • mysql -h localhost -u root -p
    3. There is no password by default, so press Enter:
      • Enter password:
    4. Create menagerie database and pet table as advised by MySQL Manual.
  • Debug
    1. The menagerie table using Innodb storage engine. A good place to setup the breakpoint is at ha_innobase::write_row.
    2. In mysql prompt, type:  INSERT INTO pet VALUES (‘Puffball’, ‘Diane’, ‘hamster’, ‘f’, ‘1999–03–30’, NULL);

Now you should get the call stack from Visual Studio and see the MySQL workflow from accepting query all way down to ask the storage engine to write the data.

Subscribe to 天舟的云游格

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe