Skip to content

Instantly share code, notes, and snippets.

View abg's full-sized avatar

Andrew Garner abg

  • VMware
  • San Antonio
View GitHub Profile
'''
Simple frmsearch command to find tables without a primary key
Run this via:
# curl get.dbsake.net > dbsake
# export DATADIR=$(mysql -sse 'select @@datadir') PYTHONPATH=$PWD/dbsake
# python find_nopk.py
!! mysql.slow_log does not appear to have a primary key !!
---
@abg
abg / mysql.py
Last active September 17, 2018 13:50
Run queries directly against MySQL via subprocess, rather than using MySQLdb
"""Examples fetching data from MySQL via /usr/bin/mysql"""
import subprocess
def get_innodb_log_file_size():
"""Run SELECT @@innodb_log_file_size and return the value as an integer"""
process = subprocess.Popen(['mysql', '-ss'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
@abg
abg / mysql_bug_75245_5622.patch
Created December 18, 2014 16:33
mysql_bug_75245_5622.patch
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -17158,6 +17158,10 @@ ib_warn_row_too_big(const dict_table_t* table)
THD* thd = current_thd;
+ if(thd == NULL) {
+ return;
+ }
+
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -17158,6 +17158,11 @@ ib_warn_row_too_big(const dict_table_t* table)
THD* thd = current_thd;
+ /* If current_thd is NULL, don't send a warning to the client */
+ if(thd == NULL) {
+ return;
+ }
@abg
abg / filters.py
Last active August 29, 2015 14:10
inclusion/exclusion filter implementation
#!/usr/bin/env python
import fnmatch
def inclusion_exclusion_filter(include=(), exclude=()):
"""Create an inclusion exclusion filter
:param include: sequence of glob patterns to include
:param exclude: sequence of glob patterns to exclude
:returns: function(name) that filters strings based on the provided filters
@abg
abg / frmsearch.py
Last active August 29, 2015 14:07
Scan .frm files in a MySQL datadir for old DATE/TIME/TIMESTAMP columns
'''
Simple frmsearch command to find tables with pre 5.6 date/time types.
Run this via:
# curl get.dbsake.net > dbsake
# DATADIR=$(mysql -sse 'select @@datadir') PYTHONPATH=$PWD/dbsake python frmsearch.py
ALTER TABLE `mysql`.`procs_priv` FORCE;
ALTER TABLE `mysql`.`columns_priv` FORCE;
ALTER TABLE `mysql`.`general_log` FORCE;
@abg
abg / kikori.sh
Last active September 17, 2018 00:29
kikori - a MySQL binary log archive utility
#!/bin/bash
### kikori - a MySQL binary log archive utility
# Support config options
format="${KIKORI_FORMAT:-directory}"
archive_path="${KIKORI_ARCHIVE_PATH:-/var/log/mysql/archive}"
compression_cmd="${KIKORI_COMPRESSION_CMD:-gzip -1}"
compression_ext="${KIKORI_COMPRESSION_EXT:-.gz}"
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
@abg
abg / lunix_unshare.py
Created May 9, 2014 18:26
python api to create process private mountpoints; essentially just a wrapper to unshare(2)
import ctypes
import ctypes.util
import errno
# <sched.h> constants for unshare
CLONE_NEWNS = 0x00020000
# <sys/mount.h> - constants for mount
MS_REC = 16384
MS_PRIVATE = 1 << 18
@abg
abg / snapshot_luks.sh
Created May 7, 2014 16:01
Snapshot an encrypted luks volume backed by LVM
#!/bin/bash
set -x
LUKS_PASSPHRASE="foo"
SNAPSHOT_MOUNTPOINT="/mnt/backup"
MOUNT_OPTIONS="barrier=0" # nouuid for xfs, etc.
# 1) Discover a MySQL datadir
datadir=$(mysql -sse 'select @@datadir')