MySQL on Leopard for rails

SQLite is a great little tool and very easy to use and setup… gem install sqlite3-ruby and you are done!! But now I’m creating a rails application that needs foreign keys and that’s something that SQLite does not do. So MySQL it is…(I’m a MySQL guy if you haven’t figured)
My choice to install MySQL on the macbook was using macports… I’ll assume that macports is installed correctly for the next exercises…  (port version should give you the version number)
Installing MySQL 5.0 with port:
sudo port install mysql5 +server
When the installation is done you have to create the run directory
sudo mkdir /opt/local/var/run
sudo mkdir /opt/local/var/run/mysql5
cd /opt/local/var/run
sudo chown _mysql mysql5
ls -al
total 0
drwxr-xr-x  4 _mysql  admin   136B Mar 12 10:37 mysql5/
setup the config file for MySql. (use the template so you can see where Mysql puts stuff)
sudo /opt/local/share/mysql5/mysql/my-small.cnf /opt/local/etc/mysql5/my.cnf
Testing if MySQL Starts…
sudo /opt/local/lib/mysql5/bin/mysqld_safe5
(you will need crtl-Z and then type bg. This will put the MySQL process in the background. type jobs to see the process)
now connect to mysql with the client
mysql5 -uroot
If you want to stop MySQL you have to kill the process. ps -ax | grep mysqld… there should be one mysqld and one mysqld_sfae5 process get BOTH pids and run kill pid pid.
ps -ax | grep mysqld 70170   ??  S      0:00.01 /bin/sh /opt/local/lib/mysql5/bin/mysqld_safe –datadir=/opt/local/var/db/mysql5 –pid-file=/opt/local/var/db/mysql5/new-host-2.home.pid
70195   ??  S      0:01.22 /opt/local/libexec/mysqld –basedir=/opt/local –datadir=/opt/local/var/db/mysql5 –user=mysql –pid-file=/opt/local/var/db/mysql5/new-host-2.home.pid –port=3306 –socket=/opt/local/var/run/mysql5/mysqld.sock kill  70170 70195
If you only kill one the server will auto restart!!
Running MySQL using MySQL launchctl
This is where I need more help BUT this is what I did and it works:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist  
PS(make sure you kill mysqld_safe5 before doing this…)
Now the part I don’t udnerstand… the server just started but I don’t know how to CONTROL the server like stop, start and restart???
sudo launchctl stop org.macports.mysql5

This did “restart” MySQL but using start/restart did nothing. Looks like when you stop MySQL it aut restart from lunched. 

Password for MySQL root user?
mysqladmin5 -u password ‘secret-password’
connecting with password
mysql5 -uroot -p
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: