Richard
For most of the systems/applications we are going to install a database is required to store the information that is used by the applications. All the users and their mailbox configurations, the spamfilter settings and learned filters, the pages in my WordPress blog, the discussions in the forum, etc…
I’ve choosen for the MySQL Community Server as the database of choice as it was the first choice of most of the systems/applications I installed on my server. Other Choices are available but aren’t as widely supported by applications I use.
Installing MySQL on Mac OS X Lion is again as simple as installing any application you come across. You download the disk image, double click on the install package and your done. There are some additional steps you need to take to get everything working properly but you don’t need to recompile it as we used to.
First you need to get yourself the disk-image. You can find it by going to the Mysql.com download section and find the “Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive“. There is no specific 10.7 (Lion) version available yet and this one works.
When the disk image is finished downloading it will be mounted automatically and you can open the contents. Double click on the package installer to start the installation. Follow the instructions and you will have it installed when finished.
The Mac OS X package of MySQL installs itself into ‘/usr/local/mysql-5.5.xx-osx10.6-x86_xx‘ 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'.
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 do not install this as it uses an outdated manner of starting the database after a reboot. The same is true for the MySQLStartupitem, please don’t use it. We’ve got a better method of starting MySQL automatically.
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 make sure that all the programs compile correct you’ll need to execute the following command, when you’ve finished the installation, in the Terminal:
sudo install_name_tool -id /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.dylib
There is another little snag, Mac OS X has a funny way of using _username for user running daemon processes. The “mysqld_safe” script which is used to start mysqld safely will use the user “mysql” while the user “_mysql”has been given access to the /data directory. You can see that this will result in a conflict. Therefore we need to edit the “mysqld_safe” script and add a single character, change:
user='mysql'
into:
user='_mysql'



Comments
2:11 am
I tried this method of install
and while I could see and touch mysql from the terminal
my existing web apps could not see the database..
what would be the special voodoo to make mysql install or have the pointers to the same places as SL
to be clear I am trying to migrate my existing PHP/MYSQL apps to lion
as it is I can install mysql but the mysql.sock seems to not be in the right place..
anythoughts?
9:36 am
@Garret, are you sure you build of PHP is capable of using MySQL? Try to look at the output of phpinfo(); otherwise please compile PHP per our instructions. http://diymacserver.com/mamp/lion/compiling-php/
2:59 pm
Very helpful! You recommended not installing the Preference Pane and the MySQLStartupitem because there’s a better method of starting MySQL automatically. Sure enough, it does seem to start.
What’s the mechanism, and is there an easy way to turn off autostart? Thanks.
5:31 pm
@john B. If you look at http://diymacserver.com/Lion/ you will find all the information you are looking for. The specific information you want is on http://diymacserver.com/mamp/lion/starting-mysql-automatically/
7:06 pm
Thanks much! I had googled into the install section, and did not see the fuller context. Great stuff, thanks again.
12:26 pm
I’ve put n/a because this applies solely to my off-line development system (10.0.1.x). I’ve followed the advice above, and all appeared to go well apart from the penultimate step, when I got this error: ‘sudo: install_name_tool: command not found’.
In any event, I can’t load any of my MySQL-based sites, including phpMyAdmin (#2002 Cannot log in to the MySQL server). PHP is fine, but in answer to your question to Garret above, phpinfo() reckons the client API version of MySQL is 5.0.8, which is an ancient installation. When I first got my present iMac a year ago, running Snow Leopard, I installed 5.1.46 (I’m pretty sure you helped me with this!), but it doesn’t even recognise that.
5:36 pm
Update: I found an install_name_tool command in /Developer/usr/bin/ and copied it into /usr/bin/ – this is entirely guesswork as I don’t really have a clue what I’m doing at this level, but it seemed to work. At least, I could run the command without an error. However, this hasn’t changed anything in my favour. I still can’t get near any MySQL-driven sites, the only change being the error number I get from phpMyAdmin when I try to log in. This is now #1045 if that’s any help.
10:31 am
@Chris, the command line with the command “install_name_tool” should work without doing something like moving it around. It looks like something is wrong with your installation. Did you install Xcode?
Many things might be wrong with your installation and it is hard to pinpoint the cause. The instructions on this site work with a plain vanilla OSX installation. There might be interference from a previous different attempt like using macports or fink. If you are able to try with a clean install (or use a virtual machine)
12:08 pm
I hadn’t installed Xcode – at least, not the Lion one – but I have now, not that it’s made any difference to anything.
I agree, my installation is probably all rather a mess: I now have folders in /usr/local for ‘mysql-standard-5.0.19-osx10.4-powerpc’, ‘mysql-5.1.46-osx10.6-x86_64′ and ‘mysql-5.5.15-osx10.6-x86_64′, the last of which is obviously the one I’m trying to use.
I have at least used the locate command in Terminal to ascertain that my data is still there, in various places, of which I assume the most relevant is /usr/local/mysql.bak (the new installation moved it there, yes?). It’s also still there in the old 5.0.19 folder, but I assume that’ll be way out of date. Curiously, on my overnight SuperDuper! backup drive, which is a complete clone of my startup disk, the data is in both of those locations, and it’s also in the 5.1.46 folder, and yet it appears not to be in that folder on the internal drive. Or maybe it’s just that locate didn’t find it for some reason? I haven’t touched any of this since the backup in the small hours of this morning.
Anyway… it seems to me that the two main things I need to do somehow are to tell Apache/PHP to use the latest installation of MySQL, and to tell all three of them where my data is… but I haven’t the foggiest idea at this point how to do either.
Where on earth phpinfo() gets 5.0.8 from I’ve no idea – searching for ’5.0.8′ with locate finds only a handful of files, none of which look as if they have anything to do with MySQL.
For what it’s worth, if this turns out to be impossible, I do have a separate development platform that I’ve barely used on a shared server at my usual host, so I could perfectly easily do my development there. I just somehow feel it’s convenient to have it all on my Mac too.
12:42 pm
@Chris, it sounds weird to have PPC and X86 binaries on the same machine. To find out which one is actually being used is to run the command “mysql_config”, it will show you all things configured for your current MySQL installation. Can you post the output of that here or mail it to me?
9:26 pm
Hi Richard,
Sorry to bother you but I’ve had an odd thing come up. I’ve installed MySQL 5.52 on OSX Lion which I know has not been tested but thought I would try anyway. When I try to link in the libraries per your instructions I’m unable to find install_name_tool. I’ve installed Developer tools and rebooted and still get the following error:
sudo install_name_tool -id /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.dylib
Password:
sudo: install_name_tool: command not found
Any ideas?
7:16 pm
@Greg, can you try “sudo /Developer/usr/bin/install_name_tool ….” the newer version of Xcode installer puts everything in the /DEveloper directory and you have to include that in your path.
5:19 pm
Tried:
sudo install_name_tool -id /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.dylib
Result:
sudo: install_name_tool: command not found
Any thoughts as to why this would be?
Thanks
5:25 pm
@Andrew, have you installed Xcode and/or the command line tools? See http://diymacserver.com/2012/03/30/follow-up-on-apache-2-4-1-xcode-4-3-2/ for more info on Xcode and the command line tools.
6:18 pm
Thanks, that worked.
Also where is the mysqld_safe script located?
6:22 pm
@Andrew, its located in /usr/local/mysql/bin