zoukankan      html  css  js  c++  java
  • AliSQL的编译使用

    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 binmysqld --standalone --console
    

    双击start.bat启动即可。

    4、编译错误解决

    错误1:alisqlsqlinlog.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:alisqlstorageinnobaseinclude rx0trx.h(54): error C2146: 语法错误: 缺少“,”(在标识符“attribute”的前面)

    因为__attribute__gcc的扩展,所以VC不支持也很正常。
    trx0trx.h文件最前面添加#define __attribute__(...)即可。
    类似的问题还出现在sql_connect.cc等文件中,可以将上面的宏添加到预编译指令中。

    错误3:AliSQLstorageinnobasehandlerha_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:AliSQLstorageinnobase ead ead0read.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:AliSQLstorageinnobase ead ead0read.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:AliSQLsqlsql_filter.cc(134): error C3861: “__sync_add_and_fetch”: 找不到标识符

    这样的错误有多个

    4>E:AliSQLsqlsql_filter.cc(134): error C3861: “__sync_add_and_fetch”:  找不到标识符
    4>E:AliSQLsqlsql_filter.cc(356): error C3861: “__sync_add_and_fetch”:  找不到标识符
    4>E:AliSQLsqlsql_filter.cc(362): error C3861: “__sync_bool_compare_and_swap”:  找不到标识符
    4>E:AliSQLsqlsql_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:AliSQLsqlsql_locale.cc(789): error C2146: 语法错误: 缺少“}”(在标识符“嗒忇�喃嵿�嗒苦�”的前面)

    这是因为VS对utf-8的支持不好(编译器支持不好),将其保存为带BOM标记的UTF-8编码即可。

    错误8:AliSQLsqlsql_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:AliSQLsqlsql_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)MSBuildMicrosoft.Cppv4.0V120Microsoft.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
    
  • 相关阅读:
    函数嵌套
    函数对象
    可变长参数
    函数的参数
    函数的调用
    函数的返回值
    定义函数的三种形式
    函数的定义
    SQLAlchemy
    Flask总结完整版
  • 原文地址:https://www.cnblogs.com/oloroso/p/6004220.html
Copyright © 2011-2022 走看看