Created
July 25, 2017 00:17
-
-
Save KingPin/775559b699b45e7cde0ee7dab1095c7e to your computer and use it in GitHub Desktop.
python connect to mysqldb and select
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
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