Feed on
Posts
Comments

If you have groups defined in your .my.cnf file so that your scripts don’t need to specify database connections directly, such as from R or perl scripts, you may wish to use these group definitions for mysql scripting from bash.

Unfortunately, there doesn’t seem to be any way to tell mysql to load login information from a group specified in the ~/.my.cnf file, although you can specify a “defaults file” to use with this syntax: mysql --defaults-file=<my special file> where "<my special file>" is a full path to a file that contains a [client] section that the mysql command will use.

However, if you use this mechanism, you would need to proliferate copies of user names, passwords and connections in multiple files for use by various tools, in my case both R and mysql. If there is a way to do this directly from a mysql command line, I have been unable to locate it.

Here then is a trick that will coerce the uncooperative mysql command to load the defaults from the specified [group] in the ~/.my.conf file. It works by filtering the ~/.my.conf file for the specified group, replacing the arbitrary group name with a [client] section into an anonymous pipe that mysql will read as the --defaults-file parameter

In my case, I have a group named [rss2twitter] that specifies login information I’m using for an R script to connect via the RMySQL package. I want to use this same information to connect from arbitrary bash scripts.

mysql --defaults-file=<(cat ~/.my.cnf | echo-group.pl "rss2twitter")

This is the echo-group.pl perl script:

#!/usr/bin/env perl
# mode=0 is initial
# mode=1 is reading the section of interest
$mode=0;
# loop through the lines in the config file
while(<STDIN>){
        # this looks out of order, but what gets executed is based on the mode
        # if we are reading the section of interest and hit another section, exit
        if(/^\[/ && $mode == 1) {exit;} 

        # if we are reading the section of interest, echo it
        if($mode ==1) {print $_;}

        # if we hit the section of interest, matched on the first command line argument, change to mode=1
        if(/^\[$ARGV[0]\]/) {print "[client]\n"; $mode=1;}
}

And here is the example ~/.my.cnf file that is used by the perl script. The “garbage_entries” are for testing and represent other sections you may have in your ~/.my.cnf file.

[garbage_entry1]
user = w00t
database = junk
password = junk
host = george

[rss2twitter]
user = root
database = rss2twitter
password = secret
host = naiad

[garbage_entry2]
user = w00t
database = junk
password = junk
host = trixie

Technorati , , ,

For some time my Acrobat 7 Professional installation on my Mac has thrown an error on initial access to the Organizer (File menu option Organizer) “Could not initialize Organizer database”. I recently upgraded to Acrobat 8, and the problem persisted.

After at least a week of extended dialog with Adobe support that was going nowhere, I decided to see if I could figure out what was going on.

Based on a Google search, I figured it must have something to do with a conflict between my Acrobat installation’s embedded mysql instance and the mysql instance I had installed on my machine.

I had an /etc/my.cnf file to force my instance to use InnoDB by default. The Acrobat embedded mysql instance was picking this up, causing it to die, since it apparently lacks InnoDB bits.

The solution is to move /etc/my.cnf elsewhere. I moved mine to the mysql data directory for my instance, /usr/local/mysql/data/ where my instance picks it up, but the Acrobat instance does not.

Technorati , , , ,

Complexity and Resilience

I’m convinced that exposed complexity contributes to more outages than any other technical factor. The operational or human sister to this is inadequate configuration management. Unless we ruthlessly squash non-value added diversity and complexity, our systems become unmanageable, and are crushed by their own mass.

The advance of technologies like Ruby over J2EE and MySQL over Oracle has a lot more to do with the ability to get things done quickly, consistently and cleanly than the relative technical merits of the implementations. Its not worth the CPU cycles to screw around with massively complex tools when you can throw more machines at most problems.

Technorati , , , , ,