May 23, 2009

MySQL vs. CS4 on OS X


In brief:
Two partitions:
Boot partition: case-insensitive. Adobe CS4 installs normally. MySQL installs from easy-to-use binary installer pkg.
CaSe partition: case-sensitive. Holds MySQL data files.

Create this file:
/etc/my.cnf
...and enter:
[mysqld]
socket = /tmp/mysql.sock
datadir = /Volumes/CaSe/MySQL_data

Copy the data files:
sudo cp -R /usr/local/mysql/bin/data/mysql /Volumes/CaSe/MySQL_data/mysql
sudo cp -R /usr/local/mysql/bin/data/myDB /Volumes/CaSe/MySQL_data/myDB

Then:
sudo chown -R mysql /Volumes/CaSe/MySQL_data/mysql
sudo chgrp -R wheel /Volumes/CaSe/MySQL_data/mysql

For PHP:
sudo cp /etc/php.ini.default /etc/php.ini
line 761 (or so) find "mysql.default_socket=" and add "/tmp/mysql.sock"

Restart.
The Problem:
Gypsy 6's MySQL databases require a cAsE-SensiTive boot drive, but Adobe CS4 requires an case-insensitive boot drive.

The Brainstorm
Maybe it's only the MySQL _data_ that has to be on a case-sensitive drive, while the MySQL server software can be on a case-insensitive boot drive.

The Pain
Five years of installing CS2, 3, 4 on a case-insensitive virtual disk, totally foiled by Flash 10 and Actionscript 3. Nineteen straight hours of formatting my old 40GB external hard drive with various formats and then installing OS X and MySQL, over and over again.

The Result
It freakin' works!



Prologue - The Death Sentence
I made a back-up of my client's database with the MySQL GUI tool called "MySQL Administrator". It was super easy. I could also have done this in a Terminal window, but I didn't so I don't have that command here. Just Google "back up MySQL database".



Act I - Installageddon
- I formatted my 40GB external drive with two partitions. One partition is about 35GB and is the default, case-insensitive format and is called "LaCie 40". The smaller 5GB Partition is HFS+ (case-sensitive) format and is called "CaSe" (<- no spaces in the name!!!).
- I installed OS X Leopard to the case-insensitive partition.
- I did all the software updates (which got me up to OS X 10.5.7).
- I ran the user-friendly installer for MySQL 5.x. on the same case-insensitive partition (you don't get a choice, the MySQL server software _must_ be on the boot drive).
- Restarted my Mac



Act II - Terminalator
- I made a new folder on the very top level of my case-sensitive partition "CaSe" called "MySQL_data" and used the Info window to make all the permissions for that folder "Read and Write" for every user I found.
- I created a new file: /etc/my.cnf by typing this in the Terminal:
myMac > sudo bbedit /etc/my.cnf (you can use the omnipresent vi if you don't have bbedit)
and put the following text in it:
[mysqld]
socket = /tmp/mysql.sock
datadir = /Volumes/CaSe/MySQL_data
- Then I did this:
myMac > sudo cp -R /usr/local/mysql/data/mysql /Volumes/CaSe/MySQL_data/mysql
The MySQL server software uses it's own database called "mysql". The above line copied it to my case-sensitive partition. I've moved the actual mysql datafiles!

- Restarted my Mac



Act III - Permission To Ill
Now I use Terminal to set up my database:
myMac > /usr/local/mysql/bin/mysql

If this gave me the fucking "/tmp/mysql.sock" error I did this:
myMac > sudo echo
myMac > sudo /usr/local/mysql/bin/mysqld_safe &

(See UPDATE 2 below for a more permanent fix for the mysql.sock problem.)

and then I left that Terminal window open. Maybe I didn't have to, but what the hell, Terminal windows are free.

Then I did this again:
myMac > /usr/local/mysql/bin/mysql

Which got me the happy "MySQL is working" message and the mysql prompt:
mysql >

Hurrah, MySQL is running. Now I log out of MySQL (type "exit") and then do this:
myMac > /usr/local/mysql/bin/mysqladmin -u root password myPassword

Now log in again as root like this:
myMac > su
sh-3.2 > /usr/local/mysql/bin/mysql -u root -p
and at the mysql prompt I did all this crap:
mysql > CREATE database MyDatabase;
mysql > GRANT all on MyDatabase.* to root@localhost identified by 'myPassword';
mysql > GRANT select, insert, update, delete, create, drop on MyDatabase.* to MainUser@localhost identified by 'UserPassword';
mysql > GRANT select, insert, update, delete, create, drop on MyDatabase.* to MainUser@"%" identified by 'UserPassword';
mysql > GRANT select on MyDatabase.* to WebSurfer@domain.com identified by 'WebPassword';

I opened another Terminal window and restored myDatabase like this:
sh-3.2# ./mysql -u root -p MyDatabase < /Volumes/myMac/web_sites/client_1/client_1_backup_file.sql <- your .sql file will be called something else.



Act IV - Wacked-Out On PHP
From here it was the normal OS X web server set-up, including /etc/apache2/httpd.conf, /etc/hosts, and copying /etc/php.ini.default to /etc/php.ini like this:
myMac > sudo cp /etc/php.ini.default /etc/php.ini
myMac > sudo bbedit /etc/php.ini
I opened /etc/php.ini in BBEdit then scrolled down to line 761 where it says "mysql.default_socket =" and added "/tmp/mysql.sock" This is what makes PHP know how to find the MySQL server.

This did it. Now I have case-sensitive databases and a case-insensitive boot drive for CS4 to clog up. But this process is so long, and so many things can go wrong, that the best I can hope for is to provide a rough guide to be used in combination with the guides I used to figure out all this horseshit.


Comments, addendums, fixes, all are welcome. This problem is not going to go away for me, so any extra info I can collect will help me the next time I have to do this.

UPDATE 1:
Adobe CS4 installs perfectly. Everything runs great.

UPDATE 2:
I migrated the external drive to my regular drive in my laptop, which generated a lot of permissions trouble and I couldn't get MySQL to run at all. I ran the permissions clean-up from the command line:
myMac > sudo /usr/sbin/periodic daily weekly monthly
the I Restarted. This helped a little. I could get MySQL to run, but only with difficulty and MySQL wouldn't launch automatically. After fighting with the permissions for a while, this worked:
myMac > sudo chown -R mysql /Volumes/CaSe/MySQL_data/myDatabase
myMac > sudo chgrp -R wheel /Volumes/CaSe/MySQL_data/myDatabase
myMac > sudo chown -R mysql /Volumes/CaSe/MySQL_data/mysql
myMac > sudo chgrp -R wheel /Volumes/CaSe/MySQL_data/mysql

sudo = "do this as the root user" (you'll need to put in your root password)
chown = "change user (or owner) that can access this"
chgrp = "change group that can access this"
-R = "do this for this folder, and everything in this folder"
the first mysql = "user name is mysql" (this is the mysql server's user name)
the second mysql = "the MySQL database called mysql that is part of the install and stores all the MySQL access info"
myDatabase = "other databases I need to access"

Good luck, and again, any war stories related to this are welcome. It seems like every time I do this it comes out a little different.

No comments: