Archive

Archive for the ‘MySql’ Category

Installing MySQLDb for OS/X

December 21, 2009 Leave a comment

We need the MySQLDb for python in order to integrate Django with MySql. Again the installation is very simple and straight forward just as any other python battery. It is available here on the sourceforge. There was no detailed steps and so here u go for newbies…

1. Download the tar file.

2. Untar it.

3. cd to the extracted folder.

4. run python setup.py install

The package will be installed the site-packages of the python. To test the installation start python interpreter and import MySQLDb. Note that you don’t need anything to be configured within the Django for this. It automatically uses this to communicate with MySQL when u say database engine is Mysql in the settings file. At least that is what my understanding is so far…

Installing MySQL from source on Snow Leopard

December 21, 2009 2 comments

Being new to the OS/X world but not unix i want to prepare myself for this installation since i want to build and install from source than from pre-built package. This because i want absolute control on the version of MySQL which i intend to use in many different projects and i don’t want any stupid auto-update mechanisms to screw this up. Having said that it seems to be a fairly easy process still.

Background

I used the following two for reference. So spend time reading it to get a better understanding on steps involved before proceeding. I was successful by combining approach from both the two.

1. http://www.malisphoto.com/tips/mysql-on-os-x.html#Anchor-Download

2. http://hivelogic.com/articles/compiling-mysql-on-snow-leopard/

Pre-installation.

1. First check that your Snow Leopard has the user and group for the mysql. Use the command “dscl . list /users” and “dscl .list /groups” for this. You should see _mysql user and group.

2. I plan to install the mysql under the /usr/local directory. Wondering why? Read this article.

3. Ensure that you’ve XCode installed. If you recently upgraded from Leopard to Snow Leopard make sure that you run XCode install on the CD before you proceed. Remember we need to build from the source and it is possible only with the tools from XCode.

Installation

1. Download the source in tar format from here.

2. It is a best practice to control the unix socket file for mysql and it is preferred to be in /var directory. So create and set permission for socket dir.

 cd /var
sudo mkdir _mysql
sudo chgrp mysql _mysql
sudo chmod 775 _mysql

3. Create src directory under /usr/local/ directory.

mkdir /usr/local/src/

4. cd to the src directory

cd /usr/local/src

5. Extract the source tar downloaded in step 1. Here the assumption tar file is in your downloads folder.

tar xzvf  ~/Downloads/mysql-x.x.xx.tar.gz

6. cd to the extracted source. x below = version you downloaded

cd mysql-x.x.xx dir

7. This is a very important step in configuring the build of mysql. Please pay attention to each options used here. Look here to know more about each configuration option before using it.

./configure --prefix=/usr/local/mysql
--with-extra-charsets=complex
--enable-thread-safe-client
--enable-local-infile
--enable-shared
--with-plugins=innobase
--with-mysqld-user=_mysql
--with-unix-socket-path=/var/mysql/mysql.sock

8. Now it’s time to build

make

9. Now it’s time to install

sudo make install

10. Now that mysql is installed we need the server to be up and running once the system is started. Easy and the standard way to do this OS/X is launchd. Create a file named com.mysql.mysqld.plist under /Library/LaunchDaemons with below content with sudo account permission. Make sure to check path/s.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>com.mysql.mysqld</string>
    <key>Program</key>
    <string>/usr/local/mysql/bin/mysqld_safe</string>
    <key>RunAtLoad</key>
    <true/>
    <key>UserName</key>
    <string>mysql</string>
    <key>WorkingDirectory</key>
    <string>/usr/local/mysql</string>
</dict>
</plist>

11. Next step is to use the launchd to start mysql.

 sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist 

12. If you did not see anything after last command then it is good. Now login to mysql.You should now see the mysql command interpreter.

mysql -u root

13. I don’t really need my MySql to be secured at this point for dev environment. If you do then please take a look at this.

Finally
Stopping MySql

sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist

Starting MySql

sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist

Python on Mac OS/X

December 19, 2009 Leave a comment

I’ve bought my first mac. It’s a macbook pro and i’m working on a project to develop web app using Django. I’ll be capturing my experience of developing python/django app onĀ  Mac OS/X Snow Leopard. Just like our other unix flavors, snow leopard comes with python 2.6 pre-loaded.

No installation required. One less job.

Categories: Django, MySql, OS/X Tags: , , ,
Follow

Get every new post delivered to your Inbox.