MySQL workbench on Mac OS “Error 1046 – No database selected”

While playing around with the triple stores and a MySQL db on our Macs, I ran into a little problem when trying to change a column name in one of the tables in the MySQL database. The error message I got from the MySQL workbench was mildly confusing:

Error 1005: Can’t create table ‘families’. (errno: 13) […]

Error 1046: No database selected

Since the query was automatically generated by the MySQL workbench, I presumed it had to be correct. A bit of googling, and this friendly chap’s forum post helped me find the solution to the problem: Access rights. As always. Here’s how you allow the MySQL user to write to the MySQL directory:

Find the name and group of the MySQL user in /etc/group and /etc/passwd respectively:

less /etc/group
less /etc/passwd

On our Mac OS X 10.7 Mac mini with a default MySQL 5.5 install, the user name and group is _mysql. 

Then set the owner and mode of the MySQL install directory:

cd /usr/local
sudo chown -R _mysql:_mysql mysql-5.5.25-osx10.6-x86_64/
sudo chmod -R 755 mysql-5.5.25-osx10.6-x86_64/

This may be obvious, but make sure you chown/chmod the actual MySQL directory, not the symlink in /usr/local which is named mysql.

That’s it – you should be able to modify your database now.