How to connect to the mysql database using python2.7 on win7, win7python2.7
I. Install the MySQL-python driver
Pip install mysql
2. Connect to the MySQL server's test Database
#! /Usr/bin/python #-*-coding: UTF-8-*-import mysql. connectorif _ name _ = "_ main _": # Open the database connection conn = mysql. connector. connect (host = 'IP', user = 'root', passwd = '000000', db = 'dbname') # Use the cursor () method to obtain the operation cursor = conn. cursor () # Use the execute method to execute the SQL statement cursor.exe cute ('select * from tset where 1 = 1') # Table query # Use the fetchone () method to obtain a database. Values = cursor. fetchall () print (values) # close database connection cursor. close ()
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.