Skip to content

Instantly share code, notes, and snippets.

@imranbhullar
Created March 12, 2018 04:50
Show Gist options
  • Save imranbhullar/3363a91cd4fdc2e58bc15c532310c101 to your computer and use it in GitHub Desktop.
Save imranbhullar/3363a91cd4fdc2e58bc15c532310c101 to your computer and use it in GitHub Desktop.
Using pexpect to play with mysql.
import pexpect
child = pexpect.spawn ('mysql -umyuser -pmysupersecret -hxxx.xxx.xxx.xxx')
child.expect ('mysql> ')
child.sendline ('show databases;\n')
child.expect ('mysql> ')
print child.before
child.expect('mysql> ')
child.sendline ('show processlist;')
child.expect ('mysql> ')
print child.before
child.sendline ('quit')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment