Skip to content

Instantly share code, notes, and snippets.

@KingPin
Created July 25, 2017 00:17
Show Gist options
  • Save KingPin/775559b699b45e7cde0ee7dab1095c7e to your computer and use it in GitHub Desktop.
Save KingPin/775559b699b45e7cde0ee7dab1095c7e to your computer and use it in GitHub Desktop.
python connect to mysqldb and select
import MySQLdb
host = '10.10.10.10'
user = 'root'
password = 'password'
port = 3306
db = 'lm'
dbc = MySQLdb.Connection(
host=host, user=user, passwd=password, port=port, db=db
)
dbc.query("""SELECT * FROM lm""")
output = dbc.store_result()
for i in range(output.num_rows()):
print(output.fetch_row())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment