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 = $(CC) <strong>-arch ppc64</strong> -dynamiclib -install_name $(DESTDIR)$(libdir)/`basename $@` -compatibility_version $(ABI_VERSION) -current_version $(ABI_VERSION) -o $@
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.
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' lib/libmenu.5.dylib: Mach-O 64-bit dynamically linked shared library <strong>ppc64</strong> lib/libmenu.dylib: symbolic link to `libmenu.5.dylib' lib/libncurses.5.dylib: Mach-O 64-bit dynamically linked shared library <strong>ppc64</strong> lib/libncurses.dylib: symbolic link to `libncurses.5.dylib' lib/libpanel.5.dylib: Mach-O 64-bit dynamically linked shared library <strong>ppc64</strong> lib/libpanel.dylib: symbolic link to `libpanel.5.dylib'
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").
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="$CC <strong>-arch ppc64</strong> -dynamiclib $allow_undefined_flag -o $lib $libobjs $deplibs$compiler_flags -install_name $rpath/$soname $verstring"
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.
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.