Building mySQL for OS X v10.0
Mar 29, '01 09:14:13AM
Contributed by: robg
mySQL is a free SQL database program that can work in conjunction with PHP (see PHP hint elsewhere here) to create dynamically generated web sites, such as this one. It's important to me, as I use mySQL and PHP locally to test new elements for this site, and it was getting to be a pain booting back to the Public Beta every time I had to work on something. I tried running the mySQL installer package from the PB, but it failed (not sure why). So I'd been waiting on a new installer package, to make things easy. Last night, I got tired of waiting :-).
I received an email stating that a new binary package was available on the iDisk of 'skribble', so I went and checked it out. Go to www.mac.com, click on the iDisk tab, sign on with your ID, and then enter 'skribble' in the box for "Open Public Folder" section to mount that folder. You'll see the binary for mySQL. I downloaded this and installed it, but couldn't quite get it running - but it may have been user error. It did not install the 'var' directory, where mySQL keeps the databases. You may have better luck than I, so it might be worth a shot.
After a few minutes of mucking around with it (without success), I "rm"ed the mysql directory, and decided to go straight to the source (literally), and grabbed the files from mysql.com to try and build it myself. I was successful, and now have a fully functional PHP 4.04 and mySQL 3.23.36 installation on my OS X machine! Read the rest of the article if you'd like instructions on how to build it yourself -- it's really not that hard!
To build mySQL yourself, you need to have installed Apple's Developer Tools from the CD that came with your OS X purchase. Assuming that you have done this (which I recommend, as there's some cool stuff in there!), and that you have root access, here's how to get mySQL up and running.
WARNING: These instructions create mySQL in the root user/group structure. This is not generally a good idea! mySQL should run as its own user, but not as root. There's a lot of good info on this on the mySQL site, but the basics are you create a new user and group for mySQL, and change the owner of the 'var' directory to the mySQL user, and the group of the 'usr/local/mysql' directory to the mySQL group. I installed it as root, but will do this next step shortly.
- Grab the latest source code distribution from mySQL - you can download it through this link.
- Expand the package using your choice of tools (Expander, the command line, or OpenUp). This will create a folder called mysql-3.23.36. The decompression will take a while, as there are thousands of files.
- Put the folder somewhere easy to work with. I chose the desktop.
- There's a bug in the source code which will prevent mySQL from compiling, so we need to fix that first. I found this bug and fix on the mySQL site, buried here. We need to change one line in one file before it will compile. Open the mySQL folder, and then open the sql folder inside of that. Double-click on the file named mysqld.cc. This will open ProjectBuilder (which I'd never used before). Hit CMD-F (for find), and type "void (*)()" (omit the quote marks!) into the search box, and hit FIND. When the line has been found (it's line 1232, just for reference), change it to read "void (*)(int)". That's it. Save the file and quit.
Now we need to actually make the installation files from the source code. Detailed instructions on all aspects of installation can be found in the Install Chapter of the mySQL documentation. I'll walk through the basic steps here, but you should read the full instructions for all the options and a more detailed explanation of each step. Each command you need to execute is specified inside the parentheses; don't type the parentheses, just type the command!- Open a terminal session, and become root (su).
- Navigate to your mysql-3.23.36 folder (cd /Users/username/Desktop/mysql-3.23.36).
- Create the configuration file (./configure --prefix=/usr/local/mysql). The '--prefix' specifies the install directory, and /usr/local/mysql is the default; you can change it if you wish. This will take about five minutes or so to run.
- Create the make file (make). This will take a long time to run. Go have lunch. Get some coffee. Do some shopping. Come back about 45 minutes to an hour later.
- Install the make file (make install). This takes another five minutes.
- Install the databases (scripts/mysql_install_db).
That's it! You should now have a functional mySQL installation. You can launch it with /usr/local/mysql/bin/safe_mysqld, and you should go create the mySQL root user password and any users you need first thing! Read and understand the mySQL Access Privelege System to make sure you have a secure system.
There are a couple of things you should be aware of. First, as described here, the process runs as root. That's bad. See the above reference for an explanation of why this is a bad thing. Change it. Second, there's a bug that seems to prevent mySQL from shutting down. If you want to turn it off, you need to kill two processes. Type ps -aux | grep "mysql" to get the processID's, and then "kill -9" each of them.
Good luck! It sounds intimidating, but it's not really that hard to compile your own binary, when the source is basically all ready to go.
Comments (15)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20010329091413870