Skip to content

Instantly share code, notes, and snippets.

@ffeast
ffeast / mysql_table_sizes.sql
Created June 21, 2016 19:02
Mysql table sizes in the selected database
SELECT
table_name,
round(((data_length + index_length) / 1024 / 1024), 2) size_mb
FROM information_schema.TABLES
WHERE table_schema = (SELECT database())
ORDER BY size_mb DESC;
@ffeast
ffeast / mysql_nopk_non_innodb_ftext_or_spatial.sh
Last active June 29, 2016 19:54
Query that helps identify tables with missing PK as well as tables with FULLTEXT or SPATIAL functionality
# taken from http://severalnines.com/blog/field-live-migration-mmm-mariadb-galera-cluster
SELECT DISTINCT
CONCAT(t.table_schema,'.',t.table_name) as tbl,
t.engine,
IF(ISNULL(c.constraint_name),'NOPK','') AS nopk,
IF(s.index_type = 'FULLTEXT','FULLTEXT','') as ftidx,
IF(s.index_type = 'SPATIAL','SPATIAL','') as gisidx
FROM information_schema.tables AS t
LEFT JOIN information_schema.key_column_usage AS c
ON (t.table_schema = c.constraint_schema AND t.table_name = c.table_name
@ffeast
ffeast / public_ip.sh
Created April 22, 2016 09:38
public ip
curl ipecho.net/plain; echo
@ffeast
ffeast / local_http_server.sh
Created March 13, 2016 08:12
Installation-free http server to list the current dir
python -m SimpleHTTPServer 8000
@ffeast
ffeast / mysql_kill_queries.sql
Created February 11, 2016 10:25
Mysql kill queries
/* run \. /tmp/mysql_victims.txt after executing this query */
SELECT
concat('KILL ', id, ';')
FROM
information_schema.processlist
WHERE
user='victim' AND time > 60
INTO OUTFILE '/tmp/mysql_victims.txt';
@ffeast
ffeast / mysql_domain_socket.sh
Created December 30, 2015 06:41
Mysql connection to domain socket over ssh
socat "UNIX-LISTEN:your_local_path/mysql.sock,reuseaddr,fork" \
EXEC:'ssh user@remote-host socat STDIO UNIX-CONNECT\:/your_server_path/mysql.sock"
mysql -S your_local_path/mysql.sock -u user
@ffeast
ffeast / mysql_db_sizes.sql
Last active January 13, 2016 20:05
Mysql database sizes
SELECT
table_schema "Data Base Name",
sum( data_length + index_length ) / 1024 /
1024 "Data Base Size in MB",
sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM
information_schema.TABLES
GROUP BY table_schema ;
@ffeast
ffeast / mysql_tcpdump.sh
Last active March 8, 2022 09:04
Mysql traffic tcpdump one-liner
# a handy one-liner to print out sql queries if you wouldn't like to enable
# queries logging in mysql server itself
tcpdump -i lo -s 0 -l -w - dst port 3306 | strings | perl -e '
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER)/i) {
if (defined $q) { print "$q\n\n"; }
$q=$_;
} else {
$_ =~ s/^[ \t]+//; $q.=" $_";
}