首页 技术 正文
技术 2022年11月6日
0 收藏 426 点赞 419 浏览 1899 个字

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://oldboy.blog.51cto.com/2561410/1321061

防止人为误操作MySQL数据库技巧一例
(本题来自老男孩培训内部学生问题,属于数据库安全技巧)

在若干年前,老男孩亲自遇到一个“命案”,老大登录数据库update一个记录,结果忘了加where,于是悲剧发生了,这使得我对MySQL的增量恢复熟练度远超过其他的知识点,同时也很在意对内的数据库安全,并且每次讲课讲到此处,都会给学生讲这个领导的故事。

1、mysql帮助说明

123 [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登录测试

12345678910111213 [oldboy_c64 ~]# mysql -uroot -poldboy123 -S /data/3306/mysql.sock -UWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 14Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.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 columnmysql> quitBye

提示:不加条件无法删除,目的达到。

3、做成别名防止老大和DBA误操作

12345678910111213141516 [oldboy_c64 ~]# alias mysql='mysql -U'[oldboy_c64 ~]# mysql -uroot -poldboy123 -S /data/3306/mysql.sockWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 15Server 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 columnmysql> delete from oldboy.student where Sno=5;Query OK, 1 row affected (0.02 sec)mysql> quitBye[oldboy_c64 ~]# echo "alias mysql='mysql -U'" >>/etc/profile[oldboy_c64 ~]# . /etc/profile[oldboy_c64 ~]# tail -1 /etc/profilealias mysql='mysql -U'

结论:
在mysql命令加上选项-U后,当发出没有WHERE或LIMIT关键字的UPDATE或DELETE时,mysql程序拒绝执行

本文出自 “老男孩linux培训” 博客,请务必保留此出处http://oldboy.blog.51cto.com/2561410/1321061

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289