Posts Tagged ‘commandline’

One-way MySQL DB Syncing for Dummies

June 3rd, 2009

To ease my development while on the move, I have local development copies of my websites running on my MacBook Pro. This has always worked pretty well for me, as content for my websites was created, predominantly, by myself, and when new content was created at a single site I could sync that database manually and get an up to date local content set.

With my recent efforts into lifestreaming, this is no longer the case. My content now comes in whenever I post content on any website. I’m a fairly frequent user of the internet services that feed my lifestream (Twitter, Delicious, Flickr, etc), and keeping the content on my local version up to date was turned into a troublesome task, forcing manual, tedious syncing each time I went to work.

Without further explanation, here are the steps I took to make a one line MySQL database syncing command. There may be better ways to do this and if you know them, please comment.

1. Setup a MySQL “dump” user. Mine is cleverly named “dump” and is passwordless, although if you are more security conscious than I am, you can add a password of your choosing. On the server, log into mysql and issue this GRANT statement from a user with the proper permissions.

1
GRANT SELECT, LOCK TABLES ON `dbname_remote`.* TO 'dump'@'localhost';

2. Create a bash alias
~/.bashrc :

1
ALIAS clone_lifestream='ssh -q -t hostname "mysqldump -u dump dbname_remote" | mysql -u root dbname_local'

Notes: For this example, you need to replace a few things.

  1. dbname = the remote database name
  2. hostname = the remote hostname
  3. dbname_local = the local database name
  4. clone_lifestream = the name of the alias, can be anything.

Length Errors in Apache Bench

May 4th, 2009

Are you seeing errors for content length in your Apache Bench tests of your webserver?

I had a hell of a time wondering what was going wrong with my webserver under load and finally found the answer here.

Turns out that Apache Bench takes the first pulled request and compares the length to all subsequent requests. Makes sense for a purely static page, but when you have a random image cropping up, you’re sure to see at least a couple bits difference in length.

So if you’re serving straight, hand coded HTML, enjoy the feeling of knowing that you’re getting the same length content each and every time… but if you’re like the rest of us (and anyone who would actually be using Apache Bench) feel free to rage that there’s no command line switch to turn off that silly notification.