Skip to content

Instantly share code, notes, and snippets.

@dodo5522
Last active March 13, 2017 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dodo5522/78f234aa7945a3b81528dfa8330ea70a to your computer and use it in GitHub Desktop.
Save dodo5522/78f234aa7945a3b81528dfa8330ea70a to your computer and use it in GitHub Desktop.
SQLAlchemy + PyMySQLでのデータ取得方法
#!/usr/bin/env python
import sys
import sqlalchemy as sa
if __name__ == "__main__":
engine = sa.create_engine(
"mysql+pymysql://{USER}:{PASS}@{HOST}/{DB}?charset=utf8".format(
USER=sys.argv[1], PASS=sys.argv[2], HOST=sys.argv[3], DB=sys.argv[4]))
ret = engine.execute("select account.id, account.name_, ability.detail from account inner join ability on account.id = ability.user_id where ability.detail regexp '.*子.*';")
dat = ret.fetchall()
print(dat[:5])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment