Monthly Archives: January 2008

MacBookAir – a Real Thinnoavation …

This month apple has launched its 3rd model of the MacBook Generation, the MacBookAir, after MacBookPro and MacBook.

The size and thickness of this new model makes you speechless, it is unbelievable how can they ship all this technology features, in this envelope thin device, really impressive.

i will leave you now with the Ad and steve job presentation about the product.

Add Samba printers in Leopard

Putting together a couple of other web resources, here is a step-by-step guide to adding Samba printers in Leopard. Our Windows print server is on a different subnet from many of our users, so the printers don’t show up automatically. This method also passes user credentials to the print server. Next step: to automate this process so that we can add multiple printers in one step.

1. Open System Preferences -> Print & Fax.

system preferences

2. Select to add a new printer.

add

3. The first time you do this, add the Advanced button to the add printer toolbar. Ctrl-click on the toolbar, select “Customize Toolbar…”, and then drag the Advanced button onto the toolbar.

toolbar

advanced

4. Select Advanced then specify the following printer settings.

Type: Windows

Device: Another Device

URL: smb://username:password@domain/printserver/printername, where username is your network username, password is your password, domain is your Windows domain, printserver is the name of your print server, and printername is the name of the printer share.

Name: the printer name

Location (optional): the physical location of the printer, e.g. “Vollum common space”

Print Using: Select a driver to use -> search for the correct model.

Select the Add button to save this printer. If prompted, select Duplexing. That should do it!

details

One of my applications got mentioned in Al-Ahram Newspaper

Scanned News

It was in the newspaper today, they mentioned the application i have done for the MenaTravelAwards, the annual awards feast that is held in Dubai every year, i developed this application last year in the company i work for “CHA” under the supervision of the well known auditing company “PriceWaterHouseCooper” the same company that audit the Oscars,

the application was used by around 100,000 voter last year, and it was such a great experience, i automated all the process of voting, and auditing, and no cheats are allowed at all due to the strong policies i applied 😉

Need someone badly ?

how many times we wanted to get someone’s friendship, love or even their persistence in our life, and worked hard to get it, and we were ready to do anything to win this, phone calls, mails, greetings, presents and doing favors for him.

and once we have him in our life, he just becomes a daily routine, and we forget how hard we worked for this sort of relationship and how badly we needed that person in our life, now imagine his feeling when he felt really needed and wanted by you, and now he became just someone in your life.

what i am saying to me and everyone of us, look around you, look for everyone you know, and you needed him badly, and you fought hard to get him, can you afford to lose him ? don’t you know that if you did it will take you doubled effort to get him back, and it might not even work again.

now list all of those around you and make them feel needed again, cause they are worth that, or you wouldn’t have fought for them at the first place, and it doesn’t take more than an sms or a card or even a phone call to make it.

isn’t it the time to stop losing people….

Mail System @ Office is back 2 life again.

Recently we had this problem in the company, our mails doesn’t reach some of the recipients,

after analyzing the situation, i discovered that we have 2 problems :

1- Our forward and reverse DNS doesn’t match

check the error from DnsStuff.com when i test the reverse DNS on our mail server :

Location: Egypt (high) [City: Cairo, Al Qahirah]Preparation:The  reverse DNS entry for an IP is found by reversing the IP, adding it to "in-addr.arpa", and looking up the PTR record.So, the reverse DNS entry for 217.52.xx.xxx is found by looking up the PTR record forxxx.xx.52.217.in-addr.arpa.

All DNS requests start by asking the root servers, and they let us know what to do next.

See How Reverse DNS Lookups Work for more information.

How I am searching:

Asking g.root-servers.net for xxx.xx.52.217.in-addr.arpa PTR record:

g.root-servers.net says to go to sec1.apnic.net. (zone: 217.in-addr.arpa.)

Asking sec1.apnic.net. for xxx.xx.52.217.in-addr.arpa PTR record:

sec1.apnic.net [202.12.xx.xx] says to go to ns2.xxxx-online.net. (zone: 52.217.in-addr.arpa.)

Asking ns2.nile-online.net. for xxx.xx.52.217.in-addr.arpa PTR record:  Reports mail.xxx-xxxxxxxxxxxxx.com. [from 62.140.73.2]

Answer:

217.52.xx.xxx PTR record: mail.xxx-xxxxxxxxxxxxx.com. [TTL 86400s] [A=CNAME] *ERROR* A record for mail.xxx-xxxxxxxxxxxxx.com. does not point back to original IP.  RFC1912 2.1 disallows CNAMEs.

To see the reverse DNS traversal, to make sure that all DNS servers are reporting the correct results, you can Click Here.

2- We don’t have any reference for the server in the office that we use to send direct emails in the MX Records of our domain, which makes some server doesn’t trust our emails.

Check the headers of emails from gmail when we had the problem :

Received-SPF: neutral (google.com: 217.52.xx.xxx is neither permitted nor denied by best guess record for domain of ahmed@xxx-xxxxxxxxxxxx.com) client-ip=217.52.xx.xxx;Authentication-Results: mx.google.com; spf=neutral (google.com: 217.52.xx.xxx is neither permitted nor denied by best guess record for domain of ahmed@xxx-xxxxxxxxxxxx.com) smtp.mail=ahmed@xxx-xxxxxxxxxxxx.com

I solved the 2 problems by following the next steps:

1- Created A record mailer1.xxx-xxxxxxxxxxxx.com to point to our mail server IP 217.52.xx.xxx

2- Created MX record for the A record previously created.

3- Contacted our ISP to change the reverse DNS / PTR to reply with mailer1.xxx-xxxxxxxxxxxx.com for any reverse lookup.

Now after 24 hours everything seems working perfectly,

check the reverse lockup results from DnsStuff.com :

Location: Egypt (high) [City: Cairo, Al Qahirah]

Preparation:
The  reverse DNS entry for an IP is found by reversing the IP, adding it to "in-addr.arpa", and looking up the PTR record.
So, the reverse DNS entry for 217.52.xx.xxx is found by looking up the PTR record for
 xxx.xx.52.217.in-addr.arpa.
All DNS requests start by asking the root servers, and they let us know what to do next.
See How Reverse DNS Lookups Work for more information.

How I am searching:
Asking i.root-servers.net for xxx.xx.52.217.in-addr.arpa PTR record:
       i.root-servers.net says to go to ns3.nic.fr. (zone: 217.in-addr.arpa.)
Asking ns3.nic.fr. for xxx.xx.52.217.in-addr.arpa PTR record:
       ns3.nic.fr [192.134.x.xx] says to go to ns2.nile-online.net. (zone: 52.217.in-addr.arpa.)
Asking ns2.nile-online.net. for xxx.xx.52.217.in-addr.arpa PTR record:  Reports mailer1.xxx-xxxxxxxxxxxx.com. [from 62.140.xx.x]

Answer:
217.52.31.189 PTR record: mailer1.cha-international.com. [TTL 86400s] [A=217.52.xx.xxx]

and the headers of our emails from gmail.

Received-SPF: pass (google.com: best guess record for domain of ahmed@xxx-xxxxxxxxxxxx.com designates 217.52.xx.xxx as permitted sender) client-ip=217.52.xx.xxx;
Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of ahmed@xxx-xxxxxxxxxxxx.com designates 217.52.xx.xxx as permitted sender) smtp.mail=ahmed@xxx-xxxxxxxxxxxx.com

I hope this would be useful for you as it was for me, have a nice mail 😉

Action Event Handling in JAVA

Throughout AWT, and all Java APIs for that matter, event handling has been consistent:

  1. Implement a listener interface (such as java.awt.event.ActionListener)
  2. Provide an implementation of all listener interface methods (such as actionPerformed( ActionEvent e ))
  3. Add your class as a listener to a component, which generates events by calling its addXXXListener() method (such as calling javax.swing.JButton‘s addActionListener() method)

i will go through 3 methods to perform Action Event Handling in Java

First method:

1- create a Handler Class in a separate file that implements from ActionListener interface.

2- overwrite the abstract method actionPerformed of the ActionListener interface, with the code we want to be executed upon the action on our object.

3- create instance of the Handler class, and add it as an action listener on the object we want like button for example.

Example :

in the following example we will create a button from the swing library, and apply the action that when a user click the button, we will show a message dialog.

File Handler.class

import java.awt.event.*;import java.awt.*;

import javax.swing.*;/**

*

* @author ahmedabdelaliem

*/

