Installing and Running MySQL on Mac OS X

With newer versions of MySQL, it is becoming quite easy to install MySQL on Mac OS X, especially if you are using OS X 10.4 (Tiger) or 10.5 (Leopard).

The first step is to download the MySQL server. You can download the MySQL Community Server for free from dev.mysql.com. Typically there are several versions of the Community Server available, including the latest stable release, the lastest release candidate, and the latest Alpha or Beta release. In this example, we are going to proceed assuming the 5.1 version of Community Server.

Version 5.1 can be downloaded from this URL: http://dev.mysql.com/downloads/mysql/5.1.html

If using OS X Tiger or Leopard, you want to select the Mac OS X Package format as the download format, and then select the appropriate link based on your version of OS X.

This will download a .dmg file (Disk Image) to your machine. Double-clicking the disk image will show a window containing a mysql-<version>*.pkg file. Double-clicking this .pkg file will launch the installer that will install MySQL on your system. If you would like for MySQL to start each time your system starts, you can also launch the MySQLStartupItem.pkg file contained in the disk image.

The installer installs MySQL in the /usr/local/mysql-version directory. It also creates a symboilic link in the /usr/local directory called mysql.

To manually start MySQL, you can launch the Terminal application found in Applications/Utilities/Terminal. Once the terminal window appears, you can type the following:

cd /usr/local/mysql

Then type the following:

sudo ./bin/mysqld_safe

Enter your password when prompted. At this point, MySQL should be running on your localhost (127.0.0.1) on port 3306.

Now you can launch RazorSQL to create users for your MySQL instance. The Mac mysql installation includes by default a user named root with no password. You can use this account to connect to MySQL using RazorSQL.

To get connected with RazorSQL, select Connections -> Add Connection Profile, select MySQL from the database type list, and select the Auto Download Driver button to get the MySQL driver. Enter root for the login, nothing for the password, 127.0.0.1 or localhost for the host, and mysql for the database name.

After connecting, you can create a new user using the DB Tools -> Create -> Create User option. If you want the user to be able to access your MySQL instance from other machines, make sure to select the check the "All Domains" option, or else click the "Select Domains" button to add specific ip addresses / hosts.

The create user tool should generate SQL similar to the following:

GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'localhost' IDENTIFIED BY 'testpass' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'%' IDENTIFIED BY 'testpass' WITH GRANT OPTION;