git clone https://github.com/alibaba/AliSQL.git
编译前须要安装好gcc
cmake
bison
等。(若是缺乏其余依赖,debian系的可使用sudo apt-get build-dep mysql-server
快速安装)html
cd AliSQL # 建立并进入构建目录 make build_linux && cd build_linux # 生成 makefile cmake -DCMAKE_INSTALL_PREFIX=/home/x/alisql .. #指定安装路径/home/x/alisql # 编译 make -j4
make install # 安装
安装完成后能够进入安装目录下的bin
目录mysql
/home/x/alisql/bin [o@o-s] [11:42] > ./mysql_config Usage: ./mysql_config [OPTIONS] Options: --cflags [-I/home/x/alisql/include -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing] --cxxflags [-I/home/x/alisql/include -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing] --include [-I/home/x/alisql/include] --libs [-L/home/x/alisql/lib -lmysqlclient -lpthread -lm -ldl] --libs_r [-L/home/x/alisql/lib -lmysqlclient -lpthread -lm -ldl] --plugindir [/home/x/alisql/lib/plugin] --socket [/tmp/mysql.sock] --port [0] --version [5.6.32] --libmysqld-libs [-L/home/x/alisql/lib -lmysqld -lpthread -lm -lcrypt -ldl -laio] --variable=VAR VAR is one of: pkgincludedir [/home/x/alisql/include] pkglibdir [/home/x/alisql/lib] plugindir [/home/x/alisql/lib/plugin]
在alisql
建立一个my.cnf
文件,写入配置文件信息。
启动mysqllinux
./bin/mysqld
mysql配置文件说明(注意,配置文件应该是UTF-8编码无BOM标识的,不然可能出错)
http://www.cnblogs.com/captain_jack/archive/2010/10/12/1848496.htmlgit
windows下使用VS2013进行编译github
mkdir build_msvc cd build_msvc cmake -DCMAKE_INSTALL_PREFIX=D:\AliSQL -G "Visual Studio 12 Win64" ..
执行cmake
前须要安装好bison
。
点击下载sql
执行完成cmake
后生成VS工程文件
使用VS2013 开发人员命令提示
进入build_msvc
目录,执行下面命令进行编译shell
msbuild ALL_BUILD.vcxproj # 编译 msbuild INSTALL.vcxproj # 安装
能够在后面添加/p:Configuration="Release"
参数来指定编译release
版本。由于文件比较多,可使用/maxcpucount:8
来指定使用的CPU核心数,并行编译。bootstrap
安装后在安装目录下创建my.ini
文件,具体写法能够百度。
新建一个start.bat
windows
:: START bin\mysqld --standalone --console
双击start.bat
启动便可。socket
定位到错误代码
#define barrier() __asm volatile("" ::: "memory")
这个宏是GCC
下作编译屏障的宏,VS2013不支持(x64编译也不支持内联汇编),使用windows下的替代版本
#define barrier() MemoryBarrier()
具体的能够看MemoryBarrier macro
参考http://book.51cto.com/art/201504/474436.htm
由于__attribute__
是gcc
的扩展,因此VC不支持也很正常。
在trx0trx.h
文件最前面添加#define __attribute__(...)
便可。
相似的问题还出如今sql_connect.cc
等文件中,能够将上面的宏添加到预编译指令中。
将ha_innodb.cc
中的
static MYSQL_SYSVAR_ULONG(adaptive_hash_index_parts, btr_search_index_num, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, "Number of InnoDB adaptive hash index partitions", NULL, NULL, 8, 1, 512, 0);
修改成
static unsigned long& btr_search_index_num_ul = (unsigned long&)btr_search_index_num; static MYSQL_SYSVAR_ULONG(adaptive_hash_index_parts, btr_search_index_num_ul, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, "Number of InnoDB adaptive hash index partitions", NULL, NULL, 8, 1, 512, 0);
将read0read.cc
中代码(506-508行)
if (view->n_descr > 0) { view->up_limit_id = min(view->up_limit_id, view->descriptors[0]); }
修改成
if (view->n_descr > 0) { view->up_limit_id = (view->up_limit_id < view->descriptors[0])? view->up_limit_id : view->descriptors[0]; }
将read0read.cc
中代码(601-604行)
os_atomic_decrement_lint(&srv_read_views_memory, sizeof(read_view_t) + view->max_descr * sizeof(trx_id_t));
修改成
os_atomic_decrement_lint((volatile lint*)&srv_read_views_memory, sizeof(read_view_t) + view->max_descr * sizeof(trx_id_t));
这样的错误还有几个,都是作这样的修改便可。
4>E:\AliSQL\sql\sql_filter.cc(134): error C3861: “__sync_add_and_fetch”: 找不到标识符 4>E:\AliSQL\sql\sql_filter.cc(356): error C3861: “__sync_add_and_fetch”: 找不到标识符 4>E:\AliSQL\sql\sql_filter.cc(362): error C3861: “__sync_bool_compare_and_swap”: 找不到标识符 4>E:\AliSQL\sql\sql_filter.cc(455): error C3861: “__sync_sub_and_fetch”: 找不到标识符
这是gcc提供的built-in
函数,用于提供加减和逻辑运算的原子操做。参考http://www.cnblogs.com/FrankTan/archive/2010/12/11/1903377.html
能够对应VC下的Interlocked
函数族。
参考http://jishublog.iteye.com/blog/1898518
https://technet.microsoft.com/zh-cn/library/ms683504
带Exchange
的函数返回的是更新前的值,不带的返回更新后的值。
因此这里能够在sql_filter.h
(多个文件中都须要用到)文件头部添加以下宏定义来实现替换
// 返回更新前的值 #define __sync_fetch_and_add(ptr,value, ...) InterlockedExchangeAdd64((LONG64 volatile *)ptr,value) #define __sync_fetch_and_sub(ptr, value, ...) InterlockedExchangeAdd64((LONG64 volatile *)ptr,-value) #define __sync_fetch_and_or(ptr, value, ...) #define __sync_fetch_and_and(ptr, value, ...) #define __sync_fetch_and_xor(ptr, value, ...) #define __sync_fetch_and_nand(ptr, value, ...) // 返回更新后的值 #define __sync_add_and_fetch(ptr, value, ...) InterlockedAdd64((LONG64 volatile *)ptr,value) #define __sync_sub_and_fetch(ptr, value, ...) InterlockedAdd64((LONG64 volatile *)ptr,-value) #define __sync_or_and_fetch(ptr, value, ...) #define __sync_and_and_fetch(ptr, value, ...) #define __sync_xor_and_fetch(ptr, value, ...) #define __sync_nand_and_fetch(ptr, value, ...) #define __sync_bool_compare_and_swap(ptr, oldval,newval, ...) InterlockedCompareExchange64(ptr,newval,oldval)
这是由于VS对utf-8的支持很差(编译器支持很差),将其保存为带BOM
标记的UTF-8编码便可。
先看一下这一段代码
// Sends the global table stats back to the client. int fill_schema_table_stats(THD* thd, TABLE_LIST* tables, Item* __attribute__((unused))) { TABLE *table= tables->table; DBUG_ENTER("fill_schema_table_stats"); char *table_full_name, *table_schema; TABLE_SHARE *share; uint indx;
这里函数中出现了__attribute__((unused))
这个东西,须要处理一下。
在文件sql_show.cc
开头添加(在mysqld.cc
中也须要)
#define __attribute__(...)
这个函数在linux下是有的,windows下没有就使用下面的来替代
char *strsep(char **stringp, const char *delim) { char *s; const char *spanp; int c, sc; char *tok; if ((s = *stringp)== NULL) return (NULL); for (tok = s;;) { c = *s++; spanp = delim; do { if ((sc =*spanp++) == c) { if (c == 0) s = NULL; else s[-1] = 0; *stringp = s; return (tok); } } while (sc != 0); } /* NOTREACHED */ }
由于编译ALL_BUILD
工程完成后会去执行下面操做
Executing E:/AliSQL/build_msvc/sql/Debug/mysqld.exe --no-defaults --console --bootstrap --lc-messages-dir=E:/windows-software/AliSQL/build_msvc/sql/share --basedir=. --datadir=. --default-storage-engine=MyISAM --default-tmp-storage-engine=MyISAM --loose-skip-ndbcluster --max_allowed_packet=8M --net_buffer_length=16K