Notes on Java, Solaris, PHP, LDAP…

June 13, 2008

Read-only dump of MySQL

Filed under: Java — negev @ 7:52 pm

Sometimes I need to dump MySQL data from servers where I have read-only access. When I run standard mysqldump, then it fails because it tries to lock the tables. Here’s how to dump without locking:

/usr/local/mysql/bin/mysqldump -u my-user -h my-server -p -O lock-tables=FALSE db-name >db-dump.sql


May 13, 2008

Filtering via Perl on commandline to extract values

Filed under: Java — negev @ 3:16 pm
Tags: , , ,

My superb admin showed me two tricks. He invokes perl and passes it the regular expression from the shell. Perl processes standard input and writes to standard output.

The first one collects all user emails and then it gets their unique email domains. The second one collects values of LDAP attribute companyDomains and again gets their unique values.

mysql -h mysql-server -u user -ppassword db-name -e ‘SELECT email FROM users’ | perl -nle ‘/.*@(.*)/;print $1;’ | sort -u | wc

ldapsearch -x -h ldap-server -D “cn=readonly,o=services” -w password -b o= users “(objectClass=organizationalUnit)” companyDomains | grep -P ^companyDomains: | perl -ple ‘s/^companyDomains: //;’ | grep -Pv ‘^\d’ | sort -u

April 27, 2008

SUN & MySQL morning briefing

Filed under: Java — negev @ 12:42 pm
Tags: ,

Last Friday 25th April I was at SUN & MySQL morning briefing. Out of 6 talks only 2 were by marketing guys, and even those were highly focused on technology and systems than selling. Saying all that, it was a more business-value and CIO-focused than SUN Tech Days, but still interesting to technology people.

Here is what caught my attention, mixed with my comments. It’s likely I attribute some quotations to a different speaker, as I originally grouped my notes by topic.

Simon Phipps, SUN’s open-source promoter
Simon can nicely describe history of open source, how their communities operate and how open source became adopted by commercial sector and enterprises. But this time, most likely because of high ratio of CIOs in the audience, he went straight to the business language. The old-style SW era was procurement-driven. Vendors proposed a system. They made it for you. You payed, trained for it and migrated to it. Just then you found the limitations, but it was too late. As the cycle took two years or more, the system was already archaic when you eventually used it.

Open source is adoption-led. You find a product and you test it. Only if it suits your needs, you pay for the value: support, extra modules, connectors, training, recently indemnification. It is now a mature main-stream market.

David Axmark, Co-Founder, MySQL
David gave a nice insight into how MySQL started and grew up. I was surprised that MySQL is used at such remote places as Greenland and Pacific islands. His suggestions for success of an open source project:

  • solution to a common problem
  • works in 15 minutes
  • binaries for many systems
  • fast, stable
  • contained – focus on core features
  • public bug database
  • wide audience
  • plugins and their API, plugin-independent data export/import format
  • documentation


  • maximalist thinking
  • lack of adoption focus
  • fear of technical maturity
  • fear of free
  • perception of IP threat
  • procurement control

From comments of David Mitchell, senior analyst at Ovum, on merge of SUN & MySQL and current IT market in general:

  • both SUN and MySQL gain new markets
  • databases and business products are doing about same well and have larger market share than operating systems
  • open source supports financial predictibility
  • software as a service is not a panacea, because it gives up architecture control to the provider. It’s a lock-in no matter what the provider says

The only marketing I caught:

  • £25.000 unlimited MySQL enterprise license, same cost as Oracle on 1 CPU
  • you can evaluate MySQL monitor (or whatever it’s called) for free

April 9, 2008

MySQL local rights

Filed under: Java — negev @ 11:36 am

When you want to create a local MySQL user (account) and you want to use that account on the same host (machine), then you need something like this:
GRANT SELECT , INSERT , UPDATE , DELETE ON my_app. * TO ‘my_app’@’localhost’

Don’t use ‘my_app’@’%’ because that somehow didn’t work – at least not on MySQL 5.0.18 which comes with SUSE Linux SLES 10.

November 18, 2007

Notes on MySQL, Novell eDirectory LDAP ACLs, XSLT, Mailtrap

Filed under: Uncategorized — negev @ 12:12 pm
Tags: ,

