1 MySQL1.1 Installation
Download: mysql-python-1.2.3.win-amd64-py2.7 direct installation, requires Python2.7 (Python version 2.7 required)
Verification: Import MYSQLDB no error can be
1.2 Basics
1 Connection database:mysqldb. Connect(host= ",port=", user= ", passwd=", db= ")
Class Connection (_mysql.connection):
"" "MySQL Database Connection Object" "
Default_cursor = cursors. Cursor
def __init__ (self, *args, **kwargs):
"""
Create a connection to the database. It is strongly recommended
That's only use keyword parameters. Consult the MySQL C API
Documentation for more information.
Host
String, host to connect
User
String, user to connect as
passwd
String, password to use
Db
String, database to use
Port
Integer, TCP/IP port to connect to
CharSet
If supplied, the connection character set would be changed
To this character set (MySQL-4.1 and newer). This implies
Use_unicode=true.
"""
< span class= "str" >< Span class= "pun" >2 Operations database: First you need to get a cursor object and then use cursor methods to execute SQL
- execute ( sql , args): Executes a single SQL statement, receives parameters as SQL statement and parameter list, returns the number of rows affected
def execute (self, query, Args=none):
"" "Execute a query.
Query--string, query to execute on server
& nbsp; args--optional sequence or mapping, parameters to use with query.
note:if args is a sequence, then%s must be used as the
; parameter placeholder in the query. If A mapping is used,
% (key) s must be used as the placeholder.
Returns Long integer rows affected, if any
""
- Callproc (procname, args): Executes a stored procedure, receives a parameter that is a stored procedure name and a parameter list, and returns a value of the number of rows affected
- Executemany (sql, args): Executes a heads-up SQL statement, but repeats the parameters in the list of parameters, with the returned value being the number of rows affected
- < span class= "str" >< Span class= "pun" >nextset (): Move to next result set
< span class= "str" >< Span class= "pun" >3 receive return value: Also use cursor object method to receive
- fetchone (): Returns a result
- Fetchall (): Return all results
- Fetchmany (Size=none): Returns the result of the size bar. If the value of size is greater than the number of result rows returned, the Cursor.arraysize bar data is returned
- Scroll (value, mode= ' relative '): Moves the pointer to a line.
- < span class= "str" >< span class= "str" >< Span class= "pun" >< Span class= "pun" >mode= ' relative ' means move the value bar from the current row
- Mode= ' Absolute ' indicates that the value bar is moved from the first row of the result set.
4 Closing the database: need to closecursor Object AndConnectObject
3 Selenium Python Database and files