Skip to content

Instantly share code, notes, and snippets.

View utdrmac's full-sized avatar

Matthew utdrmac

View GitHub Profile
@utdrmac
utdrmac / monitor_mysql.pl
Last active April 21, 2024 06:16
Perl Script to Monitor MySQL Replication and Send Email on Failure
#!/usr/bin/perl
use DBI;
use Email::MIME;
use Log::Log4perl qw(get_logger :levels);
use Data::Dumper;
use strict;
# For backgrounding
#!/bin/bash
#
# 20210119 - Use the new --endpoint flag
# - Added verbose logging
#
# 20200608 - Updated to TzKt API
#
# 20191029 - Added /v3/network back in.
# Thanks to Baking-Bad and their Mystique API
@utdrmac
utdrmac / make_employees.py
Last active February 7, 2024 16:58
Multi-Threaded MySQL in Python
#!/usr/bin/python
import os, sys
import random
import time
import string
import mysql.connector
import threading
from mysql.connector import errorcode
@utdrmac
utdrmac / max_auto_increment_tables.sql
Created August 19, 2014 15:31
Find db.table.columns that are > 90% auto_increment capacity
SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, COLUMN_TYPE,
(CASE DATA_TYPE
WHEN 'tinyint' THEN 255
WHEN 'smallint' THEN 65535
WHEN 'mediumint' THEN 16777215
WHEN 'int' THEN 4294967295
WHEN 'bigint' THEN 18446744073709551615
END >> IF(LOCATE('unsigned', COLUMN_TYPE) > 0, 0, 1)
) AS MAX_VALUE,
AUTO_INCREMENT AS CURRENT_VALUE,
/*
* Gracewatch 1.0
* Matthew Boehm <matthew@matthewboehm.com>
*
* Gracewatch is a multi-threaded MySQL monitoring solution developed for
* a client that had no in-house monitoring team.
*
* Using libConfig (http://www.hyperrealm.com/libconfig/), gracewatch reads
* a list of servers and credentials and spawns a pthread for each server.
* The thread connects to the host and every minute preforms a mysql_ping()
@utdrmac
utdrmac / mysql_memory_usage.sql
Created June 21, 2016 19:06
MySQL Memory Usage
SELECT CONCAT((@@key_buffer_size + @@query_cache_size + (@@innodb_buffer_pool_size * 1.05 + 20*1024*1024) + @@innodb_additional_mem_pool_size + @@innodb_log_buffer_size
+ @@max_connections * (@@read_buffer_size + @@read_rnd_buffer_size + @@sort_buffer_size + @@join_buffer_size + @@binlog_cache_size + @@tmp_table_size
+ @@thread_stack)) / 1024/1024/1024, ' GB') AS "POTENTIAL MEMORY USAGE";
@utdrmac
utdrmac / mysql_autoinc_checker.go
Created April 12, 2018 23:36
Checks AUTO_INCREMENT fields in MySQL to see if near MAXVALUE
/*
Copyright (c) 2014, Percona LLC and/or its affiliates. All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@utdrmac
utdrmac / rds-repl-restart.py
Last active November 23, 2023 02:42
Quick-n-dirty script for watching RDS replication and skipping on specific error codes
import sys
import mysql.connector
from mysql.connector.errors import InterfaceError
from time import sleep
mydb = mysql.connector.connect(host="", user="", password="", database="mysql")
cursor = mydb.cursor(dictionary=True)
while True:
@utdrmac
utdrmac / mysql_queries_prod_consumer.py
Last active September 27, 2023 21:52
Execute queries in parallel on MySQL; Producer-Consumer in Python
import sys
import argparse
import mysql.connector
from queue import Queue
from concurrent.futures import ThreadPoolExecutor
def parseargs():
parser = argparse.ArgumentParser(prog="mysql_queries_prod_consumer.py", add_help=False)
@utdrmac
utdrmac / imdb_comments.py
Last active September 27, 2023 21:49
Insert english-like comment strings
#
# pip3 install mysql-connector-python
"""
CREATE TABLE comments (
id int unsigned primary key auto_increment,
user_id int unsigned not null,
comment varchar(200) not null,
type varchar(10) not null,
type_id int unsigned not null);