Mysql DBA 進階營運學習筆記-DML之修改表中的資料實戰

來源:互聯網
上載者:User

標籤:修改   sele   恢複   文法   cal   mat   select   .sql   pre   

9.10 修改表中的資料

9.10.1 修改表中指定條件固定列的資料

1.命令文法:update 表名 set 欄位=新值,….where 條件(一定要注意條件)

2.修改指定的列欄位的內容

a.查看要修改的表

[email protected] 02:3907->select * from test;+----+-----------+| id | name  |+----+-----------+|  1 | wwnwan||  2 | zbf   ||  3 | lisi  ||  4 | woshishei ||  5 | nimei |+----+-----------+

b.修改id為3的行的名字為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 修改表中所有行的資料

嚴重案列(可能誤操作導致資料對視)

a.不帶條件更改所有表的資料

[email protected] 02:5352->update test set name=‘tiejun‘;

不加條件要十分小心,專業做法,一定要問開發確認,如果你發給開發的語句要括弧註明,防止DBA誤會。

b.更改了所有資料

[email protected] 03:0109->select * from test;+----+--------+| id | name   |+----+--------+|  1 | tiejun ||  2 | tiejun ||  3 | tiejun ||  4 | tiejun ||  5 | tiejun |+----+--------+

c.用備份的資料恢複

之前已經備份過了,這裡就不重新備份了

[[email protected] ~]# mysql -usystem -pzbf666 wwn < /opt/zbf_bak.sql

這裡的wwn是資料庫不是表。

[email protected] 03:1044->select * from test;+----+-----------+| id | name  |+----+-----------+|  1 | wwnwan||  2 | zbf   ||  3 | lisi  ||  4 | woshishei ||  5 | nimei |+----+-----------+

Mysql DBA 進階營運學習筆記-DML之修改表中的資料實戰

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.