Installing MySQL on Mac OS X

If you want to install MySQL on Leopard please read these new instructions on my DIYMacServer.com blog which explains the differences in the installation procedures for Tiger and Leopard.

MySQL logoInstalling MySQL on Mac OS X used to be as simple as installing any application you came across before. You download the disk image, double click on the install package and your done. However the current binary install package from MySQL.com has a problem, it’s compiled with static libraries and we need shared libraries to use MySQL in other self-compiled applications. Therefore the added complication in installing this.

First you need to get yourself the disk-image. You can find it by going to the Mysql.com download section and find the link for the current release. I’ve used version 5.0.26 for my installation. You will get a long list of all kinds of packages for a lot of different platforms. Find the first section mentioning Mac OS X downloads and download the Standard version. Filename should be mysql-standard-5.0.26-osx10.4-powerpc.dmg for a PowerPC mac or mysql-standard-5.0.26-osx10.4-i686.dmg for an Intel based Mac.

When the disk image is finished downloading it will be mounted automatically and you can open the contents. Double click on the mysql-standard-5.0.26-osx10.4-powerpc.pkg (if you have a PowerPC based Mac) to start the installation or the other for an Intel based Mac. Follow the instructions and you will have it installed when finished.

The Mac OS X package of MySQL installs itself into ‘/usr/local/mysql-standard-5.0.26-osx10.4-powerpc’ and also installs a symbolic link, ‘/usr/local/mysql’, pointing to the new location. If a directory named ‘/usr/local/mysql’ exists, it is renamed to ‘/usr/local/mysql.bak’ first. Additionally, the installer creates the grant tables in the ‘mysql’ database by executing ‘mysql_install_db’ after the installation. The MySQL socket file is created as ‘/tmp/mysql.sock’

If you want to start the MySQL database automatically after a reboot you need to install the MySQLStartupItem.pkg as well. The Startup Item for MySQL 5.0 is installed into ‘/Library/StartupItems/MySQLCOM’. The Startup Item installation adds a variable ‘MYSQLCOM=-YES-’ to the system configuration file ‘/etc/hostconfig’. If you would like to disable the automatic startup of MySQL, simply change this variable to ‘MYSQLCOM=-NO-’. The startup item uses the script ‘/usr/local/mysql/support-files/mysql.server’ with the options ’start/stop/restart’ to control everything.

The installer also comes with a Preference Pane which you can install by just double clicking on the MySQL.prefpane icon. With the Preference Pane you can start and stop the MySQL server and select if you want to startup at boot time. Please note that this will only change the entry in the ‘/etc/hostconfig’ file as described above. This will not (de-)install the Startup Item for MySQL.

MySQL Preference Pane

To be able to use the MySQL commands like mysql, mysqldump and mysqladmin from the Terminal you need to add the path to the binaries to your PATH environment variable. You can do that by creating or editing the file ‘.bash_profile’ in your home directory (don’t forget the dot in front of the filename). Add the line:

export PATH="$PATH:/usr/local/mysql/bin"

and restart the Terminal to test it.

To get the shared libraries you need to do another step which might look a bit drastic but it solves any issues you might encounter in compiling the rest of your applications. You need to download the Source to MySQL 5, it’s the tar file called mysql-5.0.26.tar.gz, unpack it and open a Terminal session where you cd into the sourcedirectory and execute the following commands. Please note the different configure instructions for Intel or PowerPC based Macs:

For Intel:

CFLAGS="-arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk" \
./configure --prefix=/usr/local/mysql \
 --localstatedir=/usr/local/mysql/data \
 --libexecdir=/usr/local/mysql/bin \
 --libdir=/usr/local/mysql/lib \
 --with-server-suffix=-standard \
 --enable-thread-safe-client \
 --enable-local-infile \
 --enable-shared \
 --with-zlib-dir=bundled \
 --with-big-tables \
 --with-readline \
 --with-archive-storage-engine \
 --with-innodb \
 --without-docs \
 --without-bench
 

