9.10 modifying data in a table
9.10.1 modifying the data in a fixed column of a specified condition in a table
1. Command syntax: Update table name SET field = new value,.... where condition (be sure to note the condition)
2. Modify the contents of the specified row field
A. Viewing the table to be modified
[email protected] 02:3907->select * from test;+----+-----------+| id | name |+----+-----------+| 1 | wwnwan|| 2 | zbf || 3 | lisi || 4 | woshishei || 5 | nimei |+----+-----------+
B. Change the name of the line with ID 3 to Tiejun
[email protected] 02:5335->update test set name=‘tiejun‘ where id=3;Query OK, 1 row affected (0.10 sec)Rows matched: 1 Changed: 1 Warnings: 0[email protected] 02:5348->select * from test;+----+-----------+| id | name |+----+-----------+| 1 | wwnwan|| 2 | zbf || 3 | tiejun|| 4 | woshishei || 5 | nimei |+----+-----------+
9.10.2 modifying data for all rows in a table
Serious case (possible misoperation causes data to be looked into)
A. Changing data for all tables without conditions
[email protected] 02:5352->update test set name=‘tiejun‘;
Do not add conditions to be very careful, professional practice, be sure to ask the development of confirmation, if you send the development of the statement to be marked in parentheses, to prevent the DBA misunderstanding.
B. All data has been changed
[email protected] 03:0109->select * from test;+----+--------+| id | name |+----+--------+| 1 | tiejun || 2 | tiejun || 3 | tiejun || 4 | tiejun || 5 | tiejun |+----+--------+
C. Restoring with backed-up data
It has been backed up before and is not backed up again.
[[email protected] ~]# mysql -usystem -pzbf666 wwn < /opt/zbf_bak.sql
The WWN here is that the database is not a table.
[email protected] 03:1044->select * from test;+----+-----------+| id | name |+----+-----------+| 1 | wwnwan|| 2 | zbf || 3 | lisi || 4 | woshishei || 5 | nimei |+----+-----------+
Mysql DBA Advanced Operations Learning note-DML Data combat in the modified table