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
Mariadb增加Jemalloc内存管理
Jemalloc在OS X下有一个很奇怪的问题,jemalloc安装在/usr/local
目录的开发包无法被Mariadb识别,几经尝试,暂时发现了一个解决方法。
Mariadb本身使用cmake作为跨平台编译解决方案,但是最终在OS X上还是使用LLVM来编译,所以我们直接编译好jemalloc以后直接使用-L和-l参数来手动指定库文件位置。
Jemalloc编译
还是三板斧./configure --prefix=/path/to & make & make install
/path/to即为安装目录,随便指定即可。
然后我们来到安装目录的lib
目录下,所有的动态静态链接库都在这里,我们直接删除到只剩下jemalloc_pic.a这个静态库文件,因为gcc默认发现了动态库文件就会使用动态库文件来连接,而我们需要静态连接。
然后这次我选择了mariadb-10.1.8这个10.1系列第一个stable(GA)版本。
cd mariadb-10.1.8
cmake . -DBUILD_CONFIG=mysql_release -DCMAKE_EXE_LINKER_FLAGS="-L/path/to -ljemalloc_pic" -DWITH_SAFEMALLOC=OFF
make
注意:/path/to是要到libjemalloc_pic.a目录的
然后。。。就发现,神奇的报错了,报错信息如下
[ 55%] Building CXX object storage/mroonga/vendor/groonga/lib/CMakeFiles/libgroonga.dir/dat.cpp.o
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:191:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:222:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:423:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:452:5: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:465:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:552:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:576:5: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:592:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:617:5: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:616:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:652:5: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:651:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:703:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:811:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:864:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:921:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:969:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:1007:3: error: cannot use 'try' with exceptions disabled
try {
^
/Users/tangjiacheng/Downloads/mariadb-10.1.8/storage/mroonga/vendor/groonga/lib/dat.cpp:1101:3: error: cannot use 'try' with exceptions disabled
try {
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
查了一下,原来是Mroonga引擎搞的鬼,幸好homebrew已经有了解决方案,我们直接修改storage/mroonga/vendor/groonga/CMakeLists.txt
@@ -192,6 +192,10 @@ if(CMAKE_COMPILER_IS_GNUCXX)
check_build_flag("-Wno-clobbered")
endif()
+if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
+ MY_CHECK_AND_SET_COMPILER_FLAG("-fexceptions")
+endif()
+
if(NOT DEFINED CMAKE_C_COMPILE_OPTIONS_PIC)
# For old CMake
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGCXX)
然后再编译就成功了
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。