如何通过命令行将MySQL临时设置为只读? [英] How do I set MySQL temporarily to read-only through the command line?

查看:650
本文介绍了如何通过命令行将MySQL临时设置为只读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个bash脚本,其中包括从MySQL数据库收集一些数据。我的MySQL用户有写权限,但出于安全原因,我想临时将其设置为只读状态。

I'm creating a bash script which, among other things, gathers some data from a MySQL database. My MySQL user has write privileges, but for safety reasons I would like to temporarily set it to a read only state. Is it possible to do this from a command line?

推荐答案

要回答你原来的问题,你可以把整个数据库读取只有模式由此命令:

To answer your original question, you can put your whole database to read only mode by this commands:

FLUSH TABLES WITH READ LOCK;
SET GLOBAL read_only = 1;

并返回正常模式:

SET GLOBAL read_only = 0;
UNLOCK TABLES;

注意这是一个操作,会对数据库的行为产生深远的影响。因此,在执行此操作之前,请阅读以上命令的可用文档。一个更常见的方法是从特定用户撤销DML权限,然后授予他们。

Beware that this is an operation which will have deep impact on the behavior of the database. So before executing this, read the available documentation to the commands above. A much more common way is to revoke DML privileges from the specific user and afterwards grant them back.

这篇关于如何通过命令行将MySQL临时设置为只读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