您好,登錄后才能下訂單哦!
防止人為誤操作MySQL數據庫技巧有哪些,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
防止人為誤操作MySQL數據庫技巧
1、mysql幫助說明
[oldboy_c64 ~]# mysql --help|grep dummy -U, --i-am-a-dummy Synonym for option --safe-updates, -U. i-am-a-dummy FALSE
在mysql命令加上選項-U后,當發出沒有WHERE或LIMIT關鍵字的UPDATE或DELETE時,mysql程序就會拒絕執行
2、指定-U登錄測試
[oldboy_c64 ~]# mysql -uroot -poldboy123 -S /data/3306/mysql.sock -U Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 5.5.32-log MySQL Community Server (GPL) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> delete from oldboy.student; 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> quit Bye
提示:不加條件無法刪除,目的達到。
3、做成別名防止老大和DBA誤操作
[oldboy_c64 ~]# alias mysql='mysql -U' [oldboy_c64 ~]# mysql -uroot -poldboy123 -S /data/3306/mysql.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 15 Server version: 5.5.32-log MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> delete from oldboy.student; 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> delete from oldboy.student where Sno=5; Query OK, 1 row affected (0.02 sec) mysql> quit Bye [oldboy_c64 ~]# echo "alias mysql='mysql -U'" >>/etc/profile [oldboy_c64 ~]# . /etc/profile [oldboy_c64 ~]# tail -1 /etc/profile alias mysql='mysql -U'
結論:
在mysql命令加上選項-U后,當發出沒有WHERE或LIMIT關鍵字的UPDATE或DELETE時,mysql程序拒絕執行
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。