Articles July 16, 2005 at 4:08 pm

Building 64-bit MySQL on Mac OS X (10.4)

You're most likely reading this because you're as sick as I am of seeingmalloc warnings when trying to start up MySQL in Mac OS X on your Xservewith 8GB of RAM and you've configured MySQL to use more than 4GB. If I've got 8GB of RAM, why can't I use more than 4GB in MySQL? Well, just because you've got 64-bit processors and an OS with64-bit support doesn't mean that your applications run in 64-bit. Youhave to explicitly build your application for the 'ppc64' architecturein order to take advantage of 64-bit addressing and use more than 4GBof RAM. Here's how you build MySQL as a 64-bit application.

Read on for more…

The instructions in this article assume you want to install mysql in/usr/local/mysql. If you want to install it elsewhere, then just replace/usr/local/mysql with your desired path wherever you see it in thefollowing instructions.

The first thing you have to do is download the ncurses library. This isn't necessary for the MySQL server software, but the command line interface uses it and the ncurses libraries that come with Mac OS X appear to be 32-bit only. So, first download ncurses and unpack it.

 curl -O http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.4.tar.gz   tar -zxf ncurses-5.4.tar.gz cd ncurses-5.4

Basically all you need to do to build a 64-bit application in Mac OS Xis to add some flags to the compiler (gcc). The easiest way to do thatis to set some environment variables that the build system understandsand it will pass on the flags to gcc. Running the following commandwill ensure the build configuration system knows about these flags youwant to pass to gcc. Once configured it will place the flags in most of the right places so it will build as 64-bit. I'll touch on a few special cases later in the article.

I found I had to explicitly set CFLAGS, CPPFLAGS and CXXFLAGS before I ran configure or make. The build system ignored the flags when I just exported them as environment variables.

 CFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64"   CPPFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64"     CXXFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64"     ./configure --prefix=/usr/local/mysql --with-shared

Once you've configured your ncurses build, you'll have to make a few changes to the Makefiles because the configure system does not placethe most important gcc flag in all of the places it needs to be. Edit thefollowing files and add "-arch ppc64" before "-dynamiclib" on the linesthat begin with "MK_SHARED_LIB". There is only one line that needs to beedited in each file.

    form/Makefile   ncurses/Makefile    menu/Makefile   panel/Makefile

It should look like this:

   MK_SHARED_LIB   = &#36;(CC) <strong>-arch ppc64</strong> -dynamiclib -install_name  &#36;(DESTDIR)&#36;(libdir)/`basename &#36;@` -compatibility_version &#36;(ABI_VERSION)     -current_version &#36;(ABI_VERSION) -o &#36;@

