python The record operation of is particularly important , It's not just about the subsequent development , We can avoid the mistakes of relativity , Let's have a look !

One Introduce

MySQL Data manipulation : DML

========================================================

stay MySQL In management software , Can pass SQL Statement DML Language to realize the operation of data , Include

Use INSERT Realize the insertion of data

UPDATE Update the data

Use DELETE Realize the deletion of data

Use SELECT Query data and .

========================================================

This section includes :

insert data

Update data

Delete data

Query data

Two insert data INSERT

  1. Insert full data ( Order insert )

Grammar 1 :

INSERT INTO Table name ( Field 1, Field 2, Field 3… Field n) VALUES( value 1, value 2, value 3… value n);

Grammar II :

INSERT INTO Table name VALUES ( value 1, value 2, value 3… value n);2. Specify the field to insert data

grammar :

INSERT INTO Table name ( Field 1, Field 2, Field 3…) VALUES ( value 1, value 2, value 3…);3. Insert multiple records

grammar :

INSERT INTO Table name VALUES

( value 1, value 2, value 3… value n),

( value 1, value 2, value 3… value n),

( value 1, value 2, value 3… value n);

  1. Insert query results

grammar :

INSERT INTO Table name ( Field 1, Field 2, Field 3… Field n)

SELECT ( Field 1, Field 2, Field 3… Field n) FROM surface 2

WHERE …;

3、 ... and Update data UPDATE

grammar :

UPDATE Table name SET

Field 1= value 1,

Field 2= value 2,

WHERE CONDITION;

Example :

UPDATE mysql.user SET password=password(‘123’)

where user=’root’andhost=’localhost’;

Four Delete data DELETE

grammar :

DELETE FROM Table name

WHERE CONITION;

Example :

DELETE FROM mysql.user

WHERE password=’’;

practice :

to update MySQL root User password is mysql123

Delete except those logged in locally root All users except users

5、 ... and Query data SELECT

Single table query :http://www.cnblogs.com/linhaifeng/articles/7267592.html

Multi-table query :http://www.cnblogs.com/linhaifeng/articles/7267596.html

6、 ... and Rights management

python Introductory tutorial 13-04 ( Grammar entry records related operations )
# Authorization Form user# Permission to release this form , in the light of : All the data , All tables under all libraries , And all the fields under the table db# Permission to release this form , in the light of : A database , All tables in the database , And all the fields under the table tables_priv# Permission to release this form . in the light of : A table , And all the fields in the table columns_priv# Permission to release this form , in the light of : A field # Explain according to the picture :user: release db1,db2 And all that it contains

db: release db1, And its db1 All that is included

tables_priv: release db1.table1, And all the

columns_prive: release db1.table1.column1, Only this field

Related permission Operation :

# Create user create user’egon’@‘1.1.1.1’identified by’123’;

create user ‘egon’@'192.168.1.%‘identified by’123’;

create user ‘egon’@’%‘identified by’123’;# to grant authorization : On the folder , The file , View help for the permission of a field in the file :help grant

Common permissions are :select,update,alter,delete

all It can represent other than grant All rights except # Authorization for all libraries :.grant select on . to’egon1’@‘localhost’identified by’123’;# Only in user It can be found in the table egon1 User select Permissions are set to Y# For a database :db1.grant select on db1. to’egon2’@’%‘identified by’123’;# Only in db It can be found in the table egon2 User select Permissions are set to Y# For a table :db1.t1grant select on db1.t1 to’egon3’@’%‘identified by’123’;# Only in tables_priv It can be found in the table egon3 User select jurisdiction # For a certain field :mysql> select from t3;±-----±------±-----+| id | name | age |±-----±------±-----+| 1 | egon1 | 18 || 2 | egon2 | 19 || 3 | egon3 | 29 |±-----±------±-----+grant select (id,name),update (age) on db1.t3 to ‘egon4’@‘localhost’identified by’123’; # Can be in tables_priv and columns_priv See the corresponding permissions in mysql> select fromtables_priv where user=‘egon4’\G*********************** 1. row *************************** Host: localhost

Db: db1

User: egon4

Table_name: t3

Grantor: root@localhost

Timestamp: 0000-00-00 00:00:00 Table_priv:

Column_priv: Select,Update

row inset (0.00 sec)

mysql> select fromcolumns_priv where user=‘egon4’\G************************** 1. row *************************** Host: localhost

Db: db1

User: egon4

Table_name: t3

Column_name: id

Timestamp: 0000-00-00 00:00:00Column_priv: Select*************************** 2. row *************************** Host: localhost

Db: db1

User: egon4

Table_name: t3

Column_name: name

Timestamp: 0000-00-00 00:00:00Column_priv: Select*************************** 3. row *************************** Host: localhost

Db: db1

User: egon4

Table_name: t3

Column_name: age

Timestamp: 0000-00-00 00:00:00Column_priv: Update

rows inset (0.00 sec)# Delete permission revoke select on db1.*from’egon’@’%’;