Skip to content

Instantly share code, notes, and snippets.

@disciplezero
disciplezero / getPrimaryKey
Created April 14, 2015 16:23
Get Primary MySQL Key
#!/bin/bash
HOST=$1
USER=$2
PASS=$3
DATABASE=$4
TABLE=$5
# head/tail to get the second line. The first column is the table, so we delete everything afterwards.
mysql -h $HOST -u $USER --password=$PASS $DATABASE -e 'show columns from '"$TABLE"' where `Key`="Pri";'| head -2 |tail -1|sed "s/\t.*//g"
@disciplezero
disciplezero / convertTable
Last active August 29, 2015 14:19
convertTable from mysql to redshift
#!/bin/bash
RDSHOST=$1
RDSUSER=$2
RDSPASS=$3
RDSDB=$4
PGHOST=$5
PGUSER=$6
@disciplezero
disciplezero / getMaxKey
Last active August 29, 2015 14:19
getMaxKey
#!/bin/bash
HOST=$1
USER=$2
PASS=$3
TABLE=$4
KEY=$5
# head/tail to get the second line. The first column is the field, so we delete everything afterwards.
mysql -h $HOST -u $USER --password=$PASS sw -e 'select '"$KEY"' from '"$TABLE"' order by '"$KEY"' desc limit 1'| head -2 |tail -1|sed "s/\t.*//g"