Posts tagged Tips

MySQL Quick-Tip: Target specific versions of MySQL with conditional comments

I was working on a project over the weekend that required me to run some code relating to MySQL privileges across a large number of MySQL servers all running various versions of MySQL between 4.0 and 5.0. My initial efforts at this entailed writing out the version specific code and targeting the version with bash thusly:

 VERSION=$( mysql -u$user -p$password -S $socket -e"SELECT VERSION();" | cut -f1,2 -d. )
 if [ $VERSION = '5.0' ]; then
  # Execute 5.0 code
 elif [ $VERSION = '4.1' ]; then
  # Execute 4.1 code
 elif [ $VERSION = '4.0' ]; then
  # Execute 4.0 code
 else
  echo "Unable to determine version
  exit 1

This method involved a lot of code duplication. Yesterday, a co-worker mentioned using MySQL version specific comments, which I had seen before, but never fully understood.
Read the rest of this entry »

How to reset the bash IFS variable

Here’s a quick tip for everyone. I was working on a one-liner today at work that involved parsing through a file with some data in it. The data had spaces in it which can cause problems with the default $IFS variable (Internal File Separator). nixCraft has an excellent tutorial on working with the $IFS variable.
Read the rest of this entry »

12 Quick and Easy MySQL Tricks

In my first two months as a MySQL DBA, I have picked up a number of tips and tricks that have helped me in my daily job. In this post, I share them here with everyone. Hopefully they will help you as much as they have helped me.
Read the rest of this entry »