阿里云 AliSQL 数据库 Mac 平台编译安装

阿里云 AliSQL 数据库 Mac 平台编译安装

若为全新的Mac,安装通用编译组件可通过HomeBrew执行安装。HomeBrew可通过Mac终端执行如下的命令进行安装:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

HomeBrew安装完成后,确保Mac安装了XCode编译工具链(可以从Mac App Store下载),homebrew执行更新操作并安装cmake编译工具:

brew update
brew install cmake

配置完成后,通过如下命令执行下载AliSQL源码:

git clone https://github.com/alibaba/AliSQL.git

源码下载完成后,进入到AliSQL的源码目录,执行如下命令进行make操作:

cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/alisql \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_DATADIR=/var/lib/alisql \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_TOKUDB_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DWITH_EMBEDDED_SERVER=0 \
-DENABLE_DTRACE=0 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" \
-DWITH_SAFEMALLOC=OFF \
-DEXTRA_CHARSETS=all

在cmake指令中,我们将AliSQL的安装目录设定为/usr/local/alisql/目录,数据文件和日志存放在/var/lib/alisql/目录,并且开启了AliSQL的TOKUDB引擎。由于Mac系统与Linux/Unix/BSD系统不同,需要通过brew安装不同的插件,命令为:

brew install jemalloc xz

由于AliSQL中的源码需要使用malloc.h,则执行如下命令:

cp /usr/include/malloc/malloc.h ~/Developer/Repository/AliSQL-master/include

将malloc.h文件复制到AliSQL源码目录中的include目录,可以保证编译时找到malloc.h头文件。接下来可以开始执行编译操作:

sudo make -j 8 && sudo make install

在编译过程中由于宿主机为macOS Sierra 10.12.6,编译时遇到错误:

[ 10%] Built target build_lzma
[ 10%] Built target vio
/Users/kyoushouu/Downloads/AliSQL-master/storage/tokudb/ft-index/portability/portability.cc:160:12: error: 'syscall' is
  deprecated: first deprecated in macOS 10.12 - syscall(2) is unsupported; please switch to a supported interface. For
  SYS_kdebug_trace use kdebug_signpost(). [-Werror,-Wdeprecated-declarations]
return syscall(SYS_gettid);
       ^
/usr/include/unistd.h:733:6: note: 'syscall' has been explicitly marked deprecated here
int      syscall(int, ...);
     ^
1 error generated.
make[2]: *** [storage/tokudb/ft-index/portability/CMakeFiles/   tokuportability_static_conv.dir/portability.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
[ 14%] Built target strings
make[1]: *** [storage/tokudb/ft-index/portability/CMakeFiles/tokuportability_static_conv.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 14%] Built target gen_lex_hash
[ 14%] Building CXX object storage/tokudb/ft-index/portability/CMakeFiles/tokuportability.dir/portability.cc.o
[ 15%] Building CXX object storage/tokudb/ft-index/portability/CMakeFiles/tokuportability.dir/toku_crash.cc.o
[ 15%] Building CXX object storage/tokudb/ft-index/portability/CMakeFiles/tokuportability.dir/toku_path.cc.o
[ 15%] Linking C executable comp_sql
[ 16%] Built target mysqlservices
[ 16%] Linking CXX executable my_safe_process
[ 16%] Building CXX object storage/tokudb/ft-index/portability/CMakeFiles/tokuportability.dir/toku_pthread.cc.o
[ 16%] Building CXX object storage/tokudb/ft-index/portability/CMakeFiles/tokuportability.dir/toku_time.cc.o
[ 16%] Built target regex
[ 16%] Built target comp_sql
[ 16%] Built target my_safe_process
/Users/kyoushouu/Downloads/AliSQL-master/storage/tokudb/ft-index/portability/portability.cc:160:12: error: 'syscall' is
  deprecated: first deprecated in macOS 10.12 - syscall(2) is unsupported; please switch to a supported interface. For
  SYS_kdebug_trace use kdebug_signpost(). [-Werror,-Wdeprecated-declarations]
return syscall(SYS_gettid);
       ^
/usr/include/unistd.h:733:6: note: 'syscall' has been explicitly marked deprecated here
int      syscall(int, ...);
     ^
1 error generated.
make[2]: *** [storage/tokudb/ft-index/portability/CMakeFiles/tokuportability.dir/portability.cc.o] Error 1
make[1]: *** [storage/tokudb/ft-index/portability/CMakeFiles/tokuportability.dir/all] Error 2
make: *** [all] Error 2

由上面的错误信息可知,syscall在10.12中已经deprecated。解决方案:到这里下载OS X 10.11 El Capitan的SDK,在XCode默认SDK目录下:/Applications/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs我们发现只有最新的MacOSX10.12的SDK,接下来我们只需要建立一个软链接到该目录即可:

$ ln -s /Users/kyoushouu/Developer/SDK/MacOS_X_SDKs/MacOSX10.11.sdk /Applications/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk

/Users/kyoushouu/Downloads/AliSQL-master/storage/tokudb/CMakeFiles/tokudb.dir

  • 更正:上面的编译操作中已含有TOKUDB引擎的安装,若需要独立安装TOKUDB引擎,请点我编译并安装Percona Server for MySQL,编译安装Percona Server后即可获得独立TOKUDB引擎。

为了方便AliSQL在终端中的使用,可以创建bash_profile提供AliSQL的快捷操作方式:

cd ~/
touch .bash_profile
vim .bash_profile
=========================================
export PATH=/usr/local/alisql/bin:$PATH
=========================================

AliSQL运行时需要有配置文件,AliSQL存在默认配置文件,可以将其拷贝至/etc/目录下:

sudo cp /usr/local/alisql/support-files/my-default.cnf /etc/my.cnf

AliSQL在初始化时会写入data目录,则需要对data目录做777权限:

sudo chmod -R 777 /usr/local/alisql/data

接下来执行以下程序以初始化AliSQL数据库:

sudo /usr/local/alisql/support-files/binary-configure

初始完成后,接下来运行AliSQL Server:

sudo /usr/local/alisql/bin/mysqld_safe

运行成功后,可使用如下命令检查是否有AliSQL开启:

ps -ef | grep mysqld

最后,操作完成后,可进入AliSQL:

mysql -u root -p

全新安装的AliSQL没有设置账户密码,默认账户密码为空。

➜  mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.6.32 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

执行SHOW ENGINES指令查看当前AliSQL使用的存储引擎列表:

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)

如上所示,如本机编译的一致,则阿里云AliSQL数据库在Mac平台上的编译安装完成。