Skip to content

Instantly share code, notes, and snippets.

@sokil
Last active May 5, 2016 06:19
Show Gist options
  • Save sokil/ef2866b7133784b8ca67 to your computer and use it in GitHub Desktop.
Save sokil/ef2866b7133784b8ca67 to your computer and use it in GitHub Desktop.

Get list from mysql

mysql --defaults-extra-file=~/credentials.cnf -Nsqe "SELECT SQL_NO_CACHE * FROM ..." | pv -l | gzip > rows.gz

Get list from mysql, based on other list in file

zcat rows.gz | awk '{print $1}' | xargs -L 1000 | sed 's/ /\\",\\"/g' | xargs -I {} mysql --defaults-extra-file=~/credentials.cnf -Nsqe "SELECT SQL_NO_CACHE otherId FROM table WHERE id IN (\"{}\")" | pv -l | sort | uniq -c | sort -rn > otherIds

credentials.cnf:

[client]
host=xxx
database=xxx
user=xxx
password=xxx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment