• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase
您的位置:首页 > 数据库 >Mysql > MySQL数据库防止人为误操作的实例讲解

MySQL数据库防止人为误操作的实例讲解

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-11

通过本文主要向大家介绍了mysql数据库,mysql数据库教程,mysql数据库下载,jdbc连接mysql数据库,java连接mysql数据库等相关知识,希望本文的分享对您有所帮助

有不少开发人员在操作MySQL数据库的时候都遇到过误操作的情况,例如更新数据库的时候update语句忘记加上where条件,就会造成极为悲剧的结果。本文就针对防止MySQL数据库误操作的方法做出如下详解:

1、mysql帮助说明

# mysql --help|grep dummy  
 -U, --i-am-a-dummy Synonym for option --safe-updates, -U. 
i-am-a-dummy  FALSE
</div>

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

2、指定-U登录测试

# 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
</div>

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

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

# alias mysql='mysql -U' 
# 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 
# echo "alias mysql='mysql -U'" >>/etc/profile 
# . /etc/profile 
# tail -1 /etc/profile 
alias mysql='mysql -U'
</div>

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

</div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 解析mysql中如何获得数据库的大小
  • 5个常用的MySQL数据库管理工具详细介绍
  • 解析mysql 缓存如何使用内存
  • 关于mysql 的时间类型选择
  • 基于mysql体系结构的深入解析
  • 优化mysql数据库的经验总结
  • 基于MySQL数据库复制Master-Slave架构的分析
  • Java实现获得MySQL数据库中所有表的记录总数可行方法
  • 基于mysql数据库的密码问题详解
  • 基于mysql 5.5 设置字符集问题的详解

相关文章

  • 2018-12-05sql 自定义百分比转换小数函数代码
  • 2018-12-05Oracle 11g2的监听器配置教程
  • 2018-12-05mysql进阶(二十四)防御SQL注入的方法总结
  • 2017-05-11mysql远程登录出错的解决方法
  • 2017-05-11Mysql CPU占用高的问题解决方法小结
  • 2018-12-05MySQL之-Replication监控及自动故障切换的详细分析
  • 2018-12-05缓存优化如何使用?总结缓存优化实例用法
  • 2018-12-05php中的implements 使用详解
  • 2017-05-11MySQL中的运算符使用实例展示
  • 2018-12-05mysql如何优化插入记录速度的详情介绍

文章分类

  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase

最近更新的内容

    • php中文件锁解决多进程同时读写一个文件问题的解决方法
    • mysql报错1033 Incorrect information in file: ''''xxx.frm''''问题的解决方法(图)
    • 实例讲解sqlite迁移到mysql脚本的方法_
    • SQL*Plus常用指令
    • 关于Mysql数据库的知识总结
    • sql中用JOIN USING如何简化JOIN ON的实例
    • 教你怎么修改mysql默认最大连接数
    • 教会你完全搞定MySQL数据库 轻松八句话
    • SQL Server 触发器 表的特定字段更新时,触发Update触发器
    • mysql读写分离实战-构建高性能web的代码示例

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有