//we create the Handler class and implement from ActionListener interface

public class Handler implements ActionListener{

//now we overwrite the abstract method of ActionListener interface

public void actionPerformed (ActionEvent event){

// here goes the code we want to execute when the action happen, for example show a message dialog with the below text

JOptionPane.showMessageDialog(null, "You Have just clicked the button");

}

}

file ButtonTest.java

/** *

* @author ahmedabdelaliem

*/

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

import java.awt.*;

import javax.swing.*;// we create our class and inherit from JFrame to create our GUI

public class ButtonTest extends JFrame{

// we create an empty reference with JButton type

private JButton plainButton,;

// we create the constructor of the class

public ButtonTest(){

//set up the container

Container con = getContentPane();

con.setLayout(new FlowLayout());

// create an object of the JButton

plainButton = new JButton();

plainButton.setText("Regular Button"); // set the text on the button

//create an object of our Handler

Handler h = new Handler();

// now we add the Handler object we created as Action Listener for the button

plainButton.addActionListener(h);

//now we add the button to the container and show the frame.

con.add(plainButton);

setSize(400,300);

setVisible(true);

}

}

file Main.java

/** *

* @author ahmedabdelaliem

*/

public class Main {

public static void main(String[] args) {

// we create an object of our ButtonTest Class

ButtonTest b1 = new ButtonTest();

b1.setDefaultCloseOperation(b1.EXIT_ON_CLOSE);    }

}

now the output of this simple application : a frame will show with a button on it, and when we click the button a message dialog will appear.

the disadvantage of this method is that we need to create a separate handler for each object we want a handler for,

for example if we have a form with 10 buttons with different actions when clicked, then we need to create 10 Handlers in 10 files with 10 different actions

that doesn’t make sense at all.

so this is why we follow one of the next 2 methods,

Method 2 : create the Handler class as inner class of our class to handle the actions on the components in our class

Example :

File : CheckButtonTest.java

import javax.swing.*;import java.awt.*;

import java.awt.event.*;

/**

*

* @author ahmedabdelaliem

*/

public class CheckBoxTest extends JFrame{

JCheckBox b1,b2; // we create 2 referneces with JCheckBox type

JTextField t1; // we create 1 reference with JTextField type    // we create the constructor of the class

public CheckBoxTest() {

//we call the constructor of our super class and give it the title of the frame

super ("Check Box Test");

//now we setup the container

Container con = getContentPane();

con.setLayout(new FlowLayout());

// we create the text field object with pre entered text

t1 = new JTextField("This is the test text");

// we set the font for the text field

t1.setFont( new Font("serif", Font.PLAIN, 14));

// now we add the text box to the container

con.add(t1);

// we create object for the checkbox and give it Bold value

b1 = new JCheckBox("Bold");

//we add the checkbox to the container

con.add(b1);

// we create another object for the second box and give it italic value

b2 = new JCheckBox("Italic");

// we add the checkbox to the container

con.add(b2);

// now we create the handler object

Handler h = new Handler();

// we add the handler as item listener for the 2 checkboxes

b1.addItemListener(h);

b2.addItemListener(h);

// now we view the frame

setSize(400,300);

setVisible(true);

}

// here we create the handler class   as inner class

private class Handler implements ItemListener{

private int bold = Font.PLAIN; // we setup initial values for the bold, italic variables

private int italic = Font.PLAIN;

// we overwrite the abstract method of the ItemListener interface

public void itemStateChanged(ItemEvent event){

if (event.getSource() == b1){ // here we check which checkbox is checked

if (event.getStateChange() == event.SELECTED){ // here we check if it is selected or the selection is removed

bold = Font.BOLD; // if conditions apply, we set the bold variable as BOLD

//t1.set;

}else{

bold = Font.PLAIN;

}

}else if (event.getSource() == b2){

if (event.getStateChange() == event.SELECTED){

italic = Font.ITALIC;

}else{

italic = Font.PLAIN;

}

}

// here we add the 2 variables and apply the format to our font

t1.setFont(new Font("Serif", bold + italic, 14));

}

}

}

File : Main.java

/**

 *

 * @author ahmedabdelaliem

 */

public class Main {    /**

     * @param args the command line arguments

     */

        // TODO code application logic here

