Skip to content

Instantly share code, notes, and snippets.

View bradfordpythian's full-sized avatar

Ronald Bradford bradfordpythian

  • Pythian
  • Trumbull CT USA
View GitHub Profile
sudo yum install -y epel-release
sudo yum install -y ansible
@bradfordpythian
bradfordpythian / master.awk
Created March 15, 2017 21:00
Generate CHANGE MASTER from master.info
BEGIN {
print "CHANGE MASTER TO"
}
{
if (NR==4) {
print " MASTER_HOST='"$0"',"
}
if (NR==5) {
print " MASTER_USER='"$0"',"
}
@bradfordpythian
bradfordpythian / schema_size.sql
Last active April 3, 2017 20:46
MySQL Statement to show schema size and table types
SELECT @@hostname, @@version, @@version_comment, @@version_compile_machine;
SELECT NOW();
SELECT table_schema,
SUM(data_length+index_length)/1024/1024 AS total_mb,
SUM(data_length)/1024/1024 AS data_mb,
SUM(index_length)/1024/1024 AS index_mb,
COUNT(*) AS tables,
CURDATE() AS today
FROM information_schema.tables
WHERE table_schema NOT IN ('mysql','sys','performance_schema','information_schema')
@bradfordpythian
bradfordpythian / table_size.sql
Last active April 24, 2017 16:42
List summary table type and size details.
SELECT @@hostname, DATABASE() as table_schema, CURDATE() AS today;
SELECT if(length(table_name)>30,concat(left(table_name,28),'..'),table_name) AS table_name,
engine,row_format as format, table_rows, avg_row_length as avg_row,
round((data_length+index_length)/1024/1024,2) as total_mb,
round((data_length)/1024/1024,2) as data_mb,
round((index_length)/1024/1024,2) as index_mb
FROM information_schema.tables
WHERE table_schema=DATABASE()
ORDER BY 6 DESC
LIMIT 15;
[ `id -u` -ne 0 ] && echo "ERROR: Script must be run as root" && exit 1
DISK="/dev/sdb"
[ `fdisk -l ${DISK} | wc -l` -eq 0 ] && echo "ERROR: A second disk '${DISK}' was not found" && exit 2
fdisk -l ${DISK}
pvdisplay ${DISK}
[ $? -eq 0 ] && echo "ERROR: Physical Volume for '${DISK}' already exists" && exit 3
pvcreate ${DISK}
vgcreate appvg ${DISK}
@bradfordpythian
bradfordpythian / VagrantFile.centos6.disk2
Created February 22, 2017 16:16
VagrantFile for CentOS 6 with a second disk of 500MB
Vagrant.configure(2) do |config|
config.vm.box = "centos/6"
file_to_disk = './disk2.vdi'
config.vm.provider "virtualbox" do |v|
unless File.exist?(file_to_disk)
v.customize ['createhd', '--filename', file_to_disk, '--size', 500 * 1024] # 500M
end
@bradfordpythian
bradfordpythian / screen_wrapper.sh
Last active February 22, 2017 18:36
Wrap a screen session with file logging
#!/bin/bash
SCRIPT_NAME=`basename $0 | sed -e "s/\.sh$//"`
[ -z "${TMP_DIR}" ] && TMP_DIR="/tmp"
TMP_FILE="${TMP_DIR}/${SCRIPT_NAME}.tmp.$$"
DATE=`date +%Y%m%d.%H%M`
[ -z "${LOG_DIR}" ] && LOG_DIR="/opt/pythian/log"
[ ! -d "${LOG_DIR}" ] && echo "ERROR: Log directory '${LOG_DIR}' is not accessible." && exit 1
@bradfordpythian
bradfordpythian / alter_to_tokudb.sh
Last active February 22, 2017 18:51
Alter all tables in a given schema from InnoDB to TokuDB
#!/bin/sh
SCRIPT_NAME=`basename $0 | sed -e "s/\.sh$//"`
[ -z "${TMP_DIR}" ] && TMP_DIR="/tmp"
TMP_FILE="${TMP_DIR}/${SCRIPT_NAME}.tmp.$$"
[ -z "${LOG_DIR}" ] && LOG_DIR="/opt/pythian/log"
[ ! -d "${LOG_DIR}" ] && echo "ERROR: Log directory '${LOG_DIR}' is not accessible." && exit 1
[ -z "${SCHEMA}" ] && SCHEMA="test"
set_target_dir() {
local TARGET_DIR=$1
[ -z "${TARGET_DIR}" ] && echo "INTERNAL ERROR: One parameter required ($#) supplied" && exit 1
if [ ! -d "${TARGET_DIR}" ]
then
sudo mkdir -p ${TARGET_DIR}
RC=$?
# This snippet performs the following for RedHat/CentOS/OL 6.x system
#
# - Clean Installation of Percona Server 5.6.26
#
# NOTE: Installing via yum is not permitted
# To simulate a base system run the following for CentOS 6.6, 6.7 and 6.8:
# vagrant init nrel/CentOS-6.6-x86_64; vagrant up --provider virtualbox
# vagrant init nrel/CentOS-6.7-x86_64; vagrant up --provider virtualbox
# vagrant init centos/6; vagrant up --provider virtualbox