Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set MySQL temporarily to read-only through the command line?

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?

like image 850
Jimmy C Avatar asked Aug 23 '13 10:08

Jimmy C


People also ask

How do I change the display settings in MySQL command line?

In Microsoft Windows mysql Command Prompt, Right-click on the prompt boarder and select Properties, now select the Layout tab and change the Window Size width or screen buffer width to a more suitable view.


1 Answers

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; 

and back to normal mode with:

SET GLOBAL read_only = 0; UNLOCK TABLES; 

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.

like image 92
Flo Doe Avatar answered Oct 12 '22 01:10

Flo Doe