In my other howto, I installed Apache, PHP and MongoDB. I now need to setup MySQL so that I can develop a WordPress theme and plugin on my local machine. Here are the few steps I used:
sudo port install mysql5-server
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
sudo -u _mysql mysql_install_db5
sudo chown -R _mysql:_mysql /opt/local/var/db/mysql5/
sudo chown -R _mysql:_mysql /opt/local/var/run/mysql5/
sudo chown -R _mysql:_mysql /opt/local/var/log/mysql5/
I then add the following aliases to make it easy to start, stop and restart MySQL:
mate ~/.bashrc
alias mysql-start="sudo /opt/local/share/mysql5/mysql/mysql.server start"
alias mysql-restart="sudo /opt/local/share/mysql5/mysql/mysql.server restart"
alias mysql-stop="sudo /opt/local/share/mysql5/mysql/mysql.server stop"
source ~/.profile
You can then use the following to start MySQL:
mysql-start
Note: I had errors when I first tried starting MySQL. This was because I’d installed a version of MySQL previously from the official site and it was conflicting. Removing the old version of MySQL did the trick – instructions here.
When you start the server, it’s best to set the root user password:
mysqladmin5 -u root password mysupersecretpassword
Then to setup PHP to work with MySQL:
sudo port install php5-mysql
Then update the php.ini file:
sudo nano /opt/local/etc/php5/php.ini
And ensure this line is in there:
mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
Restart Apache, and then you’re all set.