1、下載源碼
git clone https://github.com/alibaba/AliSQL.git
Linux下編譯
2、編譯
編譯前需要安裝好gcc
cmake
bison
等。(如果缺少其他依賴,debian系的可以使用sudo apt-get build-dep mysql-server
快速安裝)
cd AliSQL
# 創建並進入構建目錄
make build_linux && cd build_linux
# 生成 makefile
cmake -DCMAKE_INSTALL_PREFIX=/home/x/alisql .. #指定安裝路徑/home/x/alisql
# 編譯
make -j4
3、安裝使用
make install # 安裝
安裝完成后可以進入安裝目錄下的bin
目錄
/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
文件,寫入配置文件信息。
啟動mysql
./bin/mysqld
mysql配置文件說明(注意,配置文件應該是UTF-8編碼無BOM標識的,否則可能出錯)
http://www.cnblogs.com/captain_jack/archive/2010/10/12/1848496.html
windows下VS2013編譯
1、生成VS2013工程
windows下使用VS2013進行編譯
mkdir build_msvc
cd build_msvc
cmake -DCMAKE_INSTALL_PREFIX=D:\AliSQL -G "Visual Studio 12 Win64" ..
執行cmake
前需要安裝好bison
。
點擊下載
2、編譯安裝
執行完成cmake
后生成VS工程文件
使用VS2013 開發人員命令提示
進入build_msvc
目錄,執行下面命令進行編譯
msbuild ALL_BUILD.vcxproj # 編譯
msbuild INSTALL.vcxproj # 安裝
可以在后面添加/p:Configuration="Release"
參數來指定編譯release
版本。因為文件比較多,可以使用/maxcpucount:8
來指定使用的CPU核心數,並行編譯。
3、使用
安裝后在安裝目錄下建立my.ini
文件,具體寫法可以百度。
新建一個start.bat
::
START bin\mysqld --standalone --console
雙擊start.bat
啟動即可。
4、編譯錯誤解決
錯誤1:alisql\sql\binlog.h(236): error C2065: “asm”: 未聲明的標識符
定位到錯誤代碼
#define barrier() __asm volatile("" ::: "memory")
這個宏是GCC
下做編譯屏障的宏,VS2013不支持(x64編譯也不支持內聯匯編),使用windows下的替代版本
#define barrier() MemoryBarrier()
具體的可以看MemoryBarrier macro
參考http://book.51cto.com/art/201504/474436.htm
錯誤2:alisql\storage\innobase\include\trx0trx.h(54): error C2146: 語法錯誤: 缺少“,”(在標識符“attribute”的前面)
因為__attribute__
是gcc
的擴展,所以VC不支持也很正常。
在trx0trx.h
文件最前面添加#define __attribute__(...)
即可。
類似的問題還出現在sql_connect.cc
等文件中,可以將上面的宏添加到預編譯指令中。
錯誤3:AliSQL\storage\innobase\handler\ha_innodb.cc(16222): error C2440: “初始化”: 無法從“ulint *”轉換為“unsigned long *”
將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);
錯誤4:AliSQL\storage\innobase\read\read0read.cc(507): error C3861: “min”: 找不到標識符
將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];
}
錯誤5:AliSQL\storage\innobase\read\read0read.cc(603): error C2664: “lint win_xchg_and_add(volatile lint *,lint)”: 無法將參數 1 從“ulint *”轉換為“volatile lint *”
將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));
這樣的錯誤還有幾個,都是做這樣的修改即可。
錯誤6:AliSQL\sql\sql_filter.cc(134): error C3861: “__sync_add_and_fetch”: 找不到標識符
這樣的錯誤有多個
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)
錯誤7:AliSQL\sql\sql_locale.cc(789): error C2146: 語法錯誤: 缺少“}”(在標識符“嗒忇喃嵿嗒苦”的前面)
這是因為VS對utf-8的支持不好(編譯器支持不好),將其保存為帶BOM
標記的UTF-8編碼即可。
錯誤8:AliSQL\sql\sql_show.cc(3896): error C2059: 語法錯誤:“(”
先看一下這一段代碼
// 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__(...)
錯誤9:AliSQL\sql\sql_show.cc(3922): error C3861: “strsep”: 找不到標識符
這個函數在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 */
}
錯誤10:C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(170,5): error MSB6006: “cmd.exe”已退出,代碼為 1。
因為編譯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