Thursday, June 19, 2008

Grab N rows

mysqldump has a nice feature '-w' that I used today. Whilst working with a customer to migrate their 200G database from 4.1 to 5.1, we decided to grab a subset of the database to do initial tests with.
Using this:

mysqldump -w 'true LIMIT 1000'

I created a dump of 1000 rows of each table.

From:

http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
--where='where_condition'
, -w 'where_condition'

Dump only rows selected by the given WHERE condition. Quotes around the condition are mandatory if it contains spaces or other characters that are special to your command interpreter.

Friday, June 13, 2008

procedure analyse has its limits

Today whilst attempting to use procedure analyse against a customers tables I discovered that it doesn't work whilst using LIMIT in the SELECT query.
SELECT * FROM tablename LIMIT 10000 PROCEDURE ANALYSE()\G

The work around is to create a temporary table.

CREATE TEMPORART TABLE tmp_tablename from SELECT * FROM tablename LIMIT 10000;
SELECT * FROM tmp_tablename PROCEDURE ANALYSE()\G
DROP TABLE tmp_tablename;