Installing MySQL on Mac OS XPosted by Matt Thommes on June 14, 2009 | Post type: Gain Earlier we mentioned how to enable PHP on Mac OS X. MySQL is often a crucial ally to PHP, when developing applications locally. Unfortunately MySQL is not installed by default on Mac OS X client machines. Luckily, the setup process is well-detailed and easy to accomplish. The instructions are outlined at Marc Liyanage's site, and I will talk briefly about each step, while pointing out additional things I experience while installing MySQL on OS X. MySQL downloadMarc's site suggests downloading MySQL version 4.1, which is not the latest version by a long shot. Perhaps he prefers that version, or he hasn't got around to updating the link on his site. Rather than going to the download link he suggests, you may be better off visiting the main downloads page, dev.mysql.com/downloads/, which automatically provides downloads for the latest version. Choose "Download" under "MySQL Community Server":
Then pick the Mac OS X "package format":
Since I am running Mac OS 10.5 on my Intel MacBook, the appropriate download is "Mac OS X 10.5 (x86)":
Install locationOnce downloaded, click on the package and go through the install process. When finished installing, you can see where MySQL was physically installed by visiting the Finder and choosing Go > Go to Folder...:
Type
Connecting to MySQLThis sets things up initially, but we still have to tweak some settings to make things work properly. Open a Terminal window, which is found under Applications > Utilities:
We're going to navigate to the install folder mentioned above, but using Terminal instead of the Finder. Type
Now type Then type Finally, type
You've just connected to MySQL! Feel free to issue MySQL commands on the "test" database to get a feel for using the MySQL monitor via Terminal:
Adjust MySQL root passwordAn important thing to do immediately is adjust the MySQL root password, to ensure the security of your databases. First, exit the MySQL monitor by typing Next, type:
... but replace To change the root password after it's already been set, type this command:
It will then prompt you for the old password before it can change the password to the new one. Create Terminal shortcut to access MySQL monitorAnytime you want to log back in to MySQL via Terminal, type:
... then enter your password when prompted. You'll notice this is a lot to type every time you simply want to connect to MySQL via Terminal. It would be nice to avoid having to type To create a shortcut to that location, type this command:
Now, when you want to access MySQL via Terminal, all you have to type is:
Accessing MySQL from outside TerminalAccessing MySQL from the Terminal directly is not exactly the most ideal way to interact with your databases. If you're writing web applications, you'll need to access MySQL via a scripting language, such as Rails or PHP. Just use the appropriate values when connecting to MySQL via scripts:
Socket errorSometimes this error will prevent you from connecting to MySQL:
I've noticed two reasons this error could show up:
For #1, there is a small fix that can correct this. Type the following commands into Terminal: cd /var sudo mkdir mysql cd mysql sudo ln -s /private/tmp/mysql.sock mysql.sock These commands assume that the directory It will then move the sock file to a spot where a scripting language (specifically PHP) looks for it. Restart MySQL server after reboot or crashFor #2, this is a simple fix. Often MySQL will not be running after OS X crashes, and is rebooted, for example. To start up the MySQL server again, type these commands into Terminal (same as further up when initially setting things up): cd /usr/local/mysql sudo echo sudo ./bin/mysqld_safe & /usr/local/mysql/bin/mysql test This starts the MySQL server again, and logs you in to the test database. Final thingsIf everything is working right, you may also want to install a front-end app like phpMyAdmin for easier database administration. About the author(s)Matt Thommes is an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from a suburb of Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us. Comments
|
Quick Link to this postTTIP.me/2191 |
Hey Matt, great post. For some reason the short cut does not work for me. I am on Leopard.
Quick Link to this comment: http://TTIP.me/c5182