Gathan Beaga

Installing MySQL on MacOSX

In order to better understand the two blogging (Movable Type and TextPattern) systems I have running, I decided to install them locally on my iBook. But first, I needed an installation of MySQL. This turned out to be the most difficult part of the whole process, and the instructions that follow are the distilled experience of a weekend of banging my head against the problem.

I have no idea if these are in fact correct, but they seem to have worked for me. YMMV.

  • Run the installer.
    If you’ve attempted to install this before, you may need to go to /Library/Receipts and clear out the folder there for the previous installation, as well as deleting the obvious folders at /usr/local. (You may need to use sudo rm for this – be careful!)
    If you have existing data that you don’t want to lose, try Marc Liyanage’s site for help.
  • Open the Terminal
    [iBook:~] alan% cd /usr/local/mysql
    This changes your working directory to the same directory that MySQL lives in.
  • [iBook:/usr/local/mysql] alan% sudo chown -R mysql data/
    Not 100% sure what this does – I found this line in two sources – Marc Liyanage’s site and the MacDevCentre article on how to set up MySQL. I think it might be changing the ownership of the directory to the MySQL user.
  • [iBook:/usr/local/mysql] alan% sudo ./bin/mysqld_safe
    (Press CTRL+Z)
    (Press CTRL+D to exit the shell)
  • [iBook:/usr/local/mysql] alan% bg
    These four commands start the database and put it into the background. Again, have a look at Marc Liyanage’s site for a startup item that will do this for you on startup.
  • [iBook:/usr/local/mysql] alan% /usr/local/mysql/bin/mysqladmin -u root password _newpassword_
    This sets the password of the root user of the database (a different password to the root user of the system, if there is one). If you don’t set this, anyone could connect to your database.
  • [iBook:/usr/local/mysql] alan% /usr/local/mysql/bin/mysqladmin -u root -p -h localhost password _newpassword_
    This is another password setting exercise – I’m not sure exactly what it does but it’s listed in the readme.txt file that came with the MySQL download.
  • [iBook:/usr/local/mysql] alan% ./bin/mysql -uroot -p
    Here we are telling the MySQL command line client (which lives in the /bin directory inside the main MySQL directory)that we want to login as the application’s root user (-uroot) and that we will supply a password (-p)
    You will be prompted for the root password that you just set up.
  • mysql> create database _newdatabase_;
    Note that the command prompt has changed.
    Here we tell MySQL that we want to create a new database. Database names can contain only letters and numbers. No special characters, with the exception of the underscore. MySQL commands mostly have to end with a semicolon.
  • mysql> grant all on <em>newdatabase</em>.* to <em>username</em>@localhost identified by <em>'userpassword'</em>;
    Remember to put the single quotes around the password. This command assigns privileges to a user of name username who is connecting from the localhost (i.e., your Mac), using the password userpassword. The dot-star after newdatabase is extending the privileges to all tables of the database.
  • mysql> quit;
    This ends your session in the MySQL client application.

Other resources on this subject (I always find the more the better – it may be confusing, but somewhere in the mass of information must be the right path™…):

  • The wonderful series of articles on setting up Apache, PHP and MySQL at O’Reilly’s MacDevCentre are indispensable.
  • There’s quite a good tutorial at Suckeffect which takes up where the MacDevCentre articles left off with some specific instructions for setting up Apache to work with Movable Type. In order to get this to work I did have to make one further change to the httpd.conf file. Where the author talks about adding some extra text to the ScriptAlias section in the httpd.conf file, he specifies a line “Options None”. Once I changed this to “Options ExecCGI” I got mt-load.cgi to work. I’m not 100% sure why it was necessary, but after a lot of intensive web searching it seemed the thing to try.
  • There’s another article on running Movable Type on OSX here.

Update (26 June 2003): There are alternate binaries of MySQL (and a number of other MacOSX Unix tools) available at Server Logistics. These seem to come with a full installation guide, which may prove useful if the above instructions fail!