Installing and Setting Up MySQL
under Mac OS X

Apache - Perl - MySQL
The Big Picture

Installing and Setting Up MySQL

Installing MySQL Perl DBI:DBD Modules

Testing Apache - Perl - MySQL

These directions describe how to install and setup MySQL under Mac OS X. There are a few pecularities of Mac OS X which require some additional installation steps. This tutorial assumes you are running Mac OS X 10.2 (Jaguar) or later.

1. Open a Terminal Window.

2. Enter the following commands (followed by return on your keyboard): (or just cut from edit box and paste into your Terminal Window)

sudo niutil -create / /groups/mysql_group (you will be prompted to enter your Admin password)

sudo niutil -createprop / /groups/mysql_group gid 401

sudo niutil -create / /users/mysql

sudo niutil -createprop / /users/mysql realname mysql

sudo niutil -createprop / /users/mysql uid 401

sudo niutil -createprop / /users/mysql gid 401

sudo niutil -appendprop / /groups/mysql_group users mysql

sudo niutil -createprop / /users/mysql home /usr/local/mysql


This will create the necessary mysql group and user.

3. Change directory to /usr/local. This is where we are going to download the desired MySQL binary.

cd /usr/local

4. FTP to a site where you can download the latest stable version of MySQL. It is easiest if you download and install a precompiled binary, which is normally available at all mirror sites. To FTP from a command line, pick a server, then connect via the ftp command. Examples:

sudo ftp mirror.sit.wisc.edu

sudo ftp mirror.mcs.anl.gov


Both of the above commands will connect you to a mirror server (University of Wisconsin and Argonne National Laboratory, respectively). You will then need to login anonymously (login: anonymous, password: your email address).

Once logged in you will need to use the "cd" command to change directories.

For Univeristy of Wisconsin:

cd ../mirrors/mysql/Downloads


For Argonne:

cd ./pub/mysql/Downloads

You can then use the "ls" command to list all the files in the directory. Use the copy function to copy the name of the latest MySQL file you want to install (example: mysql-3.23.53-apple-darwin6.1-powerpc.tar.gz) and then paste into the :get" command, example:

get mysql-3.23.53-apple-darwin6.1-powerpc.tar.gz

You should see the ftp process begin. Once completed, click "control-D:" to terminate the FTP session and return to the command prompt.

Type "ls" to see that the archive was indeed downloaded to your /usr/local directory.

5. You must now gunzip the downloaded package then untar it. Example:

sudo gunzip mysql-3.23.53-apple-darwin6.1-powerpc.tar.gz

sudo tar -xvf mysql-3.23.53-apple-darwin6.1-powerpc.tar

6. create a symbolic link:

sudo ln -s mysql-3.23.53-apple-darwin6.1-powerpc mysql

7. Create the MySQL tables by running the mysql_install_db script:

sudo /usr/local/mysql/scripts/mysql_install_db

8. Change the ownership of directories and groups:

sudo chown -R root /usr/local/mysql

sudo chown -R mysql /usr/local/mysql/data

sudo chgrp -R mysql_group /usr/local/mysql

sudo chown -R root /usr/local/mysql/bin

9. Move into the mysql directory:

cd mysql

10. Start the MySQL daemon with:

sudo /usr/local/mysql/bin/safe_mysqld --user=mysql &

11. Add the /usr/local/mysql/bin path to your default shell PATH variables:

echo 'setenv PATH /usr/local/mysql/bin:$PATH' >> ~/.tcshrc

Now close this Terminal window, and open a new one. This will invoke the newly set PATH in your shell. This way you can directly enter mysqladmin commands without having to type the entire path.

12. See that the mysql daemon is running and your path variable is correctly set by entering:

mysqladmin version

You should see the server version displayed with additional details.

13. Set root password for MySQL:

mysqladmin -u root password new_password
[where new_password is a password of your choosing]

Should you need to change the root password at some later time, use:

mysqladmin -u root -p password new_password

You will be prompted to enter the existing (old) MySQL root password.

14. Finally, if you wish to have the MySQL daemon start automatically upon restart, you should enter the following commands:

cd /Library/StartupItems/

sudo cp -R /System/Library/StartupItems/Sendmail ./

sudo mv Sendmail MySQL

cd MySQL

sudo rm Sendmail

sudo ed

a

#!/bin/sh

. /etc/rc.common

ConsoleMessage "Starting MySQL"

cd /usr/local/mysql

/usr/local/mysql/bin/safe_mysqld --user=mysql &

.

w MySQL
[you should see the number of characters written]

q
[quits the editor and returns to shell prompt]

sudo chmod gu+x MySQL

cd Resources

cd English.lproj

sudo ed Loc*

1,$ s/mail services/MySQL Server/p

w

q
[quits the editor and returns to shell prompt]

[you should also do these changes to any other language resources you need]

cd /Library/StartupItems/MySQL

sudo ed Startup*

1,$d

a

{

Description = "MySQL Server";

Provides = ("MySQL Server");

Requires = ("Resolver");

Uses = ("Network Time", "NFS");

OrderPreference = "Last";

Messages =

{

start = "Starting MySQL Server";

stop = "Stopping MySQL Server";

};

}

.

w

q
[quits editor and returns to shell prompt]

At this time you should restart your machine to see that the mysql daemon has automatically restarted and that you can connect to it using the mysqladmin version command (through a Terminal window).