        public static void main(String[] args) {

        // TODO code application logic here

       CheckBoxTest checkBox = new CheckBoxTest();

       checkBox.setDefaultCloseOperation(CheckBoxTest.EXIT_ON_CLOSE);

    }

}

This method is better than the first one, cause it allow us to create one handler for many objects and the handler can reach and compare the variables of our main class.

The third method is to create an instance of

How to highlight code in wordpress posts

well, to highlight the code in your posts in wordpress, you need to download the plugin

http://wordpress.org/extend/plugins/wp-syntax/

after you install it as in the instructions,

go to the admin panel then plugins, and activate the plugin, then go to Presentation -> Theme Editor , then choose from the menu on the right “Stylesheet” this will allow you to edit the file Style.css of your theme,

paste the following code in the end of it

pre {  font-family: Monaco, "Courier New", Courier, monospace;

font-size: 10px;

}.wp_syntax {

color: #100;

background-color: #f9f9f9;

border: 1px solid silver;

margin: 0 0 1.5em 0;

overflow: auto;

}

/* IE FIX */

.wp_syntax {

overflow-x: auto;

overflow-y: hidden;

padding-bottom: expression(this.scrollWidth > this.offsetWidth ? 15 : 0);

width: 100%;

}

.wp_syntax table {

border-collapse: collapse;

}

.wp_syntax div, .wp_syntax td {

vertical-align: top;

padding: 2px 4px;

}

.wp_syntax .line_numbers {

text-align: right;

background-color: #def;

color: gray;

overflow: visible;

}

/* potential overrides for other styles */

.wp_syntax pre {

margin: 0;

width: auto;

float: none;

clear: none;

overflow: visible;

}

then save the file, and whenever you want to write a code; write it as follow

<pre line=”1″ lang=”java”>
your code here</pre>

where java is the attribute of the code language

here is the full lists of attributes supported by this language

abap, actionscript, ada, apache, applescript, asm, asp, autoit, bash, blitzbasic, bnf, c, c_mac, caddcl, cadlisp, cfdg, cfm, cpp-qt, cpp, csharp, css, d, delphi, diff, div, dos, dot, eiffel, fortran, freebasic, genero, gml, groovy, haskell, html4strict, idl, ini, inno, io, java, java5, javascript, latex, lisp, lua, m68k, matlab, mirc, mpasm, mysql, nsis, objc, ocaml-brief, ocaml, oobas, oracle8, pascal, per, perl, php-brief, php, plsql, python, qbasic, rails, reg, robots, ruby, sas, scheme, sdlbasic, smalltalk, smarty, sql, tcl, text, thinbasic, tsql, vb, vbnet, vhdl, visualfoxpro, winbatch, xml, xpp, z80

and enjoy the colors 😉

How to Disable “Enter” action to submit a form

this is how to disable the Enter action on submitting a form, and forcing the user to click submit button

Fix the MySQL PHP issue in Leopard (mysql.sock file)

This is a known issue in Leopard, basically the system is looking for the mysql.sock file in the wrong place. Just need to create a symlink and you should be in business:

sudo mkdir /var/mysql/
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Installing MySQL on Mac OS X (Tested on Leopard)

Found it very useful, hope you will too

What follows are instructions for building and installing MySQL 5 on Mac OS X. These instructions should work perfectly on both Tiger and Leopard.

If you’re a pro at this type of thing already, if you’re impatient, or just feeling lucky, you can download the basic install steps as a shell script and give that a go. Just make sure you’ve installed Xcode and set your path correctly (if that doesn’t make sense, you should keep reading).

Why You Might Want to Build MySQL Yourself

So why would you want to compile your own version of MySQL when the MySQL team releases a Mac OS X build that you can download and install in one step? There are a few reasons:

  1. As of today (2007-11-09) there isn’t a MySQL package-installer for Leopard, and the Tiger one has a few issues
  2. You’ll have a stand-alone, easy-to-update version of MySQL that you control and understand
  3. When a new version of MySQL comes out, you won’t have to wait for the MySQL team to release a package for Mac OS X (or for your version of Mac OS X) … just download the latest source and follow the steps – they never change
  4. You can easily uninstall MySQL yourself at any time
  5. Compiling software yourself lets you learn how Mac OS X and the software you use really work behind the scenes

