OS X编译安装MariaDB


MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。

很多开发环境需要我们安装数据库,随着mysql的日渐衰弱,更多的开发环境使用mariadb作为数据库,而mariadb数据库目前没有OS X的release版本,所以我们需要手动编译安装

修改代码

由于mariadb本身使用了tokudb的上游代码,而tokudb目前尚未有支持OS X的计划,所以常规安装方式是不成功的,我们需要对代码本身进行修改。
由于是tokudb引擎导致的问题,所以只需要修改两个文件
storage/tokudb/ft-index/cmake_modules/TokuSetupCompiler.cmake

-set(CMAKE_C_FLAGS "-Wall -Werror ${CMAKE_C_FLAGS}")
-set(CMAKE_CXX_FLAGS "-Wall -Werror ${CMAKE_CXX_FLAGS}")
+set(CMAKE_C_FLAGS "-Wall ${CMAKE_C_FLAGS}")
+set(CMAKE_CXX_FLAGS "-Wall ${CMAKE_CXX_FLAGS}")

storage/tokudb/ha_tokudb.cc
- extern const char * const tokudb_hton_name;
+ extern const char *tokudb_hton_name;

笔者猜测最根本的原因是tokudb没有对OS X编译工具链做编译测试,OS X的编译工具是LLVM和BSD工具,而并非是gcc和GNU工具,所以在一些细节上有一些差别。如果没有改代码,会导致以下信息报错

[ 80%] Building CXX object storage/tokudb/ft-index/locktree/CMakeFiles/locktree_static.dir/locktree.cc.o
In file included from /Users/tangjiacheng/Development/server/storage/tokudb/ft-index/locktree/locktree.cc:99:
In file included from /Users/tangjiacheng/Development/server/storage/tokudb/ft-index/locktree/locktree.h:94:
/Users/tangjiacheng/Development/server/storage/tokudb/ft-index/buildheader/db.h:323:1: error: 
empty struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat]
struct __toku_db_lsn {
^
1 error generated.
make[2]: *** [storage/tokudb/ft-index/locktree/CMakeFiles/locktree_static.dir/locktree.cc.o] Error 1
make[1]: *** [storage/tokudb/ft-index/locktree/CMakeFiles/locktree_static.dir/all] Error 2
make: *** [all] Error 2

In file included from /Users/tangjiacheng/Development/server/storage/tokudb/ha_tokudb.cc:8293:
/Users/tangjiacheng/Development/server/storage/tokudb/hatoku_hton.cc:262:13: error: 
redefinition of 'tokudb_hton_name' with a different type: 'const char *'
vs 'const char *const'
const char *tokudb_hton_name = "TokuDB";
^
/Users/tangjiacheng/Development/server/storage/tokudb/ha_tokudb.cc:382:31: note: 
previous definition is here
extern const char * const tokudb_hton_name;

注:至于一些朋友说homebrew install mariadb可以安装mariadb的说法,其实是因为homebrew本身修改过mariadb的代码,增加了一个cmake选项禁用了tokudb,而tokudb本身代码是没有问题的,因噎废食的做法笔者不敢苟同,所以还是原生编译安装更加实在。Homebrew.mariadb

使用XtraBackup备份恢复MariaDB数据库 

在 CentOS/RHEL/Scientific Linux 6 下安装 LAMP (Apache with MariaDB and PHP)

MariaDB Proxy读写分离的实现

Linux下编译安装配置MariaDB数据库的方法

CentOS系统使用yum安装MariaDB数据库

安装MariaDB与MySQL并存

Ubuntu 上如何将 MySQL 5.5 数据库迁移到 MariaDB 10 

[翻译]Ubuntu 14.04 (Trusty) Server 安装 MariaDB 

相关内容