How to Build MySQL from Source Code on Windows & compile MySQL on win7+vs2010


Not counting obtaining the source code, and once you have the prerequisites satisfied, [Windows] users can build from source code in 5 easy steps.

Prerequisites – Install & ensure they are in the $PATH:

  1. CMake <-- Download
  2. C++ compiler <-- Visual Studio 2008 Express - Free Download
  3. Bison <-- Download (ensure m4.exe is also included, which it should be)

Optional (but most likely you’ll want):

  1. Perl <-- For Test Suite/Scripts. Strawberry Perl is a great option.
  2. Bazaar <-- If want latest source tree

Tip: Install these in locations where spaces are not in the path. Specifically, watch for the Bison/m4 as there is a known bug with regards to that.

..

Now that that’s out of the way, we can begin. You just need to decide if you want to build from source code you download or from the latest development tree.

This will walk through building from the latest development tree (since the downloaded version requires no extra steps – just grab it from any mirror).

Also, this post assumes you can connect to the Launchpad repository via Bazaar and download the source (i.e., you’ll have to create SSH keys to connect to Launchpad – see this write-up for more details. You might also need Pageant too, if you don’t already have it.)

I. Prerequisite Checks:

C:\>cmake --version
cmake version 2.6-patch 4

C:\>bison --version
bison (GNU Bison) 2.4.1

C:\>m4 --version
m4 (GNU M4) 1.4.13

C:\>perl --version
This is perl 5, version 12, subversion 3

C:\>bzr --version
Bazaar (bzr) 2.4.1

..

II. Obtain Source Code (skip this if you download the source directly from a mirror):

  1. Open Pageant -> Add Key -> Select your SSH Key (for Launchpad)
  2. cd C:\
  3. bzr init-repo –trees mysql-5.5
  4. cd mysql-5.5
  5. bzr branch lp:mysql-server/5.5 mysql-5.5

..

III. Build/Compile Source Code:

  1. cd mysql-5.5
  2. cmake . -DBUILD_CONFIG=mysql_release -G “Visual Studio 9 2008″
  3. Copy m4.exe to $basedir/sql <-- this avoids any m4.exe errors (or fix this permanently if this affects you)
  4. Open Solution in VS: File -> Open -> Project/Solution -> C:\mysql-5.5\mysql-5.5\MySQL.sln
  5. Now build in VS: Build -> Build Solution (or F7)
========== Build: 93 succeeded, 0 failed, 5 up-to-date, 10 skipped ==========

There you have it! (Assuming you have “0 failed”, otherwise, you’ve got some debugging to do.)

..

For those interested, I have full outputs, and common errors (with their solutions) from the entire process here:

MySQL 5.5 Windows Build Appendix : Full Outputs and Common Errors from Building MySQL 5.5 on Windows

..

