Posts Tagged ‘DBA’

Bash: Count the number of databases in a gzip compressed mysqldump

A simple bash one-liner! ?View Code BASHgunzip -c /path/to/backup/mysqldump.sql.gz | grep -E "^CREATE DATABASE" | wc -l Breaking this down.. This prints the contents of a gzip compressed mysqldump to the terminal ?View Code BASHgunzip -c /path/to/backup/mysqldump.sql.gz Grep for lines that start with CREATE DATABASES… ?View Code BASHgrep -E "^CREATE DATABASE" Count the number of […]

Recover a single table from a mysqldump

I needed to recover the data, from a single table, from a mysqldump containing all the databases from an entire instance. A quick google yielded this result. This produced a nifty little sed one-liner… ?View Code BASHsed -n -e ‘/CREATE TABLE.*your_table_name/,/CREATE TABLE/p’ mysqldump_file.sql > your_table_name.sql I also wanted to import the data into a different […]

MySQL Database Maintenance Stored Procedure Update

This is just a quick update of a stored procedure to assist with MySQL Database Maintenance. I originally posted this back in 2012. The Stored Procedure allows you to run OPTIMIZE TABLE or ANALYZE TABLE on all (or most) tables in a MySQL database. In this version I’ve added some simple logging and automatic recognition of partitioned tables to take advantage […]

Check Mirroring Status with Powershell

Here’s a simple Powershell snippet to check the mirroring status on your SQL Server instances. ?View Code POWERSHELL# Load SMO extension [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null;   # Servers to check $sqlservers = @("server1", "server2", "server3"); foreach($server in $sqlservers) { $srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $server; # Get mirrored databases $databases = $srv.Databases | Where-Object {$_.IsMirroringEnabled -eq $true}; Write-Host […]

System Documentation: My Method

Jorge Segarra (Blog | Twitter) posed the question System Documentation: What’s your method?. In my experience documentation has either been nonexistent, out of date or even worse, plain wrong. These situations often get blamed on lack of time dedicated to documentation tasks. Therefore I’ve always aimed at making documentation easy or even fun. I’ve blogged […]