If you want to install MySQL on Lion it’s pretty easy, just head on over and download the DMG from mysql.com (for lion you’ll need the 64bit DMG Archive).
Then double click on mysql package to install it, then on MySQLStartupitem.pkg, and then on the MySQL.prefPane. Once that’s done start it up via system prefs.
Finally, you will need to add ‘/usr/local/mysql/bin’ to your path environment. To do this, open up terminal and type in:
Or if you have textmate you can use:
Then just update the export PATH if there’s one already there, my file looks like this:
eval "$(rbenv init -)"
PS1="[\W:]$ "
alias ll="ls -lahG"
alias irbs="irb --simple-prompt"
alias rake="bundle exec rake"
Then save it. Rbenv already created the PATH so I just updated it. The PS1 line tells terminal to show the directory you are currently in as the prompt (you can always use ‘pwd’ to get the full path to working directory if you forget where you are). I’ve also added the alias to ll, which shows you all your files in the directory (including hidden files) with permissions, when you type in ll in terminal. The alias, irbs, will give you irb –simple-prompt, and the last one for rake, will use bundler.
If you want your terminal prompt to be in red, use the following instead:
Close the terminal window and restart it for changes to take effect, and now you should be able to type ‘mysql’ and get to MySQL.
Set root password for MySQL
It’s good practise to set your root password, here’s how:
SET PASSWORD FOR root@localhost=PASSWORD('your_password_here');
FLUSH PRIVILEGES;
Install MySQL gem for Ruby
If you’re using Ruby, simply open a terminal window and:
Enter your user password (not your mysql one) when asked.
If you get an ‘Library not loaded: libmysqlclient.18.dylib’ when doing your first rake db:migrate, you will need to add this to your .bash_profile
(Then simply close and open a new terminal window)
If that doesn’t work try running this in your terminal:
All done
This is what my .bash_profile looks like btw, I’ll probably keep it updated in this post given I mention it above:
export PATH="$HOME/.rbenv/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
eval "$(rbenv init -)"
PS1="[\W]\$ "
alias ll="ls -lahG"
alias irbs="irb --simple-prompt"
alias rake="bundle exec rake"
alias bec="bundle exec cucumber"
alias ber="bundle exec spec"
alias pow="touch tmp/restart.txt"
Why not give PostgreSQL a go?
Since writing this guide I have moved to Postgres – it is a much better relational database and includes many features such as a nosql option, queueing, transactions plus lots more. It is also very fast and very stable – and now seems to be the database of choice for Rails developers. You can install easily by brew install postgresql (you can install it in addition to MySQL btw – so you don’t have to choose one or the other).
Tags: clean lion install for ruby dev, Lion, mysql, OS X
Your instructions were correct and I got mysql up on my OS LION 1.2
my only issue now is I was looking for and couldn’t find /etc/my.cnf
Hi Greg
The OS X install doesn’t create a my.cnf file – it just uses default values. If you would like to create your own you can:
cd /usr/local/mysql/support-files/
sudo cp my-huge.cnf /etc/my.cnf
That will copy over a sample my.cnf file (to /etc/my.cnf) that you can edit.
Greetings,
I have installed mysql 5.5.20 for Lion but cannot get it to start from the preferences pane. Any suggestions??
Thanks
What does it say David? Have you tried restarting the machine? Did you double click the pref pane installer? (MySQL.prefPane)
I installed MySqil.prefPane. The prefpane exists in my system preferences. After attempting to start the server (even after a restart) it asks for password then does not start. Prefpane “mySQL server instance is stopped” and remains stopped. I had the same problem with OSX 10.6.8 and upgraded to Lion in attempt to resolve this. I tried this fix but the basedir and datadir are correctly defined.
http://forums.mysql.com/read.php?11,399397,399606#msg-399606
Any help is greatly appreciated. Thanks.
I have exactly the same problem with Lion. I tried almost everything on the web about this issue. Even noone points the problem this much clearly.
I have tried to install 5.5.21 DMG, even the beta 5.6.x; nothing works. You can’t start the database from preferences pane. It remains stuck as “stopped” even after clicking the start button and entering the admin password, and then the computer thinking for a little while…
Any comment on this is highly appreciated…
Hi both, the only thing I can suggest is try doing a clean Lion install, as I had no probs doing it that way: http://astonj.com/tech/clean-lion-install-for-ruby-development/
hi Guys, have you tried this: http://jaykhimani.blogspot.com/2010/12/mysql-55-startup-problems-on-os-x-1065.html
?
[in part similar to what David posted but more complete)
Thanks Aston, great help!
Aston you ROCK!
Thanks Aston. Your instructions guided me well.
I’m trying to download myql community server on my macbook, the download is fine and when you click on it something loads, but then it disappears. there is a file in my downloads folder but I can’t find an installer anywhere. help!
Thanks Dude! After I updated to Ruby 1.9.3p194 and RVM
I was getting a “Library not loaded: libmysqlclient.18.dylib” error only when using pow.cx. It was fixed by using your symlink suggestion.
Just a note. Lion comes with Postgresql already installed, so you don’t have to install it.
I have installed MySQL on my laptop and have both, so I can switch back and forth depending upon the one I need.
[...] (4) http://astonj.com/tech/how-to-install-mysql-on-lion-mac-os-x/ [...]
i m getting rbenv command not found error