Build Notes (step #2 above):

The -DBUILD_CONFIG=mysql_release flag uses the same build options used for official releases, which are stored in cmake/build_configurations/mysql_release.cmake.

The simplest you could use is: cmake . -G “Visual Studio 9 2008″

Or you could specify a number of options: cmake . -DMYSQL_SERVER_SUFFIX=-chris -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 -DWITHOUT_BLACKHOLE_STORAGE_ENGINE=1 -G “Visual Studio 9 2008″

The -G lets know which compiler will be used. In this case, I’m using VS 2008 Express. If you were using VS 2005, it’d be “Visual Studio 8 2005″, but I’m not sure if VS 2005 will even work.

This command should end with something like “– Build files have been written to: C:/…” or you’ll need to debug.

Lastly, the cmake command creates the MySQL.sln file and all .vcproj files.

..

IV. Kicking the tires …

Creating a “package” in Visual Studio is quite simple:

In the “Solution Explorer” view (far right-hand side of page), right-click on “PACKAGE” -> then “Build”.

If you have problems with this, it can be pieced together easily enough:

  1. Make main dir mysql-5.5.xx
  2. Make subdir bin/ – copy in all .exe files (from client/debug, sql/debug, */debug, etc.)*
  3. Make subdir data/ – copy from sql/data/
  4. Make subdir scripts/ – copy from scripts/ (at least all perl, sql, and sh scripts)
  5. Make subdir share/ – copy from sql/share/
  6. Create my.ini

* Notes re: .exe files: mysqld.exe is located in /sql/debug/ and mysql.exe is located in /client/debug/. The remaining .exe files are located in /client/debug/, /sql/debug/, /extra/debug/, /libmysql/debug/, /mysys/debug/, /scripts/debug/, /storage/myisam/debug/, /storage/heap/debug/, and /tests/debug/.

Now start mysqld:

mysql> select version();
+------------------+
| version()        |
+------------------+
| 5.5.21-debug-log |
+------------------+

Of course you should test it a bit more than that, but I’ll leave that to you.
 
 
..

Related Build Links:

  • Building MySQL and MariaDB on Windows using Visual Studio 2012 Express versus Visual Studio 2010 Express:
    http://www.chriscalender.com/?p=1245

  • How to Build MySQL 5.7 on Windows from Source Code:
    http://www.chriscalender.com/?p=1273

  • How to Build MySQL 5.6 on Windows from Source Code:
    http://www.chriscalender.com/?p=1233

  • How to Build MySQL 5.5 on Windows from Source Code:
    http://www.chriscalender.com/?p=689

  • How to Build MariaDB 10.0 on Windows from Source Code:
    http://www.chriscalender.com/?p=1224

  • How to Build MariaDB 5.5 on Windows from Source Code:
    http://www.chriscalender.com/?p=1087

  • Building MariaDB 5.3 on Windows:
    http://www.chriscalender.com/?p=864

  • Building MariaDB 5.1 on Windows:
    http://www.chriscalender.com/?p=736

  • Building MariaDB 5.1 on Windows Revisited:
    http://www.chriscalender.com/?p=1256

  • Troubleshooting Building MariaDB 5.1 on Windows:
    http://www.chriscalender.com/?p=1259

  • MySQL 5.5 Windows Build Appendix : Full Outputs and Common Errors from Building MySQL 5.5 on Windows:
    http://www.chriscalender.com/?p=720

  • Maintaining (and Building) your MySQL Source Tree on Windows:
    http://www.chriscalender.com/?p=759

  • Resolving the bison.exe m4 Invalid argument Error when building MySQL/MariaDB/XtraDB on Windows:
    http://www.chriscalender.com/?p=798

  • Resolving sasl/sasl.h Not Found during CMake when Building MySQL on Windows:
    http://www.chriscalender.com/?p=1302

  • Resolving Missing ‘sys’ Include Files: devpoll.h, epoll.h, event.h, and queue.h during CMake when Building MySQL on Windows:
    http://www.chriscalender.com/?p=1317

  • Building XtraDB on Windows:
    http://www.chriscalender.com/?p=820


    win7+vs2010源码编译mysql

    最近由于在实习,工作重点在于一些数据库的开发,为了更好的理解数据库的实现机制,目前萌生了要研究一下mysql数据库源码的想法。那么好吧,说干就干,首先我们需要实现对源码的编译,这里我们选择win7+VS2010来实现,但是试了很多次都失败了。这是我多次配置环境时遇到的问题,各种博客文章总是不太完全,或者说没有说明一些遇到的问题的解决方案,这可能跟具体的操作系统和环境有关。本文就说说我安装的情况。

    1. 准备工作

    (1)OS:win7 旗舰版 64位 + VS2010 (2013也试过了)

    (2)mysql 源码(windows版):mysql-5.6.19.zip (下来框选择source code)

    (3)perl tool:ActivePerl-5.16.3.1604-MSWin32-x64-298023.msi

    (4)Cmake:cmake-3.0.0-win32-x86 .exe

    (5)Bison:bison-2.4.1-setup.exe

    安装需要注意的几点,一般安装在根目录下,如C:\Cmake C:\GnuWin32 C:\Perl64 ,当然也可以是其他目录,一般路径不要出现中文字符,空格及特殊字(这个貌似很重要)。具体安装见下面博客:Windows+VS2012环境下编译调试MySQL源码

    除了Bison安装需要注意意外,其他几乎都是默认安装,这些细节最好遵守,以免后续出错。Perl, Cmake, Bison安装完事之后,将他们安装目录下的bin所在路径加入环境变量中(windows环境变量添加),如C:\Cmake\bin.好了至此基本ok。保险起见我们需要验证一下安装是否成功:

     

    加载中... 加载中... 

    2. 开始安装

    在任意你喜欢的盘里面创建一个用于安装的目录:如在D盘创建mysql然后将mysql-5.6.19.zip解压到该目录下,然后在cmd中切换到安装目录,此处即为D:\mysql\mysql-5.6.19,记({install}=D:\mysql\mysql-5.6.19),其下包含如下文件目录:

    然后在{install}下执行以下命令:

    >mkdir bld

    >cd bld

    >cmake ..

    这样你可看到类似如下的输出:

    有一些错误,目前也没有解决,但其实这并不影响我们生成VS下MySQL.sln 工程文件。事实上只要看到下面这个就可以了,各种not found也不要紧。如果采用Cmake 图形界面,其实也差不多了。这里不再赘述。

    下一步我们就可以在VS2010中build solution了(对应生成解决方案),但为了尽可能减少警告或错误,我们首先需要对下述文件进行修改:

    修改的方法很简单,就是将这些文件以UTF-8(带BOM头的)格式保存。一般使用Nodepad++工具等。

    最后一步就是找到{install}\mysql-5.6.19\sql\mysqld.cc中的test_lc_time_sz()函数,将其中的DBUG_ASSERT(0)改为DBUG_ASSERT(1)即可。

    至此我们就完成了将源码转换成VS中工程文件的目的。之后我们就可以build solution了。如果没有错误说明就已经没有问题了,一些小的警告可能是因为C++编译器比C编译器严格的缘故。下一步我们开始调试。

    3. 调试

    然后将mysqld工程的Debug的:属性->调试->命令参数,设为--console,如下:


    然后启动实例,

    这样就可以看到下面的命令行界面:

    cmd下进入到目录{install}\client,然后执行如下命令,就可以开始连接到刚刚开启的mysql服务了。这说明mysql服务已经启动,下一步就是启动mysql客服端,这里我是采用命令行的启动方式。


    好了至此,我们基本完成了在win7下实现在vs下编译调试mysql数据库的目的,下面就可以开始研究源码了。

    4 .新增问题

    (1)vs2010:

    1
    2
    LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 [F:\mysql\bld\CMakeFiles\CMakeTmp\cmTryCompileExec2556624813.vcxproj]
    解决办法:这是由于.NET中的cvtres.exe 与 VS2010中的有冲突,删掉VS2010中的cvtres.exe就可以了(目录F:\Install\VS2010\VC\bin),注意install是你安装VS2010的目录。

    为了更好地为后来者指明方向,也为了今后便于自己查询,故做了这个简单的指南。也希望按照这篇文档安装的朋友遇到任何问题可以一起探讨,然后不断完善该文档,以便后来者能够因此而受用,同时营造一个负责人写稿的氛围。


    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: 命令“setlocal
    4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: cd D:\mysql-5.6.19\sql
    4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
    4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: D:
    4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
    4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: D:\mysql-5.6.19\client\Debug\echo.exe x64 && cscript //nologo D:/mysql-5.6.19/win/create_def_file.js x64 D:\mysql-5.6.19\sql\Debug\sql.lib D:\mysql-5.6.19\mysys\Debug\mysys.lib D:\mysql-5.6.19\mysys_ssl\Debug\mysys_ssl.lib D:\mysql-5.6.19\dbug\Debug\dbug.lib D:\mysql-5.6.19\strings\Debug\strings.lib > mysqld.def
    4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
    4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: :cmEnd
    4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
    4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: :cmErrorLevel
    4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: exit /b %1
    4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: :cmDone
    4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd
    4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(108,5): error MSB3073: :VCEnd”已退出,代码为 1。
    _______________________________________________
    问题找到了,发现输出日志里有一行 “输入错误: 没有文件扩展“.js”的脚本引擎。” 
    按照网上的方法:系统安装Dreamwear、UltraEdit、EditPlus后修改了.js文件的默认打开方式。当想直接执行js脚本时就会出现此错误。


    http://blog.csdn.net/clever101/article/details/8757740


    解决办法如下:

    打开注册表编辑器,定位"HKEY_CLASSES_ROOT" > ".js" 这一项,双击默认值将数值数据改为"JSFile"即可,具体如下图:


            后来分析这个主要是由于改变了JScript文件的默认打开方式(不再是由Windows Script Host打开)。


    来源: http://bbs.csdn.net/topics/390817362




posted @ 2018-08-21 19:51  Jerry_Jin  阅读(643)  评论(0编辑  收藏  举报