But … there are some downsides, too:

  1. You won’t get a Preference Pane to start/stop MySQL (unless Mantorg agrees to build us one. Idea: email him and tell him you want him to)
  2. It takes about 20 minutes to build and install

In the end, compiling and installing MySQL this way is well worth the effort, as the end result delivers an easy-to-upgrade, system-independent, stand-alone development platform that is impervious to potential problems that can be caused by system updates, operating system upgrades, etc.

By rolling our own from source this way, we also have full control over our environment. We know what’s installed and where, what version we’ve used, where it came from, and there’s no dependence on an external ports system and the breakage or issues that come from relying on others to manage our software.

These issues and additional background information about why one might roll their own tools in this fashion are detailed in the article, Using /usr/local/, which could be considered a prerequisite for this task.

A Quick Warning

While it’s unlikely anything we do here might do any kind of damage to the system, it’s good advice to have a current backup of everything, just in case. I don’t take any responsibility for anything that results from following these instructions. You’re following these instructions at your own risk.

Prerequisites

You’ll need to install Xcode. Xcode can be found in the Optional Installs folder of the installation DVD. You can also download the latest version from Apple by getting a (free) membership from the Apple Developer Connection.

Just double click the Xcode installer package, take the defaults, and you’ll be ready to roll.

A Note About Existing MySQL Installations

If you already have MySQL installed and used the package installer from MySQL to install it, you need to remove a single file (actually a symlink) to disable it:

sudo rm /usr/local/mysql

If you also installed the StartupItem package, you’ll want to remove it as well. Keep in mind that if you ever want to auto-start the old version of MySQL later on, you’ll need to re-download the package installer and reinstall the StartupItem.

sudo rm -rf /Library/StartupItems/MySQLCOM/

Exporting or migrating your old data isn’t difficult, but it is beyond the scope of this article. I may write something up to handle this in a subsequent article if it’s something people want.

Terminal

We’re going to be typing archaic commands into a window using a monospaced font, just like in a movie! And if things go well, later, your life-sized avatar will learn kung-fu.

Open the Terminal application. It can be found in the

/Applications/Utilities

folder.

Each of the lines below appearing in monospaced type should be entered into Terminal, and be followed by the Return key. But you knew that already.

Setting the Path

Do not skip this step! Most everything else will fail if you do.

Mac OS X, like other UNIX systems, uses something called a path to determine where it should look for applications on the command line (that is, when you’re using the Terminal app). The path is actually an environment variable, set by a special file that’s automatically executed when you open a new Terminal window.

To see if the path has been set properly, we can check the contents of the

.bash_login

file (the special file hidden in our home folder) for a

PATH

line using a text editor. TextMate, TextWrangler, BBEdit, and vi are all perfectly good options. To open the file with TextMate, for example, we can type:

mate ~/.bash_login

This will open the file if it already exists, or open a blank file if it doesn’t. Add the following line at the very end of the file:

export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

Now save and close the file.

It doesn’t matter how many other lines there are in the file, or what they say or do. Just make sure that this line comes last and you should be fine.

To make sure the changes are picked up correctly, we now need to execute the file with the following command:

. ~/.bash_login

It’s likely there will be no response from the shell here, just the prompt, but that’s OK, the changes have been picked up and we’re ready to move on.

You can also close your Terminal and open a new one instead if you’d like.

Setting Up

I like to create a folder to contain the MySQL source code file and build folder. This way, I can later uninstall MySQL easily, as well as download and compile new versions, all in one place.

For these examples, we’ll create a folder called

src

in our home folder, and change directories into that folder. It will be our workspace for everything we do here:

mkdir -p ~/src
cd ~/src

You’ll download and compile everything in this new folder.

Download, Extract, Etc.

Now we’re ready to start the real work. Just type (or cut-n-paste) each one of the following lines into Terminal, one by one. When one line finishes (some will take a while and dump a lot of information to the screen), enter the next one.

This will first download and then expand the MySQL source code distribution:

curl -O http://mysql.he.net/Downloads/MySQL-5.0/mysql-5.0.45.tar.gz
tar xzvf mysql-5.0.45.tar.gz
cd mysql-5.0.45

You then need to configure MySQL:

CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc \
CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
-fno-exceptions -fno-rtti" \
./configure --prefix=/usr/local/mysql \
--with-extra-charsets=complex --enable-thread-safe-client \
--enable-local-infile --enable-shared

When that process completes, you can initiate the actual compilation process:

make

This part can take a while. Now is a good time to go and get yourself a tasty beverage.

The last part of the build process is where MySQL actually gets installed. You’ll be prompted for your password here, because this is where files actually get written to their actual locations:

sudo make install

Next, we need to setup the initial databases and privileges. You may be prompted for your password again:

cd /usr/local/mysql
sudo ./bin/mysql_install_db --user=mysql
sudo chown -R mysql ./var

That’s it, MySQL is installed. But you’re not done yet.

Auto-Starting MySQL

Now that the install is done, you need to have MySQL auto-start every time you start or reboot your Mac. The easiest way to do this is using launchd.

I’ve prepared a launchd plist file that will manage MySQL, starting it at boot and stopping it cleanly at shutdown. Create a file named

com.mysql.mysqld.plist

using the text-editor of your choice, and save it to your Desktop. Enter the following text into the file:

<?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>

Now we need to move the file into place and set the permissions on it. You may be prompted for your password again:

sudo mv ~/Desktop/com.mysql.mysqld.plist /Library/LaunchDaemons
sudo chown root /Library/LaunchDaemons/com.mysql.mysqld.plist

With the file in place, the last step is to tell launchd to load and startup MySQL. You may be prompted for your password again:

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

If things go well, you won’t see anything special happen, but MySQL will have started up. You can verify this, again back in Terminal:

mysql -uroot

This will initiate MySQL’s command-line monitor. If everything went well, you should see something like this:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.45 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

If you see that, that’s it, you’re done! Type

exit

to quit the MySQL monitor.

If you see something else, verify that your paths are set correctly and try the command again. If things still don’t work, it’s likely that something didn’t work and the compile didn’t finish. Try going through the steps once more and see if you can catch any error messages.

Starting and Stopping MySQL Manually

If you ever want to stop MySQL manually, use this command in Terminal, entering you password when prompted:

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

To start it manually, use this command in Terminal, entering you password when prompted:

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

A Note about Security

The easiest way to secure your MySQL installation without affecting the way you (or your applications) will need to communicate with it is to limit anything but local connections to your MySQL server. In other words, only you and the apps you run on your own Mac will be able to connect. You won’t need to enter passwords when interacting with MySQL locally, and won’t need to tweak the default

database.yml

files that Rails creates, for example.

We can limit access by creating (or editing) the

/etc/my.cnf

file. If you have TextMate installed, you can enter the following command to create (or edit) the file:

mate /etc/my.cnf

If you use BBEdit, you’d use this command:

bbedit /etc/my.cnf

The handy bit about using TextMate (or BBEdit) for this task is that it will handle authentication and setting permissions for you.

Enter the following text into the file save it and close it, authenticating as needed:

[mysqld]
bind-address = 127.0.0.1

Thanks to my friend Mike Clark for this tip.

If limiting access isn’t enough for you, you can read about setting a root access password for MySQL in this article.

Baking-In the MySQL Bindings

You can gain some bigtime Rails-to-MySQL speed improvements by building the MySQL C bindings for Ruby.

If you have an Intel Mac, just run the following command (entering your password when prompted):

sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

If you have a PPC Mac (I hear some still exist), you’d enter:

sudo env ARCHFLAGS="-arch ppc" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

You’ll see a prompt asking you which gem to install:

Select which gem to install for your platform (universal-darwin9.0)
 1. mysql 2.7.3 (mswin32)
 2. mysql 2.7.1 (mswin32)
 3. mysql 2.7 (ruby)
 4. mysql 2.6 (ruby)
 5. Skip this gem
 6. Cancel installation

Pick the option closest to the top that ends in “(ruby)”. In the example above, we’d want to select option 3.

Uninstalling MySQL

In case you one day decide that you’d like to remove MySQL, it’s easy to do when building from source:

cd ~/src/mysql-5.0.45
sudo make uninstall
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo rm /Library/LaunchDaemons/com.mysql.mysqld.plist

That’s It

So, you’re done. What are you waiting for? Go create the next Google or something.

Special thanks to Koz, Mike Clark, Ryan Schwartz, and Jason Seifer for their tips and suggestions.