MySQL 5 Server Cannot Start on Apple Mac Leopard

There were some problem during configuring MySQL5 Server on Leopard with MacPorts when creating default db with command;

sudo -u mysql mysql_install_db5

Error Messages;

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
mkdir: /opt/local/var/db/mysql5: Permission denied
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
chmod: /opt/local/var/db/mysql5: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
mkdir: /opt/local/var/db/mysql5: Permission denied
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
chmod: /opt/local/var/db/mysql5/mysql: No such file or directory
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
mkdir: /opt/local/var/db/mysql5: Permission denied
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
chmod: /opt/local/var/db/mysql5/test: No such file or directory

It’s the permission issue, to generate default, try this command;

sudo mysql_install_db5

Now MySQL5’s default DB should be successfully initializes to /opt/local/var/db/mysql5. But there is some problem when starting MySQL;

shell> sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper start
Starting MySQL
/opt/local/share/mysql5/mysql/mysql.server: line 159: kill: (31272) – No such process
ERROR!

Have a look at the system.log file on your Leopard;

Jun 9 17:09:59 redarrows com.apple.launchd[1] (0x10bac0.nohup[31285]): Could not setup Mach task special port 9: (os/kern) no access
Jun 9 17:09:59 redarrows com.apple.launchd[1] (0x10bac0.nohup[31286]): Could not setup Mach task special port 9: (os/kern) no access
Jun 9 17:09:59 redarrows com.apple.launchd[1] (0x10bac0.nohup[31291]): Could not setup Mach task special port 9: (os/kern) no access

This should be the permission issue on MySQL database folder, to solve this, chown your mySQL db folder to _mysql:_mysql…

sudo chown -R _mysql:_mysql /opt/local/var/db/mysql5

Now go to the db dir and see the permission;

shell> cd /opt/local/var/db/
shell> ls -al mysql5
drwx—— 5 _mysql _mysql 170B Jun 9 17:09 mysql5

Now, try to start MySQL5 Server again;

shell> sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper start
Starting MySQL
SUCCESS!

Hell ya, MySQL5 successfully running on your machine! Voila, Happy MySQL-ing with your Apple Mac Leopard!