Archive for category Programming
Copy mysql table between servers/databases
Posted by Bricky in Programming on July 20th, 2009
This is one of those reminder-to-self style posts.
To copy mysql table tablename from database1 on server1 to database2 on server2, issue the following command (on either server)
mysqldump -h server1 -u user1 -ppassword1 database1 tablename | mysql -h server2 -u user2 -ppassword2 database2
user1, password1, user2, and password2 are the respective usernames and passwords to use on server1 and server2, respectively. Note that there is no space between the -p and password (unlike the other switches).
Popularity: 9% [?]
getmail FutureWarning with python2.3
Posted by Bricky in Programming on May 5th, 2009
Some python (I assume) update on an old Centos box made getmail bork:
/usr/lib/python2.3/optparse.py:668: FutureWarning: %u/%o/%x/%X of negative int will
return a signed string in Python 2.4 and up
return ("<%s at 0x%x: %r>"
It gets more than a little annoying when you get emailed those few lines several hundred times per day. However, according to the getmail FAQ, it’s not their fault – it’s the nasty evil lazy python developers’ fault.
Changing the top of the /usr/bin/getmail file to ignore the warning made it go away:
#!/usr/bin/python -Wignore::FutureWarning
Popularity: 7% [?]
CSS min-width for Buttons in safari/webkit
Posted by Bricky in Mac, Programming on April 16th, 2009
… has stopped working in the latest webkit versions (for quite some time actually).
CSS min-width ignored for input type=”button” on webkit
(ok, you guessed it, I’m posting this just to draw uncle G’s attention. Sorry!)
Popularity: 12% [?]
All zero dates, mysql, and jdbc
Posted by Bricky in Programming on April 3rd, 2009
Cannot convert value '0000-00-00 00:00:00' from column N to TIMESTAMP
Familiar? This problem arises because ‘null’ dates in MySql are generally represented as ‘0000-00-00 00:00:00′, which, while valid in MySql, are completely forbidden in jdbc.
There is a wonderful workaround however, simply add the zeroDateTimeBehavior parameter to the end of your jdbc url as follows:
jdbc:mysql://hostname/dbname?zeroDateTimeBehavior=convertToNull
And that’s it, zero dates will be converted to nulls and jdbc will be happy.
Popularity: 7% [?]
htmlspecialchars for mysql
Posted by Bricky in Programming on March 2nd, 2009
Yes, it’s bad, evil, nasty, and just plain wrong.
But that doesn’t mean that there aren’t occasions when you do need to spew out html directly from mysql (or at least I’ve found one).
DELIMITER $$ DROP FUNCTION IF EXISTS `htmlspecialchars`$$ CREATE FUNCTION `htmlspecialchars` (_str text) RETURNS text BEGIN set _str = replace(_str, '"', '"'); set _str = replace(_str, '&', '&'); set _str = replace(_str, '<', '<'); set _str = replace(_str, '>', '>'); return _str; END$$ DELIMITER ;
Usual disclaimers apply.
Popularity: 7% [?]