阿里云 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_BUILD_TYPE="Release" -DCMAKE_INSTALL_PREFIX="/usr/local/alisql" -DWITH_EMBEDDED_SERVER=0 -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_CSV_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1

由于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
  • 上面的编译操作中不含有TOKUDB引擎的安装,若需要安装TOKUDB引擎,请点我编译并安装Percona Server for MySQL,编译安装Percona Server后,若需要编译支持TOKUDB引擎的AliSQL,可在上面AliSQL的cmake操作中增加以下子指令再次编译AliSQL后即支持TOKUDB引擎。

    -DWITH_TOKUDB_STORAGE_ENGINE=1
    

为了方便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)

如上所示,如本机编译的一致,除TOKUDB引擎外的其他引擎均正常使用。则阿里云AliSQL数据库在Mac平台上的编译安装完成。