Archive for the ‘MySQL’ Category

Production MySQL performance tuning

Thursday, January 15th, 2009

mysql Back in my days doing SAP I got intimately involved in Oracle performance tuning and there is a LOT to know! However, for the past 9 years I’ve been working almost exclusively with MySQL (with a little PostgreSQL thrown in) and while I don’t do nearly as much DBA work these days, I still find myself troubleshooting a query or tuning my.cnf. While in general I find MySQL to be a lot more straightforward to work with, it’s still equally important to tune it for your applications needs.

To that end one of the tools I want to give a shout out to is the MySQL Performance Tuning Primer Script. You download and run it against a production system (more…)

Standalone Migrations: Using Rails migrations in non Rails projects

Monday, December 22nd, 2008

Update 7/8/2009: With the latest batch of user submitted patches standalone migrations now works just like Rails migrations
Update 12/26/2008: I switched standalone migrations to use a Rakefile instead of a Ruby script.

Standalone MigrationsIn my work managing websites I end up working in Ruby, Java, and PHP. In everything but Rails managing the schema requires rolling your own solution. As a result I’ve started using Rails migrations in non-Rails projects to manage the schema. It’s not much code but I figured others might benefit from it so I created a little Github project called standalone migrations.

It’s based on Lincoln Stoll’s blog post titled Stand-alone ActiveRecord migrations and David Welton’s blog post titled Using Migrations Outside of Rails.

Assuming you have Ruby and Gem installed on your machine, here’s how to use it:

gem install -y activerecord rake mysql
wget http://github.com/thuss/standalone-migrations/zipball/master (or fetch it using git)
unzip it, and mv to something like my_non_rails_project/db
cd my_non_rails_project/db/ (or wherever you put it)
cp config/database_sample.yml config/database.yml
vi config/database.yml
./new_migration some_user_story
vi migrations/*_some_user_story.rb
rake db:migrate (this applies your newly created migration)

Comparing Amazon EC2 with VPS and dedicated hosting

Thursday, November 30th, 2006

I’ve been reading all the great things about Amazon EC2 (or Elastic Compute Cloud) and lots of pricing comparisons with VPS and dedicated hosting. I finally got an EC2 account and tinkered a bit and there’s a big difference between EC2 and Virtual Private Server or Dedicated hosting that most of the preliminary write-ups I’ve seen completely overlook.
(more…)

SQL statements mysteriously not replicating with MySQL replication

Wednesday, September 13th, 2006

If you’re using MySQL replication there’s a feature/bug that you should be aware of. The following SQL statement would not replicate to the slave servers:
(more…)

MySQL ODBC Driver issues and Excel

Tuesday, September 12th, 2006

Caveat: this post is probably only of interest if you’re running into this particular MySQL ODBC Driver problem. Hopefully other people running into this issue will find this useful or please add a comment if you find a better way!

Today I had to get an Excel document that was loaded with ODBC database queries that connect to multiple MySQL databases working on a new machine. The problem I ran into is that if there are any MySQL permission issues such as a missing grant, authentication problems, etc… you’ll always get the following completely meaningless error message:
(more…)

Configuring MySQL sql-mode in Ruby on Rails

Wednesday, June 7th, 2006

In my previous post I wrote about setting MySQL to a stricter sql-mode to make it behave like most other databases, however, I recently ran into a case where I couldn’t set the global sql-mode without breaking some legacy applications. I imagine this is also often the case when you host on a shared server where a global configuration change would be out of the question.
(more…)

When installing MySQL always set the sql-mode

Sunday, May 28th, 2006

As I’ve described before, MySQL has some appalling out of the box settings which will thwart your attempts at good data integrity! They’ve clearly seen the light though and at least give you an option to achieve good data integrity through foreign keys in InnoDB and proper handling of non-nullable fields and invalid values through the servers sql-mode setting.

To make matters worse it seems MySQL may have different out of the box settings per platform and per version. For example a friends 5.0.21 install on Windows XP had the sql-mode set with relatively strict settings whereas 5.0.18 on my Mac had an empty sql-mode. This only illustrates the necessity of always explicitly defining these settings with each install yourself so that you get consistent behavior.
(more…)

Creating database test fixtures and the rails export fixtures plugin

Tuesday, May 16th, 2006

Being able to quickly and easily create test fixtures for your database is important yet it’s not always easy. There are basically 3 approaches I’ve seen used:

1. Use a MySQL or PostgreSQL dump that gets imported before the tests are run. I’ve never seen this approach used with Oracle, most likely because it’s such a PITA to export to text (or at least it used to be)
2. Just create the schema before the tests and then populate the test data in code
3. Use a database test fixture tool such as the XML based DBUnit for Java or Ruby’s YAML based fixtures
(more…)

Moving MySQL tables live with zero downtime

Tuesday, May 9th, 2006

The biggest challege to moving large amounts of data into production with (almost) zero downtime with MySQL is that the old table will be dropped and the new table locked while you’re loading the data. If you try that while serving a lot of traffic you’ll get into trouble as the database connections start stacking up waiting for the lock to free on that table and then you’ll hit max connections giving most of your users a 500 error.

If you need to move big tables live you basically have 2 options: (more…)