Macs ship with a built in version of MySQL Community Edition that meets most requirements, however MySQL doesn’t get updated by Apple through Software Updates unless of a major security vulnerability. So what do you do if you have to upgrade? You can’t upgrade this built in version of MySQL, however you can install a second instance of a newer version and take all your data with you.
Here’s How So hold on…
This guided is based upon Mac Server 10.6.8 Snow Leopard.
Ensure to stop the MySQL instance running on the Mac server (through Server Admin).
Install the mysql-5.5.27-osx10.6-x86.pkg (obviously the version may be different), then the MySQLStartupItem.pkg and lastly the MySQL.prefpane.
Now you might have already been using the built in version of MySQL and therefore have data. You most likely will need to utilise all the users/databases etc in this new version. To do this the best way I have found is to symlink your data directory in the new install of MySQL to the existing database location.
Open Terminal More data please Sir…
To restore your users/databases navigate to the new install in Terminal:
list the directory
ls -l to check that there is a symlink from the mysql directory to your new installation directory (obviously the version number may be different), eg:
lrwxr-xr-x 1 root staff 25 Sep 25 08:08 mysql -> mysql-5.5.27-osx10.6-x86/
If there isn’t this symlink, create it (obviously changing the version number for yours):
sudo ln -s mysql-5.5.27-osx10.6-x86/ mysql
cd into mysql folder and list the contents
ls -l to see if there is a data directory? Check that it symlinks to /var/mysql like so:
lrwxr-xr-x 1 root wheel 11 Sep 25 09:30 data -> /var/mysql/
If it doesn’t exist or isn’t a symlink (just a folder), first backup the folder:
sudo mv data data.back
Then create the new symlink:
sudo ln -s /var/mysql data
The next step is to upgrade the database schema, to do this you need temporary write access to the bin directory for temporary files through the upgrade, so chmod it first:
sudo chmod 777 bin
cd into the bin directory of the new installation and run mysql_upgrade:
If you run into any errors like:
Warning: mysql_connect(): Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (2)
Then you may need to symlink the mysql.sock location from /private like so:
sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock
Don’t forget to chmod the bin directory back!
sudo chmod 755 bin
Now you should be able to Open System Preferences > MySQL PreferencePane and start the MySQL server.
Please let me know if this blog post has helped you or if you have anything to add!