How to install MySQL and Rails on Osx Snow Leopard

Hello everyone. These days I've bought a MacBook Pro with Osx Snow Leopard 64-bit pre installed. Having to develop mainly in Rails and Django on MySQL and PostgreSQL, I've found some difficulties to install and properly configure all packages. The main problems were due to the presence of 32bit libraries and other at 64bit. For example, Python or Ruby (already installed by default) were compiled at 32bit. Everything seems to work best, however, until you try to install the gem "mysql" or the eggs "psycopg2" or "MySQL_python". These database drivers, having to be "compiled", generate many problems of incompatibility between different architectures. In this first tutorial, we'll see how to install MySQL and Rails 3.0. In the next we'll see how to proceed with Django and PostgreSQL. The approaches taken by me are simply the result of googling and other online tutorials. So I'll link every resource I've used. Regarding the installation of MySQL, I've mainly followed the "Hivelogic":http://hivelogic.com/articles/compiling-mysql-on-snow-leopard tutorial. See below the key points that allowed a successful installation. h1. Step 1: Set the $PATH environment variable Open a terminal and set the $PATH environment variable in order to link the correct folders in /usr/local/

mate ~/.profile
Add, if it does not exist, this line at the bottom of the .profile file:

export PATH="~/bin;/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
and reload the $PATH in this way:

source ~/.profile
To verify that our $PATH contains the paths set above, type the following command:

echo $PATH
h1. Step 2: Download MySQL Create a new folder to download the sources and compile them:

mkdir ~/src
cd ~/src
Download the latest version available at the time of writing this tutorial:

curl -O http://mysql.mirrors.pair.com/Downloads/MySQL-5.1/mysql-5.1.47.tar.gz
h1. Step 3: Compile and Install Build and install MySQL with the following commands:

tar xzvf mysql-5.1.47.tar.gz
cd mysql-5.1.47
./configure --prefix=/usr/local/mysql --with-extra-charsets=complex \
--enable-thread-safe-client --enable-local-infile --enable-shared \
--with-plugins=innobase
 
make
sudo make install
At this point we create a mysql user and a default database.

cd /usr/local/mysql
sudo ./bin/mysql_install_db --user=mysql
sudo chown -R mysql ./var
cd ..
Then we can create scripts to start and stop the MySQL server using the command line. We create a bin folder in our home and the following file, also giving execute permissions:

mkdir bin
touch mysqlscript
chmod +x mysqlscript
Edit the file you've just created by inserting the following body:

#!/bin/bash
start()
{
echo -n "Starting MysSQL server"
cd /usr/local/mysql ; sudo /usr/local/mysql/bin/mysqld_safe
return
}

stop()
{
echo -n "Stopping MySQL server"
cd /usr/local/mysql ; sudo /usr/local/mysql/bin/mysqladmin -u root -p shutdown
return
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: {start|stop|restart}"
exit 1
;;
esac
exit $?
At this point you can start the server by typing "mysqlsript start" in the console. To stop the server just type "mysqlscript stop". We are now able to install Ruby on Rails. As mentioned at the beginning of the article, system Ruby is compiled at 32bit. If you want to compile from source at 64bit and place it in /usr/local/ ruby just follow this "tutorial":http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard. Since it is my intention to use instead "rvm":http://rvm.beginrescueend.com/, I'll settle for a system level Ruby at 32bit and I prefer to compile every new virtual environment at 64bit (from this "tutorial":http://amerine.net/2010/02/24/rvm-rails3-ruby-1-9-2-setup.html) Therefore proceed as follows: h1. Step 1: Install rvm Launch in a console this command and follow the instructions:

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
h2. Step 2: Install Ruby 1.9.2 Type the following commands and verify that you have version 1.9.2 installed.

rvm install 1.9.2 -C --with-readline-dir=/opt/local,--build=x86_64-apple-darwin10
rvm 1.9.2
ruby -v
h1. Step 3: Create a Rails3 gemset Create a Rails3 gemset and activate it as default:

rvm use --create 1.9.2@rails3
rvm 1.9.2@rails3 --default
h1. Step 4: Install Rails3 and database drivers for SQLite and MySQL

gem install sqlite3-ruby
env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
gem install rails
In this tutorial we've then installed MySQL and Ruby 1.9.2 from source. Now that all the packages have been compiled to 64bit we should not find errors while installing other application's gems. Learn more strategies in internet marketing that will boost your business.