Once you're done with those changes, just type 'make' and ncurses willbe built as a 64-bit library. Before you install it, check the librariesthat were built to make sure they're 64-bit.

   file lib/*.dylib

Make sure that the .dylib descriptions end with 'ppc64'. If they end withjust 'ppc', then ncurses did not build correctly. Make sure the CFLAGS,CPPFLAGS, and CXXFLAGS declarations are all placed immediately beforethe ./configure so it is one command, not four.

  lib/libform.5.dylib:    Mach-O 64-bit dynamically linked shared library <strong>ppc64</strong>  lib/libform.dylib:      symbolic link to `libform.5.dylib&#39;  lib/libmenu.5.dylib:    Mach-O 64-bit dynamically linked shared library <strong>ppc64</strong>  lib/libmenu.dylib:      symbolic link to `libmenu.5.dylib&#39;  lib/libncurses.5.dylib: Mach-O 64-bit dynamically linked shared library <strong>ppc64</strong>  lib/libncurses.dylib:   symbolic link to `libncurses.5.dylib&#39;   lib/libpanel.5.dylib:   Mach-O 64-bit dynamically linked shared library <strong>ppc64</strong>  lib/libpanel.dylib:     symbolic link to `libpanel.5.dylib&#39;

If you've got 64-bit ncurses libraries, install them and we'll move on tothe MySQL build process.

  sudo make install

Now run the following command to configure MySQL's build process. If thereare other options you use in your MySQL builds (BDB, Cluster, etc.) YMMV.(Your Mileage May Vary)

   CFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64 -force_cpusubtype_ALL"     CPPFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64 -force_cpusubtype_ALL"   CXXFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64 -force_cpusubtype_ALL"   ./configure --prefix=/usr/local/mysql   --enable-shared     --enable-static     --enable-thread-safe-client     --with-named-curses-libs=/usr/local/mysql

There is a problem with the 'bool' type not being declared. I'm not surewhy building it as a 64-bit application causes this problem with the configuration, but here's how you can fix it. Edit 'include/my_global.h'and add the following at line 22 (below "#define _global_h").

 #include 

The last change you need to make is to tell 'libtool' that it needs tobuild 64-bit shared libraries. It seems like the '-arch ppc64' flag getslost when passed to 'libtool' so we'll just set it manually.

Edit the 'libtool' file and edit line 205 (begins with "archive_cmds=").We need to add "-arch ppc64" before "-dynamiclib" here also to ensure that libtool builds 64-bit libraries and executables.

  archive_cmds=&quot;&#36;CC <strong>-arch ppc64</strong> -dynamiclib &#36;allow_undefined_flag -o &#36;lib   &#36;libobjs &#36;deplibs&#36;compiler_flags -install_name &#36;rpath/&#36;soname &#36;verstring&quot;

Now all you need to do is to type 'make' and then let it run for a fewminutes. Once the build is complete, type 'sudo make install' and enteryour password to install it. Run the following command to check yourinstalled files to make sure they were properly built as 64-bit applications. You should see the 'ppc64' identifier on the right againin the descriptions.

 file /usr/local/mysql/bin/*

That's it. Be sure to run the mysql tests that come with it (make test) to be sure there aren't any problems with the build. I didnotice that one test (the kill test) failed in MySQL 4.1.12, but that occurred in the 32-bit build also, so it's not a 64-bit-related problem. You should now be able to set some very large configuration values without any problems now. To test it, I set key_buffer to 4GB and query_cache_size to 4GB on a system with 5GB of RAM and it started up without any complaints and I ran the tests on it.

So now you can give MySQL as much RAM as you want. Bear in mind it's a good idea to stick with your physical RAM limits so you can avoid hitting the virtual RAM (swap, on-disk memory). Be sure to leave some RAM for the OS itself also. At least 512MB – 1GB.

Good luck, and if you've got questions, I'll be happy to answer them as best I can.

Gabriel Ricard
[email protected]

No Comments

  • I’m not sure why it didn’t come through, but each time there is a multi-line command in the article, there should be a backslash at the end of each line to indicate that the command should be all on ONE LINE when you enter it in Terminal.

    An example is this command:

    CFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64"
    CPPFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64"
    CXXFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64"
    ./configure –prefix=/usr/local/mysql –with-shared

    On the command line, without the backslashes, it should be on one line:

    CFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64" CPPFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64" CXXFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64" ./configure –prefix=/usr/local/mysql –with-shared

  • This is what I used and it worked great.

    ./configure \
      --prefix=/usr/local/mysql \
      --with-shared \
      CFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64" \
      CPPFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64" \
      CXXFLAGS="-mpowerpc64 -mcpu=G5 -mtune=G5 -arch ppc64"
    

    Of course building MySQL with GCC 4.0 is still giving me
    problems.

    — Dale

  • You need to replace ‘<‘ with ‘&lt;’ and ‘>’ with ‘&gt;’ when you
    need to use these characters cause we can’t see what you have in your

    #include

    statment because of this problem.

  • Ugh. I posted a comment and it doesn’t seem to have appeared. Anyways… Like Tim O said, it’s stdbool.h that is the include.

  • I can’t get this to build. I’ve tried gcc 3.3 and 4.0 here’s the error I get:
    Making all in client
    /bin/sh ../libtool –preserve-dup-deps –mode=link g++ -O3 -DDBUG_OFF -fno-implicit-templates -fno-exceptions -fno-rtti -DHAVE_DARWIN_THREADS -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -o mysql mysql.o readline.o sql_string.o completion_hash.o ../cmd-line-utils/libedit/libedit.a /usr/local/mysql ../libmysql/libmysqlclient.la -lm -lz
    g++ -O3 -DDBUG_OFF -fno-implicit-templates -fno-exceptions -fno-rtti -DHAVE_DARWIN_THREADS -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -o .libs/mysql mysql.o readline.o sql_string.o completion_hash.o /usr/local/mysql -Wl,-bind_at_load ../cmd-line-utils/libedit/libedit.a ../libmysql/.libs/libmysqlclient.dylib -lm -lz
    ld: can’t map file: /usr/local/mysql ((os/kern) invalid argument)
    make[2]: *** [mysql] Error 1

    Thanks in advance!

    • Try changing this part of the MySQL ./configure command

      –with-named-curses-libs=/usr/local/mysql

      to this:

      –with-named-curses-libs=/usr/local/mysql/lib/libncurses.dylib

  • FYI, MySQL AB is now providing 64-bit builds of MySQL on their download page
    (without installer).

    http://dev.mysql.com/downloads/mysql/4.1.html