For PowerPC:

CFLAGS="-arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk" \
./configure --prefix=/usr/local/mysql \
 --localstatedir=/usr/local/mysql/data \
 --libexecdir=/usr/local/mysql/bin \
 --libdir=/usr/local/mysql/lib \
 --with-server-suffix=-standard \
 --enable-thread-safe-client \
 --enable-local-infile \
 --enable-shared \
 --with-zlib-dir=bundled \
 --with-big-tables \
 --with-readline \
 --with-archive-storage-engine \
 --with-innodb \
 --without-docs \
 --without-bench
 

For both:

make

sudo make install

And now you’ve got a MySQL installation with shared libraries and can continue compiling and installing all you ever need without a problem (at least I didn’t find any)

You might want to read Securing MySQL server for some added security measures for your fresh MySQL installation.

56 Responses to “Installing MySQL on Mac OS X”

  1. Paul Magrath Says:

    “mysql> drop database test;
    mysql> use mysql;
    mysql> delete from db;
    mysql> delete from user where User = ”;
    mysql> flush privileges;”

    You might add a warning to people not to do this if they are upgrading their installation.

  2. Markis Says:

    I don’t know if it is because I’m using Safari, but on some of the longer code examples they are getting cut-off (i.e.: “otherhost$ ssh mysqlserver /usr/local/mysql/bin/mysqldump -A > bac”).

    Another editing note… I noticed you are using MySQL version 5.0.19, but the rest of your documentation refers to 5.0.18 (i.e.: ‘/usr/local/mysql-standard-5.0.18-osx10.4-powerpc’). I don’t know if WordPress has an easy search and replace function, but that would help keep things up-to-date. Great work!

    Richard5: Thanks it’s corrected, missed that one…

  3. Nate Carroll Says:

    If we originally installed the server logistics version, can we follow your directions above as stated to upgrade (minus killing all the users and databases), or are there extra steps to remove parts of the old version first?

    Thanks!

  4. Chad Keith Says:

    These instructions worked great for compiling MySQL, Thanks!.

    I am compiling my application on a MacBook Pro and trying to compile a universal application. When I select “Intel” as the architecture in Xcode (click on the target and go to Get Info, select the “Build” tab) the source compiles great. When I add “PPC”, I receive the following error:

    warning /usr/local/mysql-standard-5.0.24-osx10.4-i686/lib/mysql/libmysqlclient.dylib cuptype does not match cuptype for specified -arch flag: ppc

    then it lists all of the undefined symbols (MYSQL functions).

    Is there a compiler flag I am missing?

    Thanks again,
    Chad.

  5. John A.. Magdaleno Says:

    For MySQL 5.0.27, I had to manually copy the shared libraries from /usr/local/mysql/lib/mysql into /usr/local/mysql/lib . Otherwise, the PHP 5 install would error out during configuration each time. Did I do something wrong that put the libraries there, or is this something new.

    Thanks for the great info!
    John

  6. Jonathan Watmough Says:

    Thanks for the info. I’m trying to get MySQL working under SBCL and CLSQL, and wasn’t having much luck.

    Thanks,
    Jonathan

  7. John Hopkins Says:

    Excellent information you have put up here Richard5. It worked perfectly. I now have MySQL 5.0.33 running on my machine. Great site. Keep up the great work.

    Thanks,

    John

  8. monoclast Says:

    On January 13th, 2007 at 1:55 pm, John Hopkins wrote:

    >> Excellent information you have put up here
    >> Richard5. It worked perfectly. I now have
    >> MySQL 5.0.33 running on my machine. Great
    >> site. Keep up the great work.

    5.0.33 was a source-only release. There is no Mac OS X package for 5.0.33 that I can find on http://mysql.org. So how would you have followed these instructions to get 5.0.33 running??

  9. Richard5 Says:

    @monoclast, if you read the instructions after the binary install package there is a “how to” compile and install from source. You can still use the preference pane and startup script from an older binary install package.

  10. monoclast Says:

    > On Thu, 18 Jan 2007 07:28:31 +0100 (CET), Richard wrote:
    >>
    >> On January 13th, 2007 at 1:55 pm, John Hopkins wrote:
    >>
    >>>> Excellent information you have put up here
    >>>> Richard5. It worked perfectly. I now have
    >>>> MySQL 5.0.33 running on my machine. Great
    >>>> site. Keep up the great work.
    >>
    >> 5.0.33 was a source-only release. There is no Mac OS X package for 5.0.33
    >> that I can find on http://mysql.org. So how would you have followed these
    >> instructions to get 5.0.33 running??
    >
    > if you read the instructions after the binary install package there is a “how
    > to” compile and install from source. You can still use the preference pane and
    > startup script from an older binary install package.
    >
    > Richard

    I’m sorry, but I’m not sure which instructions you are referring to when you say “the instructions after the binary install package”.

    - If I mount the mysql-standard-5.0.27-osx10.4-i686.dmg file, and open the “ReadMe.txt” file in it, I see no instructions about compiling and installing from source.

    - If I run the installer from that disk image, the same ReadMe.txt file is displayed, and no other instructions are displayed.

    Can you be more specific please?

  11. Richard5 Says:

    @monoclast: What about this page ? It has some instructions… ;-)

  12. monoclast Says:

    Ah I see now - thanks. Sorry for overlooking the obvious.

    I have another question:

    It appears mySQL.org will only be doing source releases from now on.

    Does that mean Mac users will no longer see updates to the startup item and system preference panel portions of the previous Mac package?

    And will Mac users from now on have to start by installing the 5.0.27 package and then “update” it by compiling and installing the latest source on top of that?

  13. michael Says:

    When I try to send commands to my webserver using the “Send RAW command” option in transmit they don’t work. Do I have to set something up so that I can do this? Also, some wordpress plugins seem to require this function as well.

  14. Henk Says:

    Hi there,
    I’m trying to install mysql5.0.27 following the instructions above on a G5 PPC Mac OS X.4.8. I still get the static libraies missing error, what am I doing wrong?
    error syas: checking size of char… 0
    configure: error: No size for char type.
    A likely cause for this could be that there isn’t any
    static libraries installed.

    many thanks

  15. michael Says:

    I’m having the same problem as henk. I’m installing on a PowerPC mac mini running OS X 10.4.8.

  16. michael Says:

    hmm, I seem to have really messed up my installation (I was attempting to upgrade from the V1, server logistics, install).

    Prior to making any changes I did a hard drive clone onto my iPod using SuperDuper! now, I’ve booted from the external drive to get everything back up and running, but MySQL won’t start, Argh! I guess I will take another look at this tomorrow.

  17. Richard5 Says:

    Henk had a problem when using an old version of XCode. He didn’t have the directory /Developer/SDKs/MacOSX10.4u.sdk on his system which messes it up.

  18. Stephen Rider Says:

    Just a quick note — you really should date these posts. When I read “There’s a problem with the current version, I have no idea what “current” means. This is the Internet — I could be reading something written in 2002 for all I know.

    From the dates on comments, I’m guessing it’s a bit newer than that. ;)

  19. Richard5 Says:

    Your comment is noted and already taken care of on my new site diymacserver.com, it shows the creation date and the last time it got updated.

    By the way, it is still a valid remark, as the latest version still has this problem. It has been since 5.0.24. if it would be solved I would have updated the documentation. As this is the internet it’s easy to keep it current.

  20. tima Says:

    Just an FYI for those that want to install the latest from source, you might want to check out http://darwinports.com/ This sight allows you to install a package manager on your Mac that will retrieve and compile software in their repository. MySql 5.0.33 is the current version.

  21. Dennis Says:

    I’m having trouble with the shared libraries. I get this error

    ./bin/mysqladmin version
    dennis-robins-computer-2:/volumes/main/mysql-standard-5.0.27-osx10.4-i686 DER$ chown: /volumes/main/mysql-standard-5.0.27-osx10.4-i686/data/dennis-robins-computer-2.local.err: Operation not permitted
    Starting mysqld daemon with databases from /volumes/main/mysql-standard-5.0.27-osx10.4-i686/data
    rm: /tmp/mysql.sock: Permission denied
    STOPPING server from pid file /volumes/main/mysql-standard-5.0.27-osx10.4-i686/data/dennis-robins-computer-2.local.pid
    070221 20:43:46 mysqld ended

    Then the make
    make
    make: *** No targets specified and no makefile found. Stop.

  22. Jeff Says:

    Richard (or anyone else…):

    I am about to embark on upgrading MySQL to 5.0.27 (which seems as of today (Feb 21, 2007) to be the current stable release, and I want to know if anyone has experienced any problems or lack of problems with this scenario:

    I am not upgrading anything else. At the moment the only way I access my MySQL databases is through PHP. I am using PHP 5.2.0 - Marc Liyanage’s distribution.

    My concern is that if I follow these steps, I may possibly break something in the PHP connection.

    Has anyone done this? Or does anyone have suggestions on things to look out for in doing this?

    Any help (or even reassurance that it’s very unlikely I’ll have a problem) is very much appreciated!!

    Thank you

  23. Kevin Says:

    I having the same problem as Dennis; I get the same exact message when i try to compile the binaries.

    Any suggestions? Thanks in advance!

  24. Mintyness Says:

    I am attempting to follow the second half of th einstructions for installing MySQL (the “./configure…” stuff), and I am using 5.0.37 on an Intel MacBook Pro. However, when I try to configure it to include the shard libs, I get the following from the .tar.gz distribution:

    “NOTE: This is a MySQL binary distribution. It’s ready to run, you don’t
    need to configure it!”

    …And it creates a db and starts the daemon. Ummm, I’m guessing that’s not what shouldbe occuring. Any ideas?

    Thanks in advance,
    HRM

  25. Barbara Says:

    I’m also having the same problem as Dennis and Kevin …

    ./bin/mysqladmin version
    barbara-shaurettes-computer:~/mysql-5.0.37-osx10.4-i686 bshaurette$ Starting mysqld daemon with databases f
    rm: /tmp/mysql.sock: Permission denied
    STOPPING server from pid file /Users/bshaurette/mysql-5.0.37-osx10.4-i686/data/barbara-shaurettes-computer.
    070316 16:41:47 mysqld ended

    Anyone have any ideas?

  26. Richard5 Says:

    @ Dennis, Kevin and Barbara:

    Please stop your current MySQL server that is locking the files, rename the directory that MySQL is located in and try again…

  27. Jonathan Says:

    Hi,

    I’m having the same problem as Dennis (comment 21), but I have stopped MYSQL (as oer the advice in comment 26). It’s a clean install of the version 5.0.37 on OSX 10.4.9 PPC. Any suggestions? The package installed fine, its just when adding the shared libraries I get:

    chown: /Users/Jonathan/Desktop/mysql-5.0.37-osx10.4-powerpc/data/imac-g4-wlan.home.err: Operation not permitted

    and the like.

    Thanks

  28. Jonathan Says:

    In follow-up, turns out I have stupidly downloaded the binary, not the source! Thanks Richard5

  29. stephen Says:

    I of course had the same problem as Dennis, Kevin and Barbara.

    @Richard5

    which Mysql directory? Mysql, Mysql-vs, or the Mysql source files directory.

  30. stephen Says:

    FYI (mysql-5.0.37) After a bunch of warnings the error I am receiving is:

    configure: error: No size for char type.
    A likely cause for this could be that there isn’t any
    static libraries installed. You can verify this by checking if you have libm.a
    in /lib, /usr/lib or some other standard place. If this is the problem,
    install the static libraries and try again. If this isn’t the problem,
    examine config.log for possible errors. If you want to report this, use
    ’scripts/mysqlbug’ and include at least the last 20 rows from config.log!

    TIA

  31. stephen Says:

    So, after some debugging, the problem was simple. I was performing this on a fresh install of an old PPC power book. And the Dev Tools were older and thus the universal tool set was not available for the install. Once that was fixed everything compiled perfectly.

    Thanks again.

  32. Mike Says:

    I get an error :

    ./configure does not exists.
    Also, make command cannot be found.

    Any ideas?

  33. Mike Says:

    Hi Rich!

    problem: I restored my db from a mysql dump sql file. When using mysql query browser, I dont see the tables. When I connect using /usr/local/mysql/bin/mysql I can see all of the tables.

    I tried using mysql_fix_priv…. but I changed the root user name, so I get an error.

    What am I to do?

    M

  34. TigerKR Says:

    the “source” is AT THE BOTTOM OF THE WEB PAGE, under the heading “Source downloads”, NOT “Mac OS X (package format) downloads” and NOT “Mac OS X (TAR packages) downloads”. You can use this link to get to the source download:

    http://dev.mysql.com/downloads/mysql/5.0.html#source

  35. 7stud Says:

    Thanks TigerKR!

    WARNING:
    The mysql source downloads are corrupt at this time. The md5’s don’t match. Apparently, mysql knows about it, but inexplicably they don’t think it’s important enough to put a warning on their website.

  36. Stephen Durkin Says:

    In reference to post #34 (thanks TigerKR!), I had already made the mistake of downloading the MAC OS X (TAR packages) downloads instead of the source downloads, and then issuing the author’s configure command, so now I think I have TWO MySQL INSTALLATIONS (OOPS :)…

    What is the safest, cleanest way of uninstalling/removing the inadvertent second MySQL installation?? I haven’t done anything after issuing the configure command, but it seems to have started a mysqld process as a side effect of the command (strangely)…which I then stopped.

    Thanks for reading this far!

  37. Richard5 Says:

    If you only ran the configure command, nothing really happened besides looking at the configuration and setup you had. Just delete the extracted directory and start again with the source.

  38. Tim Says:

    Hi Richard, i’m having the same issues that Dennis had.

    chown: /Users/Tim/Desktop/DOWNLOADS/t_mysql-5.0.45-osx10.4-i686/data/127.0.0.1.err: Operation not permitted

    the preference pane says that mysql is not started, and i’ve renamed the source directory from where i am trying to compile… any ideas ?

    Thanks

  39. Kevin Says:

    Hay, im having the same problems as Dennis and Tim. With the operation not pemitted.

    Any idea?

  40. alias Says:

    I keep hearing about a package installer, none of the mysql osx downloads have a package installer, or am I losing my mind everything has to be done via the terminal am i missing something ?

    Is there any place we can download mysql that comes with an automatic installer ?

  41. Richard5 Says:

    Look at the list of downloads and use the one for your mac listed under the header “Mac OS X (package format) downloads”.

  42. alias Says:

    did that and downloaded but there’s no package installer, can only be installed via commandline

  43. alias Says:

    doh!! i got it this time, must be losing my mind, all the other downloads didn’t come with it but this one was a lucky charm came with the installer thanks :)

  44. mikehal Says:

    A few suggestions after my experience with your invaluable guide:

    Put the following tips clearly (I’d go ALL CAPS even):

    1. Don’t use Unstuffit Expander to unpack tar files. It’s an easy slip-up for macheads.

    2. When doing the shared library part, make sure you scroll all the way down to the bottom of the downloads page at mysql.com and grab the source tar (vs the binaries tar)

    Also, why the double install in the first place?

    Also, a big thanks Richard5!

  45. Holly Says:

    Has anyone run into this? I just installed the mysql 5.0.45 osx10.3 powerpc.pkg and then the startup item. But when I double-click to install the mysql.prefpane, I get the following two messages:
    —–
    The preference pane you are installing is already installed. Do you want to replace the existing preference pane?

    To this, I click “OK”, and then get the following message:

    —-
    preferences error
    you cannot open MySQL preferences pane on this computer. Contact the developer of this software for a newer version.

    I’m running Tiger 10.4

    Why can’t I get the preference pane to open?

    Thank you,
    Holly

  46. Richard5 Says:

    Sounds like a permissioning issue. But it’s not a real problem, the old pref pane will still work, I think it’s even the same one.

  47. Cicada Says:

    I am having the same problem as Holly– just finished installing MySQL on a new MacBook Pro Intel Core Duo and got the message:

    You cannot open MySQL preferences pane on this computer. Contact the developer of this software for a newer version.

    Doesn’t matter whether I install the preference pane to be acessible to all users, or just to admin (myself). Is there a fix for this? Thanks!

  48. Erica Says:

    I am also getting the same error message when I attempt to open my preference pane! If anyone has a fix for this - please share!! Thanks!

  49. Richard5 Says:

    I just found out that Cicada used the wrong package. Please make sure you’ve downloaded the correct package for the right kind of Mac you’re using.

    The “Mac OS X 10.4 (x86)” if you’re using intel and “Mac OS X 10.4 (PowerPC, 32-bit)” if you are using a PowerPC Mac.

  50. Scott Says:

    I have followed your directions as best as I could being a noobie to terminal and UNIX. Please forgive my short-comings in comprehension of your excellent work here.

    I have downloaded the package which installed the MySQL5 into /usr/local/
    I have the preferance pane and startup item also installed on my Mac PPC 10.4.

    Have used the right packages !

    My confusion began when you referred to the prefix -
    To be able to use the MySQL commands like mysql, mysqldump and mysqladmin from the Terminal you need to add the path to the binaries to your PATH environment variable.

    export PATH=”$PATH:/usr/local/mysql/bin”

    Which I placed in /usr/local/ (figuring that was my “home” directory. (am I right)

    Then ! I downloaded the source binary of the same MySQL 5.0.45 and I did the cd mysql-5.0.45 to get into the directory to place your install pref for shared library.

    Terminal referenced another instalaton of MySQL and would not let me initiate the “make” comand ?

    Little confused ?

    Thanks so much for this…

  51. Steven Says:

    Hey,
    how about how to specify and option file?

    like the my-huge.cnf file included with the install.

    lmk

  52. Scott Says:

    I feel quite silly asking.. but hey the good news is I have installed Mysql perfectly as per your guide.

    My question is - How do I find out what my local host id is using UNIX terminal on Mac?

    Also -

    Does the next step of installing the apache server replace the existing 1.03 that comes standard with OS10.4.10. I have rebuit my machine from scratch (actually) re-installed (formatted) a number of times.

    I really want to get this right.

    Being that I am on a MAC G5 on a Windows SBS2003 server connected to the internet via a gateway on the server, does that effect my ability to connect it straght to the internet?

    It would be good to set it up right from the start. I am only really using it as a testing server so it is not “absolutely” required. but any help or suggestions here would help me out.

    Oh yeah the server is directly connected to internet with a fixed IP address.

  53. Davis Says:

    I feel stupid, but i have to say that my understanding of linux and command line is lacking. Is there anyway around this or a more step by step description.

    thanks

  54. Richard5 Says:

    David, if you are using linux your distribution should have a package manager that should take care of the installation of MySQL. Please read the documentation or ask in the forum of the distribution you are using. This install guide is for Mac OS X only.

  55. David Says:

    I am doing this on mac osx, its actually a brand new mini, its not really about the install of MySql, where i am stuck is at the “To get the shared libraries you need to do another step which might look a bit drastic”

    i am not sure what you mean when you day download it to MySql. could you help me with a more step by step process or get me a tutorail that may help

    thanks - i realize that my issues are my lack of knowledge

  56. Richard5 Says:

    David, please goto http://diymacserver.com/docs for the latest documentation and “how-to” on installing MySQL.

Leave a Reply