mysql錯誤:ERROR 1175: You are using safe update mode 解決方案

來源:互聯網
上載者:User

標籤:mysql

操作mysql資料庫,刪除表中的某一行資料提示如下錯誤:ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column 

錯誤提示:正在使用安全更新模式,嘗試更新表沒有使用鍵列的where條件;


原因是:mysql有個叫SQL_SAFE_UPDATES的變數,為了資料庫更新操作的安全性,此值預設為1,所以才會出現更新失敗的情況。


舉例如下:

mysql> select * from test;+----+--------+| id | name   |+----+--------+|  1 | anglea ||  2 | baby   ||  3 | jerry  ||  4 | tom    ||  5 | yong   |+----+--------+mysql> delete from test where name=‘yong‘; ERROR 1175 (HY000): You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column


查看設定:

mysql> show variables like ‘sql_safe%‘;+------------------+-------+| Variable_name    | Value |+------------------+-------+| sql_safe_updates | ON    |+------------------+-------+

下面是SQL_SAFE_UPDATES變數為0和1時的取值說明:

 SQL_SAFE_UPDATES有兩個取值0和1, 或ON 和OFF;


  SQL_SAFE_UPDATES = 1,ON時,不帶where和limit條件的update和delete動作陳述式是無法執行的,即使是有where和limit條件但不帶key column的update和delete也不能執行。 

  SQL_SAFE_UPDATES =0,OFF時,update和delete操作將會順利執行。那麼很顯然,此變數的預設值是1。 

 

所以,出現1175錯誤的時候,可以先設定SQL_SAFE_UPDATES的值為0 OFF,然後再執行更新;

以下2條命令都可以;

mysql> set sql_safe_updates=0; 

mysql> set sql_safe_updates=off;    

mysql> show variables like ‘sql_safe%‘;+------------------+-------+| Variable_name    | Value |+------------------+-------+| sql_safe_updates | OFF   |+------------------+-------+mysql> delete from test where name=‘yong‘;Query OK, 1 row affected (0.00 sec)


更改只在當前生效,退出mysql,再次登入後恢複為預設。


本文出自 “模範生的學習部落格” 部落格,請務必保留此出處http://mofansheng.blog.51cto.com/8792265/1694516

mysql錯誤:ERROR 1175: You are using safe update mode 解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.