您好,欢迎访问一九零五行业门户网

MySQL之——如何防止人为误操作MySQL数据库

今天,一位原公司的同事,打电话来问我说误操作了数据库数据,如何恢复。他原本的想法是登录数据库update一个记录,结果忘了加where,于是悲剧发生了。今天,我们不讲如何恢复误操作的数据,我们讲讲如何从源头上避免这样的问题,这才是避免类似问题的根本措施。好了。我们直接进入主题:
1、mysql帮助说明
[root@liuyazhuang151 ~]# 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登录测试
[root@liuyazhuang151 ~]# mysql -uroot -proot -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误操作
[root@liuyazhuang151 ~]# alias mysql='mysql -u' [root@liuyazhuang151 ~]# 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 [root@liuyazhuang151 ~]# echo "alias mysql='mysql -u'" >>/etc/profile [root@liuyazhuang151 ~]# . /etc/profile [root@liuyazhuang151 ~]# tail -1 /etc/profile alias mysql='mysql -u'
4、结论:
在mysql命令加上选项-u后,当发出没有where或limit关键字的update或delete时,mysql程序拒绝执行
以上就是mysql之——如何防止人为误操作mysql数据库的内容。
其它类似信息

推荐信息