9 Aug 07
MySQL Select & GROUP records with minimum value of a chosen column
SELECT, disposition, count( num_positions FROM offices, positions WHERE condition-on-office AND GROUP BY ORDER BY num_positions ASC LIMIT 8;

Novell eDirectory
– schema and attribute names
– how to change [ROOT] permissions to more specific permissions:
— When replacing [ROOT] by a specific DN, then remove [] brackets
— so instead of “2#entry#[ROOT]#member” you use “2#entry#o=MyCompanyName#member”

XSLT to concatenate strings
– use concat( first, second…) rather than operator +. + works only for numbers
– don’t concatenate values/expressions with in-XML constants, because it will add spaces etc:
<xsl:value-of select=”$logoName” />.gif

Using JEdit with files that are hard-linked at multiple locations
– then in JEdit’s opetions unset: jEdit > General > Two-stage save (safer but resets file owner on Unix)

novell eDirectory weird ACLs – couldn’t modify LDAP ‘mail’ attribute
– that was because I had ACLs in ConsoleOne to EMail Address, not to ‘Internet EMail Address’ – and the second is NDS attribute respective to LDAP attribute ‘mail’
– so you need to set ACLs to ‘Internet EMail Address’ rather than ‘EMail Address’
– see NDS-LDAP attribute mappings in Console One > tree > Resources > Servers > LDAP Group – my server > Attribute Mappings

23 Oct 2007
Mailtrap – fake SMTP server that traps all emails and saves them to a file
– it uses Ruby

Universal USB Webcam driver for Mac OS X

November 17, 2007


Filed under: Uncategorized — negev @ 9:37 pm

17 July 07
MAMP (AMP for Mac OS X) and graphics library error: Symbol not found: __cg_jpeg_resync_to_restart
– follow
— comment out both lines in /Applications/MAMP/Library/bin/envvars

MySQL counting of associations grouped by the number of occurrences
SELECT count(*), agency_id FROM positions WHERE active_flag=1 GROUP BY agency_id;

– be careful though: following 2 queries give different results:
SELECT count(*), agency_id FROM positions WHERE active_flag=1 AND agency_id IN (SELECT id FROM agencies WHERE disposition=’live’) GROUP BY agency_id;
–> a lot of small sum results
SELECT count(*), agency_id FROM positions WHERE active_flag=1 GROUP BY agency_id AND agency_id IN (SELECT id FROM agencies WHERE disposition=’live’);
–> a few big cumulated results

MySQL dump when you don’t have lock rights to the tables:
mysqldump –lock-tables=FALSE

Setting old-style MySQL passwords:
GRANT SELECT , SHOW DATABASES ON * . * TO ‘readonly’@’%’
IDENTIFIED BY ‘readonly’

SET PASSWORD FOR ‘readonly’@’%’= OLD_PASSWORD(‘readonly’);


Filed under: Uncategorized — negev @ 9:33 pm
Tags: , , ,

4 July 07

Unix/CRON output redirection
my-command >/my_log_dir/my_file 2>&1

LDAP search expressions
– need to have parenthesis both outside & inside operator-based expressions:

Subversion on Novell SLES 10
— don’t use David Summer’s – it complained about libraries even when they were up to date (for SVN 1.4.0)
– use CollabNet commandline client

Subversion on Mac OS X
— use DMG from Metissian 1.3.1 or newer

Grep filtering of Java/C multi-line comments
pcregrep -r -M -f ~/comments.regex
– comments.regex is:
– don’t use \w – that doesn’t include new line in pcregrep
– \n doesn’t represent new line
-l = Instead of printing lines from the files, just print the names of the files
-c = Do not print individual lines; instead just print a count of the number of lines
-n = Precede each line by its line number in the file

Backslash problems when connecting via rdesktop from a Linux box to Windows VM:
Set Windows (VM) to use US keyboard

PortableApps – packaging/’virtualization’ of MS Windows applications – it makes a package you can run from USB; open-source
Thinstall – same but commercial

MySQL on Mac OS X 10.4 Intel
– install DMG from Mysql site and also follow

Cross-platform presentational SW:
– generates Flash
– audio+screenshots

JavaOne 2007 – Open Source mobile OS:
Freedom also means that you have to let other people be free to make choices that you might not…

Test Units – abstract of Tapestry testing @JavaOne 2007
– it helps if there a single class that has responsibility for all task of a given process
– test-driven dev = change detection (regression tests) + more
– tests
— isolated, thorough
— easy to debug, frequently run (i.e. fast) => out-of-server, or out-of-container
— test the ‘hard stuff’
— tests document design decisions – expectations/requirements

Migration PHP4 -> PHP5, PHP4 references and connection to MySQL

Filed under: Uncategorized — negev @ 9:23 pm
Tags: ,

18 June 07

Migration from PHP4 to PHP5
There is a PHP5 php.ini directive that puts PHP5 into PHP4
compatibility mode. In otherwords, your PHP4 scripts will for
sure [most likely] work. This directive is called: zend.ze1_compatibility_mode

If the compatibility mode doesn’t do it, try to reorganize code a little – e.g. constructors needing to be renamed…

Configuring PHP5 with Apache on SLES 10
– after installing Apache, PHP5, mod_php etc Apache
— make Apache start at boot time
— if need be, follow /usr/share/doc/packages/php5/README.SUSE

PHP5 and <? ?>

PHP5 has short_open_tag=off by default, which means that <? ?> and <?= ?> cannot be used. While <?php ?> can be used in place of the first tag, the next one must be replaced by <?php echo ?> which is makes code quite unreadable.

So how about having short_open_tag=on in php.ini?

PHP4 and references

We can use references for arguments and return them from the functions. There are at least a few tricky situations in PHP4 when references work weirdly or not at all:

  • returning/passing NULL by reference – it doesn’t make sense to do it, but if that happens then (my) PHP4 badly and quietly dies.

  • $myVariable =& $this→myField→itsFunction() generates a notice even when itsFunction() is defined to return by reference. Only $myVariable =& $this→myFunction() works.

  • references and global variables don’t really work together. Global variables are generally a bad idea, but sometimes we need them ($_REQUEST, $_SESSION). CakePHP session management doesn’t give access by references (and it it uses $_SESSION by default).

  • you need to keep track of your reference ‘links’ and when passing/retrieving data by reference you need to make sure that the functions don’t perform undesired/undocumented/unexpected side effects

  • if typing assignments by reference as =& then it’s easy to search/grep for them – in order to track any funny interaction

PHP mysql connection has its selected DB changed without any obvious reason
– PHP mysql_connect(..) by default reuses a connection if we pass same server, user & password several times.
– If we use those for several DBs then we want to pass an optional FALSE parameter to mysql_connect() to turn off this default behaviour. Or we can use same DB, or to have separate user for each DB.

PHP and SQL notes

Filed under: Uncategorized — negev @ 8:04 pm
Tags: , ,

Installing PHP on Mac OS X:
./configure –with-ldap –with-apxs
sudo make install

Getting unique values from an array – PHP
use: array_keys( array_flip($arr) )
array_flip() – it switches keys and values
array_reverse() – it returns the array in reverse order, optionally preserving the keys

27 Mar 07
When opening a MySQL/SSH connection to another box takes really long (c.a. 6-7sec)
-> set skip-name-resolve=true in my.cnf

Sun LDAP and related-products:

  • Open DS. An community building an open source directory service.
  • Open SSO. A community working on an open source implementation of single sign on.

PHP arrays – items are kept in order they were added in, rather than sorted by values of keys!

MySQL, CakePHP tips

Filed under: Uncategorized — negev @ 5:26 pm
Tags: , ,

28 Feb 07
Mutliple databases and PHP frameworks
– Code Igniter (OpenWorld)
— in a controller: $this->load->model( ‘Officemodel’, ”, $this->config->item(‘my_db_profile’) );
— in application/config/autoload.php -> add a new config file for the other DB, e.g. application/config/database_2nd.php:
$autoload[‘config’]= array( whatever-was-there, ‘database_2nd’ )

– CakePHP
— have several DB ‘profiles’ in app/config/database.php
— in model class: var $useDbConfig = ‘my_db_profile’;


MySQL 4.1.13-standard: do not have DB user and DB name same, otherwise it used to cause problems.
— however, same DB user and database name worked on another instance of MySQL 4.1.13-standard

MySQL -copying a value from one DB or table to another:
use main_db;
UPDATE cities SET name=(SELECT name FROM old_main_db.cities WHERE id=337) WHERE id=337;

CakePHP multi-DB application:
Have following set in the model(s):
var $useDbConfig = ‘test’;

Unicode in MySQL:

SET NAMES 'charset_name' COLLATE 'collation_name'

SET NAMES ‘utf8’;
– the above commands set several variables, list them by

Next Page »

Blog at