Skip to content

Instantly share code, notes, and snippets.

View utdrmac's full-sized avatar

Matthew utdrmac

View GitHub Profile
@utdrmac
utdrmac / vip_move
Created August 19, 2014 15:27
vip_move.txt
// If the host with the VIP is up, this removes it
ip addr del 10.20.43.184/32 dev eth2
// Add VIP to new host
ip addr add 10.20.43.184/32 dev eth2
/sbin/arping -c 5 -U -I eth2 10.20.43.184
@utdrmac
utdrmac / order-by-rand.sql
Last active August 29, 2015 14:07
Solution to ORDER BY RAND()
-- Option 1
SELECT *
FROM title t
WHERE kind_id = 1 AND id >= FLOOR(1 + RAND() * (SELECT MAX(id) FROM title)) LIMIT 1;
-- Option 2
SELECT id, title
FROM title t RIGHT JOIN
(SELECT CEIL(RAND() * (SELECT MAX(id) FROM title WHERE kind_id = 1)) AS id) h USING (id);
@utdrmac
utdrmac / per-engine-size.sql
Created February 4, 2015 16:05
Per-Engine Size Usage
SELECT count(*) TABLES,
concat(round(sum(table_rows)/1000000,2),'M') rows,
concat(round(sum(data_length)/(1024*1024*1024),2),'G') DATA,
concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(sum(index_length)/sum(data_length),2) idxfrac, engine
FROM information_schema.TABLES
WHERE table_type != 'VIEW' AND table_schema NOT IN ('mysql', 'performance_schema', 'information_schema')
GROUP BY engine;
@utdrmac
utdrmac / pushbullet_slave_monitor.sh
Last active December 30, 2015 17:58
Pushbullet Slave Watcher
#!/bin/bash
# A title for the notification
title="Slave - ${HOSTNAME}"
# PushBullet API Token
# https://www.pushbullet.com/#settings/account
token="C17CdC7b0XXXXXXXX1idCdATgVjbfEY"
# Send a notification every X minutes
SELECT t.table_schema, t.engine, t.table_name, c.column_name, c.column_type
FROM information_schema.tables AS t
INNER JOIN information_schema.columns AS c ON c.table_schema = t.table_schema
AND c.table_name = t.table_name
LEFT OUTER JOIN information_schema.innodb_sys_tables AS ist
ON ist.name = concat(t.table_schema,'/',t.table_name)
LEFT OUTER JOIN information_schema.innodb_sys_columns AS isc
ON isc.table_id = ist.table_id AND isc.name = c.column_name
WHERE c.column_type IN ('time','timestamp','datetime')
AND t.table_schema NOT IN ('mysql','information_schema','performance_schema')
@utdrmac
utdrmac / queue.php
Created September 22, 2016 01:25
Test script for AWS SQS
#!/usr/bin/env php
<?php
include 'config.php';
/* This is the EC2 API Client object */
$sqs = Aws\Sqs\SqsClient::factory(array(
'key' => $aws_key,
'secret' => $aws_secret,
'region' => 'us-west-2',
@utdrmac
utdrmac / checksumreport.sh
Last active December 26, 2016 17:44
Scripts checksums, binlog purge
#!/bin/bash
# This script will use the results from pt-table-checksum ran on the master and verify
# if any chunks are actually different. This is necessary because of the way NDB
# bundles up transactions within a single epoch. If a table is found to be inconsistent,
# pt-table-sync will use an explicit full table lock on the master during the comparison.
# Save output to log file
reportfile=$(mktemp /tmp/checksumreport.XXXXX)
exec 2>&1 >$reportfile
@utdrmac
utdrmac / find_checksums.sh
Created January 20, 2016 17:49
Finding Tables for Checksum
#!/bin/bash
mysql -e "TRUNCATE TABLE percona.checksums"
pt-table-checksum --no-check-binlog-format --no-check-replication-filters --engines ndbcluster --tables $below
# Get all NDB tables
# mysql information_schema -BNe "SELECT CONCAT(table_schema,'.',table_name) FROM tables
# WHERE table_schema NOT IN ('mysql',' ndbinfo','percona','information_schema')
# AND engine = 'ndbcluster'" >/root/ndb_tables.txt
@utdrmac
utdrmac / keybase.md
Last active February 21, 2017 19:39
Keybase Proof

Keybase proof

I hereby claim:

  • I am utdrmac on github.
  • I am utdrmac (https://keybase.io/utdrmac) on keybase.
  • I have a public key ASBe9_sYtgbqJWYn6uB5b2tkVuDEvqzD3zH8Y9uJ2qTcWAo

To claim this, I am signing this object:

@utdrmac
utdrmac / guider.c
Last active February 21, 2017 19:40
Multi-Threaded MySQL Connections in C
/*
* guider 1.0
* Matthew Boehm <mboehm@paypal.com> <matthew@matthewboehm.com>
*
* GUIDer reads in a file of global identifiers (GUIDs) and retrieves
* obfuscated data out of databases. This is done using pipe() to create
* a producer/consumer set-up. We create a pool of mysql connections
* and pthread out user-supplied number of threads to handle data.
* Each thread waits and reads 1 GUID off the front of the pipe() and processes
* it, outputting results to stdout. Once done with that set of queries, this