Last active
August 29, 2015 14:12
-
-
Save tym-xqo/8dbeac1229013e6f1a8a to your computer and use it in GitHub Desktop.
Little script for command-line SSH tunnel to MySQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create this file and save in your home directory | |
# chmod 600 ~/my.safety (won't protect it from root, but better than nothing) | |
[client] | |
user=$USER | |
password=$PASSWD | |
# put your actual MySQL username and password in place of $USER and $PASSWD above. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Tunnel via qa.iadops to OAO MySQL server host | |
# (Note -f forces the ssh command into the background, where we run a sleep command on the remote. | |
# In this way, the tunnel is destroyed after we log out of mysql) | |
# Edit $USER below to your actual username on the ssh server | |
# (for which you might be editing the name as well - I use qa). | |
# NB: Copy a key file to the SSH host first! | |
ssh -f -N -L 3306:e0a31f99e1599c2b6e3fa335f48d5fdf5b2ac052.rackspaceclouddb.com:3306 \ | |
$USER@qa.iadops.com sleep 60; \ | |
mysql --defaults-extra-file=~/my.safety -P 3306 -h 127.0.0.1 | |
# Launch mysql client with user and password passed via --defaults-extra-file setting |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment