Skip to content

Instantly share code, notes, and snippets.

@disciplezero
Created April 14, 2015 16:23
Show Gist options
  • Save disciplezero/93bcb7bc069633f89e0d to your computer and use it in GitHub Desktop.
Save disciplezero/93bcb7bc069633f89e0d to your computer and use it in GitHub Desktop.
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment