Installation of MySQL server on Mac OS X Lion

This article is part of Django Installation on Mac OS X Lion

At the time of writing this post, MySQL Server on MySQL site doesn’t have installer package for OS X 10.7 (aka Lion) but 10.6 Package works just fine for 10.7 as well. This may change soon and we may see package for OS X 10.7 as well or may be rename current package to 10.6 & above.

Installing MySQL community server:

  1. Download the latest  64-Bit DMG Archive (Apple Disk Image) from MySQL Site (http://dev.mysql.com/downloads/mysql/). Current latest version is 5.5.14 which I’ll be using to install on my machine.
  2. Mount the Disk Image (I mean open/double-click the DMG file) and install MySQL server by double-clicking the PKG file (in my case mysql-5.5.14-osx10.6-x86_64.pkg) and follow onscreen instructions. ( It will ask for Master password, as it installs MySQL server in /usr/local )
  3. Add /usr/local/mysql/bin to your path by editing .profile file. (Optionally you can create alias to mysql and mysqladmin as mentioned in README File)
  4. You can start MySQL server by running “/usr/local/mysql/bin/mysqld_safe &” from terminal but Disk image you downloaded also consists of Startup Package & Preferences Pane which allows you to start/stop MySQL server from System Preferences and even Automatically Start MySQL Server at Startup.

*Please note /usr/local/mysql is only symlink to /usr/local/mysql-5.5.14-osx10.6-x86_64 which means when you upgrade to new version symlink will be changed to point to new version but won’t be deleting the older version. However you need to copy your data directory to new location to make sure your existing databases are intact post upgrade.

Installing MySQL Startup Scripts & Preferences Pane (OPTIONAL)

  1. Double Click MySQLStartupItem.pkg and Follow on screen instructions (You will be asked for Master Password)
  2. Double Click MySQL.prefPane which will add MySQL to OS X System Preferences and it should like something like below

    MySQL Mac OS X Lion Preferences

    MySQL Mac OS X Lion Preferences

  3. Check Automatically Start MySQL Server on Startup to start MySQL server at boot time.

In next section we will discuss installing phpMyAdmin which will provide us web interface to perform basic MySQL administration tasks on Mac OS X Lion.

31 thoughts on “Installation of MySQL server on Mac OS X Lion

  1. I am trying to host a WordPress site on a Lion Server. I was able to get MySQL downloaded and installed and running on this machine. However, there is a disconnect between the web server and MySQL when I try to build out a WordPress site. I have the MySQL server running and verified it is indeed running as I can hit it and make changes using Navicat. When I try to built out a WordPress site, however, I am getting the following error when it tries to create the wp-config file (I get database connection error when I try to manually create the wp-config file as well).

    “Error establishing a database connection
    This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down.

    Are you sure you have the correct username and password?
    Are you sure that you have typed the correct hostname?
    Are you sure that the database server is running?”

    It appears that there is a disconnect between Apache running on this machine under Lion Server and the MySQL Server that I installed. Separately they are both up and running, but for some reason they cannot communicate with each other. Can you explain what might be causing this? Any guidance is appreciated.

  2. Pingback: Installing Django on Apple Mac OS X 10.7 aka Lion | A Non-Programmer Approach to Django

  3. I’m trying to get MySQL running on Lion Server. I can do it from the command line… using mysqld running as a user named mysql. I can’t for the life of me figure out how to get this to run as a daemon. The MySQL pref pain does nothing at all. No errors, no warnings.. nadda.

    I have 30 MySQL databases.. and Apple wants me to switch to PostGre… are they off their bleeding rockers?

  4. What do you mean by

    Add /usr/local/mysql/bin to your path by editing .profile file. (Optionally you can create alias to mysql and mysqladmin as mentioned in README File)

    PLEASE HELP.

  5. “Add /usr/local/mysql/bin to your path by editing .profile file. (Optionally you can create alias to mysql and mysqladmin as mentioned in README File)”

    What I did was:

    In a terminal type: nano ~/.profile

    then paste the line below:
    export PATH=/usr/local/mysql/bin:$PATH

    and save. Restart your terminal (close and open it) and do a: echo $PATH and it should not list the mysql/bin folder

  6. Do you have to be running Lion Server Edition to use mysql databases lcoally? There won’t be any remote clients. Just a loca SQL database being queried from the same machine it is stored on.

  7. Please, I don’t know where have to save .profile. I don’t find the “local” path. Can you help me with step 3 please?? Thanks!

  8. It is probably worth suggesting that you run /usr/local/mysql/bin/mysql_secure_installation as well – this will let you set a root password and generally tighten up the security of the base install.

  9. “ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/Applications/MAMP/tmp/mysql/mysql.sock’ (2)” :(

    from some reason on my MBP works fine but mini make some problems :(

    Any help?

  10. Apple going to PostgreSQL because Oracle have ALL RIGHTS on MySQL, and there is have some conflict (such as in JAVA-cleaning situation) :)

    Try also migrate your DB to PostgreSQL, or use MySQL your choice :)

  11. Like seija I get the same message:
    mysqlcheck: Got error: 2002: Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (2) when trying to connect

    I am trying to get this to work on my MBP.

    How could this be happening? Suggestions?

  12. Wondering if I need to edit /etc/my.cnf to get this to work.
    Since it’s throwing error 2002 on socket ‘/var/mysql/mysql.sock’ should I change the following in /etc/my.cnf?
    port = 3306
    socket = /var/mysql/mysql.sock

    Thanks for any info on this! :)

  13. Great article. And thanks for the tip, Gary. Setting up a password is essential for allowing login to phpMyAdmin with the default configuration.

  14. Installed the startup scripts and prefpane, that does not work on reboot, and clicking start does not work, no errors.

    Tried starting it with “/usr/local/mysql/bin/mysqld_safe &”, got a host of permission errors.

    ps aux | grep mysql has this running, and I can’t stop it

    _mysql 11985 0.0 0.0 2466484 872 ?? Ss 3:52pm 0:00.01 /sbin/launchd

    Tried starting it with sudo and the command above, it starts something but it’s not right.

    Totally didn’t work for me :-(

  15. Where do i set the username and keyword for the Server????
    i don’t get it!

  16. hi, after using it, I was happy with it. but now I need to uninstall it completely, How can I do that?

  17. Hey, this blog entry is still providing some good useful service–thanks! I’ve consulted it a couple of times: once after messing around with my Python installation (MySqlWorkbench uses it) and again to find out about the rudimentery info about .profile and System Preferences.
    Thanks again.

  18. After installing mysql-5.5.27-osx10.6-x86_64 as described, my mysql failed to start.

    I have found in error log that the following :

    120826 9:41:38 InnoDB: Operating system error number 13 in a file operation.
    InnoDB: The error means mysqld does not have the access rights to
    InnoDB: the directory.
    InnoDB: File name ./ibdata1

    Then I have found that ib* files had root ownership in data directory

    -rw-rw—- 1 root wheel 5242880 Aug 26 09:21 ib_logfile0
    -rw-rw—- 1 root wheel 5242880 Aug 26 09:21 ib_logfile1
    -rw-rw—- 1 root wheel 18874368 Aug 26 09:21 ibdata1

    The following resolved the issue:
    > gregorykneller$ sudo chown _mysql ib*

  19. I am trying to download the mysql server for mac from mysql website but I cant find the download the file with the bloody DMG file.
    What am I doing wrong?

  20. I am trying to download the mysql server for mac from mysql website but I cant find the download the file with the bloody DMG file.
    What am I doing wrong???

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>