Using mysqldump to Backup Database Structure and Data Separately

I have have been developing on a MySQL database where a small amount of test data is still over a half a million rows or more. So exporting the schema to pass it along to others takes forever. Fortunately you can export just the structure of the database and nothing else (which is much faster).

mysqldump -h hostname -u user database -RQdp > structure.sql

The option d is the key here. It stands for "no data". The option R will make it include your stored procedures and functions. And the option Q puts backticks (`) around your table names, column names, etc to prevent keyword errors on import.

Alternatively you can also export just the data.

mysqldump -h hostname -u user database -Qtp > data.sql

The option t means "no create info". Which means it wont put any CREATE TABLE statements in your export.

Convert a MySQL Date String into Javascript Date Object

Here is a Javascript function that I threw together the other day that will take the default format of a MySQL DATETIME or TIMESTAMP field (YYYY-MM-DD HH:MM:SS) and convert it into a Date object in Javascript.

function parse_date(string) {
    var date = new Date();
    var parts = String(string).split(/[- :]/);

    date.setFullYear(parts[0]);
    date.setMonth(parts[1] - 1);
    date.setDate(parts[2]);
    date.setHours(parts[3]);
    date.setMinutes(parts[4]);
    date.setSeconds(parts[5]);
    date.setMilliseconds(0);

    return date;
}

Database Schema Searching Utility

This is a php script that I wrote a number of years ago. It allows you to search through schema of MySQL databases by table column name. It can connect to multiple servers and it will search the structure of every table in every database.

It is a great tool to find related columns in a complex server situation. You can get the source code here, feel free to download and use it.

I found this in an old email that I sent to myself. I wrote this utility at my first job out of college. They had a software system that had been through a number of reincarnations over the years and they were left with redundant data across numerous servers and databases. I used this script to locate related fields across systems and would then write translation code that would merge data into a consolidated system.

{
}