Tools for 1.MySQL: Navicat
Advantages: Convenient
2. Importing the database
Mysqldump-u User name-p password database name > Export corpus path #结构 + data
Mysqldump-u User name-p password-d database name > Export Corpus path #结构
Export Database Export
Mysqldump-u User name-p password database name < export corpus path #结构 + data
Mysqldump-u User name-p password-d database name < export corpus path #结构
MySQL also has some complicated query methods * * * *
3.python Operational Database
Https://pypi.python.org/pypi
PIP3 Install Pymysql
#下载本地
#解压到执行目录
#python2, no pip command by default
#python3, default comes with PIP3 command
#C: \python35\scripts=== executable file
There may be some problems
C:\USERS\ADMINISTRATOR>CD C:\Python35\Scripts
C:\PYTHON35\SCRIPTS>PIP3 install MySQL
Fatal error in launcher:unable to create process using ' "'
c:\python35\scripts>python-m pip install--upgrade pip---need to be followed by a new
C:\PYTHON35\SCRIPTS>PIP3 install pymysql=== with new after installation Pymysql
Collecting Pymysql
Downloading PYMYSQL-0.7.11-PY2.PY3-NONE-ANY.WHL (78kB)
51% |████████████████▋| 40kB 136kb/s eta 0:0 64% |████████████████████▊| 51kB 152kb/s ETA 77% |█████████████████████████| 61kB 182kb/s 90% |█████████████████████████████| 71kB 94k 100% |████████████████████████████████| 81kB 104kb/s
Installing collected Packages:pymysql
Successfully installed pymysql-0.7.11
-----This is the installation method of Python3 operation MySQL
There is also a mysqldb (Python3 incompatible), the same installation method.
4. Execute SQL statements
1 #_author_:lizebo2 #DATE:2017/11/5 00053 4 " "5 steps to execute SQL, 7 parts6 " "7 ImportPymysql8 #Get Connected9Con=pymysql.connect (host='127.0.0.1', port=3306,user='Root', password='1234', database='Test', charset='UTF8')Ten #Get Cursors OneCusor=con.cursor () A #Execute SQL -Cusor.execute ("INSERT INTO TB1 (Nid,name) VALUES (2, ' liuting ');") - #Submit the Con.commit () - #Close - cusor.close () - con.close () + " " - 7 steps for MySQL database connection operation in Python + " "View Code
5. About SELECT
1 #_author_:lizebo2 #DATE:2017/11/5 00053 4 ImportPymysql5 6Con=pymysql.connect (host='localhost', port=3306,database='Test', user='Root', password='1234', charset='UTF8')7 8Curor=con.cursor ()9 TenReturns=curor.execute ('SELECT * from UserInfo') One Con.commit () A #If it is a select, it is necessary to use Curor fetchall,fetchone,fetchmany to make queries; the other additions, deletions, and modifications are the same, just select comparison - #Special - curor.close () the con.close () - Print(Curor.fetchone ()) - Print(Curor.fetchmany (3)) - Print(Curor.fetchall ())View Code
MySQL complex query, connection database