Skip to content

Instantly share code, notes, and snippets.

View jeffreyroberts's full-sized avatar

Jeffrey L. Roberts jeffreyroberts

  • PHP DevOps
  • Miami, Florida
View GitHub Profile
@jeffreyroberts
jeffreyroberts / mysql_db_server_growth_history.sql
Last active December 23, 2015 05:59
MySQL - Monitor growth history of all databases and tables hosted on a MySQL Server
-- SET GLOBAL event_scheduler = ON;
-- create table db_growth_history(db_name varchar(64), tbl_name varchar(64), avg_row_length int, row_count bigint, time_stamp datetime);
DELIMITER $$
CREATE
EVENT `document_db_growth_history`
ON SCHEDULE EVERY 1 DAY
DO BEGIN
-- Grab db name, table name, avg row length, row count, add timestamp = growth_history
@jeffreyroberts
jeffreyroberts / mysql_db_table_growth_rates.sql
Last active June 11, 2022 10:35
MySQL - Monitor table growth rates in terms of row counts
-- SET GLOBAL event_scheduler = ON;
-- create table growth_history(tbl_name varchar(64), row_count bigint, time_stamp datetime);
DELIMITER $$
CREATE
EVENT `document_growth_history`
ON SCHEDULE EVERY 1 DAY
DO BEGIN
@jeffreyroberts
jeffreyroberts / mysql_count_tables_in_db.sql
Created September 17, 2013 04:25
MySQL - Count number of tables in a database
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '<database_name>';
@jeffreyroberts
jeffreyroberts / mysql_count_rows_sql_generator.sql
Last active December 23, 2015 05:49
MySQL - Generate selects for counting rows of each table in a database
SELECT CONCAT(
'SELECT "',
table_name,
'" AS table_name, COUNT(*) AS exact_row_count FROM ',
table_schema,
'.',
table_name,
' UNION '
)
FROM INFORMATION_SCHEMA.TABLES
@jeffreyroberts
jeffreyroberts / mysql_count_rows_in_db.sql
Last active December 23, 2015 05:49
MySQL - Calculate total rows of all tables in a database
SELECT SUM(TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '<database_name>';
@jeffreyroberts
jeffreyroberts / mysql_count_rows_for_each_table_in_db.sql
Last active December 23, 2015 05:49
MySQL - Count all rows per table in a database
SELECT TABLE_NAME, TABLE_ROWS FROM `information_schema`.`tables` WHERE `table_schema` = '<database_name>';
@jeffreyroberts
jeffreyroberts / php_load_file_into_random_queue.php
Last active December 22, 2015 03:09
PHP - load random queue from file with lines terminated by \n
function load_queues($path) {
$queuesTemp = array();
$contents = file_get_contents($path);
$contents = explode("\n", $contents);
foreach($contents as $content)
{
if(!in_array(trim($content), $queuesTemp)) {
$queuesTemp[] = trim($content);
#!/bin/sh
#
# <daemonname> <summary>
#
# chkconfig: <default runlevel(s)> <start> <stop>
# description: <description, split multiple lines with \
# a backslash>
### BEGIN INIT INFO
# Provides:
#!/bin/bash
# Usage: sub mytop [-u (username)] [-p (password)]
# Summary: Watch MySQL Processes / Queries
# Help: Take a snapshot of what mysql queries are running in one second intervals
# Reference: http://akrabat.com/software/the-watch-linux-command-line-tool/
set -e
# Default Username & Password
_MYTOP_PASSWORD="-pYOURPASSWORD" # or "" for no password
@jeffreyroberts
jeffreyroberts / gist:5406798
Created April 17, 2013 18:58
Bash Resolve Sub Directories
resolve_sub_dirs() {
path=""
path_arg="$1"
search="$path_arg/sub-"*
for command in $search; do
if [ -d "$command" ]; then
if [ "$path" != "" ]; then
path="$command:$path"
else