August 04, 2009
Install MySQL on Mac OSX
The article takes you through all of it step by step, if you want to skip reading and just get to all commands you need then go there now.
Download the package First of course you need to get the installation package on www.mysql.com. Click the download link, choose MySQL Community Server and the Mac OS X (package format). For all recent Macs you need the x86_64 version.
Install all the package contents Once you have downloaded the package install MySQL and also the StartupItem and MySQL.PrefPane. The startup item makes sure the database is started every time you startup your Mac and the prefpane allows you to control this.

Check whether MYSQL is really running When you have installed all open the MySQL preference in your System Preferences to make sure the database is really running.

Setup the command line tools Now one of the things the installation is missing it to set the paths for the command line tools. To fix this open a terminal window (in your Applications > Utilities folder) and type: echo ‘export PATH=/usr/local/mysql/bin:$PATH’ >> ~/.profile
Set a password on your database server Best practice would be to add a new user and disable the standard database root user. Depending on the scenario you could have many different databases with different users assigned to them. For now we will just add a password to the default root database user. In a terminal window type: mysqladmin -u root password NEWPASSWORD
If you want to change the password after you have set the initial password you need to use: mysqladmin -u root -p’OLDPASSWORD’ password NEWPASSWORD
Set up the manual pages The command line manual pages are a great and directly available resource if you need help using the command line tools. Unfortunately they are not automatically set up properly by the installation. Lucky for us it is fairly simple to do. Just open a terminal window again and type: echo ‘export MANPATH=/usr/local/mysql/man:$MANPATH’ >> ~/.profile to set the path and then: sudo /usr/libexec/makewhatis to rebuild the manual pages index.
If all went well you should be able to get the manual pages by typing: man mysql
Set MySQL for use with PHP Only needed if you want to run or develop php based applications (websites) that make use of the MySQL database. The default setup puts the mysql.sock file in the wrong location so that needs to be corrected. Again, open a terminal windows and type: sudo mkdir /var/mysql sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
The commands for all this magic
Open a terminal window and fire off all these commands, obviously after replacing the passwords. echo ‘export PATH=/usr/local/mysql/bin:$PATH’ >> ~/.profile echo ‘export MANPATH=/usr/local/mysql/man:$MANPATH’ >> ~/.profile sudo /usr/libexec/makewhatis sudo mkdir /var/mysql sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock mysqladmin -u root password NEWPASSWORD mysqladmin -u root -p’OLDPASSWORD’ password NEWPASSWORD
Troubleshooting
If you have an issue with the mysqladmin command there are two things you can do to troubleshoot. All commands without quotes!
Check if the software is installed correctly (usually is). Open a terminal window and type cd /usr/local/mysql/bin and then type ./mysqladmin status. If it returns some status information it’s installation is fine and the issue in in the path.
Check your .profile to see if the path is correct. From the same terminal window, typecat ~/.profile. It should have a line with export PATH=/usr/local/mysql/bin:$PATH. If not, go back to: Setup the command line tools
I hope reading this is as useful for you as writing and finding it all out (again) was for me.
6 comments
Post a comment
Your e-mail is never shared, required fields marked with *
I’ve followed above instruction, when i typed “mysqladmin -u root password NEWPASSWORD” command not found came. it’s not working on my mac os. please help me
You need to type the commands without quotes. If you did that I’d guess the command line tools setup did not work. You can test this by going to /usr/local/mysql/bin and then typing ./mysqladmin -u root password NEWPASSWORD
I’ve tried the same as dhirendra and received the same results
Rheals-lappy:~ rheal$ mysqladmin -u root password MyPassword -bash: mysqladmin: command not found Rheals-lappy:~ rheal$
You may want to check the quotes on this line and do it again. echo ‘export PATH=/usr/local/mysql/bin:$PATH’ >> ~/.profile
After installing the MySQL.PrefPane I had the message ‘Do you want the application “mysqld” to accept incoming network connections?’ and while trying to research this, the message disappeared. Have you come across this?
@dhirendra After installing mysql using installer downloaded from (http://www.mysql.com/downloads/mysql-4.0.html) I got the same error message: $ mysqladmin -u root password NEWPASSWORD -bash: mysqladmin: command not found After messing around for ages (and getting nowhere) I just re-installed from the original package I downloaded and it now works without error.