--------------------python to control the MySQL API--------------------
#import mysqldb: Referencing the corresponding development package
#conn =mysqldb.connect
(host= ' localhost ', user= ' root ', passwd= ' root ', db= ' test ', port=3306): Create data
Library connections
#cur =conn.cursor (): Creating Cursors
#cur. Execute (Self, query, args): Executes a single SQL statement, receiving parameters for the SQL statement itself and
The list of parameters used, the return value is the number of rows affected
#cur. Executemany (self, Query, args): Executes a heads-up SQL statement, but repeats the parameter list
parameter, the return value is the number of rows affected
#cursor用来执行命令的方法:
#cur. Commit (): Commit. When you modify a database, you need to use commit on the database after you perform the operation
Make a modification operation
#cur. Rollback (): Rollback
#cursor用来接受返回值的方法:
#cur. Fetchall (self): receives all the returned result rows.
#cur. Fetchmany (Self, Size=none): Receives a size bar that returns the result row. If the value of size is greater than the return
The number of result rows, the Cursor.arraysize data is returned.
#cur. Fetchone: Fetchone (self): Returns a result row.
#cur. RowCount: Gets the number of bars for the result set.
#cur. Description: Gets the description information for the connection object.
#cur. RowCount: Gets how many rows are affected.
#scroll (self, int, mode= ' relative '):
int: Number of rows moved, integer; in relative mode, positive numbers move down, negative values move up.
Mode: The moving pattern, default is relative, relative mode, acceptable absoulte, absolute mode.
#cur. Close (): Close the cursor
#conn. Close (): Close operation for database connection
#except mdb. Error,e:
Conn.rollback ()
--------------------Configure the operating system where MySQL operates remote service operations--------------------
1. Create a new User:
Mysql-uroot-p: Log in to MySQL
Use MySQL: Open the corresponding MySQL database
Insert into Mysql.user (Host,user,password) values
("localhost", "Test", "1234"): Create a user ("localhost" here, means that the user only
Can log on locally and not remotely on another machine. If you want to log in remotely,
Change "localhost" to "%", which means you can log on on any computer. You can also designate a machine to
to Telnet. )
2. Permissions:
(1) This means that all tables in the database are licensed to the user
Grant all privileges the testdb.* to [email protected] identified by
' 1234 ' with GRANT option
Grant Select,delete,update,create,drop on * * to [email protected] "%" identified
By "1234";
(2) flush privileges;: Refresh System Permissions Table
Note: Identified by is followed by your MySQL root user password
The test user has Select,delete,update,create,drop permissions on all databases.
@ "%" indicates authorization for all non-local hosts, excluding localhost. (The localhost address is set to
127.0.0.1)
Authorization to localhost: Plus one sentence grant all privileges on testdb.* to
[email protected] identified by ' 1234 ';
3. Finally, just restart MySQL.
/etc/init.d/mysql restart
----------------------the settings from Ubuntu connected to the MySQL under Win--------------------
mysql-uroot-p use MySQL;
Update user Set host = '% ' where user = ' root ';
Flush privileges;
Python control of MySQL API notebooks