As part of the Ruby and Rails course that I talked about in my earlier post, I needed to install MySQL on my MacBook Pro. I also needed to “register” this MySQL installation in Netbeans so that it is relatively easy to start/stop the database and to create tables using the Netbeans interface.
I initially downloaded the Mac OS X package installer for MySQL 5.1 provided by MySQL. However, this installs MySQL in the /usr/local directory and requires a user with administrator privileges to administer the server. I got sick of running sudo for all my commands and decided that, at least while I was learning things, I would install a private copy of MySQL – something that would under my home directory and would not require any administrator privileges to administer.
Thankfully, the folks at MySQL have a tarball that does just that. You merely untar the distribution in the directory of your choice, run the scripts to set up the initial data directory and off you go… or so I thought. Here are some of the things I had to do to get my “private” MySQL installation working.
-
Download MySQL:
This is easy – just go to http://dev.mysql.com/downloads/mysql/5.1.html#macosx. I chose the version for Mac OS X 10.5 x86_64. Click on the link that says “Select a Mirror” and off you go.
-
Extract the tar file
Again an easy step – merely untar the file in a directory of your choice (I’m going to call it $MYSQL_HOME from now on).
-
Run the Installation Script
$ cd $MYSQL_HOME
$ ./scripts/mysql_install_dbYou’ll notice that the script has now created a directory called “data” under $MYSQL_HOME and within that directory are two subdirectories called “mysql” and “test”.
-
Create the configuration file
Create a file in your home directory called ” .my.cnf” with the following contents:
[mysqld]
basedir=$MYSQL_HOME
user=<your username>
Remember to replace $MYSQL_HOME with the absolute path to the mysql directory from step 2 above. Also, replace <your username> with your login username.
-
Start the server
$ cd $MYSQL_HOME
$ bin/mysqld_safe &
-
Stop the server
$ cd $MYSQL_HOME
$ bin/mysqladmin -u root shutdown
That’s all I have for now. In my next installment I’ll talk about how to “register” MySQL with Netbeans. While you’re waiting for the next installment, you might want to download the latest Netbeans IDE – the latest at the time of writing this blog is Netbeans v6.8.
I prefer to always get the “All” bundle which is a chunky 200+MB download. So, go start the download and get some coffee.
