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_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_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 / 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_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_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 / git_submodule_recursive_checkout.sh
Created September 24, 2013 06:11
Recursively checkout branch for submodules
git submodule foreach --recursive git checkout master
#!/bin/bash
find $1 -size $2c -delete
@jeffreyroberts
jeffreyroberts / raid_file_system_create_format_assemble.sh
Last active December 26, 2015 04:29
A collection of linux raid/file system command snippets
# How to assemble raid device
mdadm --create --verbose /dev/md128 --level=1 --raid-devices=2 /dev/xvdm /dev/xvdn
# Make file system
mkfs -t xfs /dev/md128
# How to re-assemble
mdadm --assemble --verbose /dev/md128 /dev/xvdm /dev/xvdn
# Get UUID
@jeffreyroberts
jeffreyroberts / git_list_files_from_commit.sh
Created October 30, 2013 18:02
list files modified from a commit
#!/bin/bash
# http://stackoverflow.com/questions/424071/list-all-the-files-for-a-commit-in-git
git diff-tree --no-commit-id --name-only -r $1
# Colors
DARK_PURPLE="\[\033[1;34m\]"
GREEN="\[\033[0;32m\]"
GREY="\[\033[1;30m\]"
NORMAL="\[\033[0m\]"
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
# Git shortcuts
alias gci='git commit'