Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: How to turn one database to read-only?

I need to turn one database into read-only, so I can clone the database and make schema modifications on the clone before we switch the application to the new database. I know the way to turn the MySQL database server into read-only, but that will make it impossible to do the schema change on the new cloned database.

I searched and didn't find any answer. I suspect there is no such feature. In that case, what would you recommend for upgrading a live database without pausing the service?

like image 990
ycseattle Avatar asked Jun 04 '10 22:06

ycseattle


People also ask

How do I turn off read only in mysql?

To turn it off, you can use the SET GLOBAL statement as shown below: SET GLOBAL read_only=0; The option should now be turned off.

How do I change a read only table in mysql?

Hold down Ctrl and press Enter to execute the SQL. You can edit the SQL afterward when you run it without getting an error. Before that, run a SELECT query to view the table data. The "Read Only" text has changed to a disabled Apply button.

How do you make MariaDB read only?

If read_only is set to 1, then the SET PASSWORD statement is limited only to users with the SUPER privilege (<= MariaDB 10.5. 1) or READ ONLY ADMIN privilege (>= MariaDB 10.5. 2). Attempting to set the read_only variable to 1 will fail if the current session has table locks or transactions pending.


2 Answers

You could revoke write access for specific users during this period.

like image 56
k_b Avatar answered Sep 23 '22 17:09

k_b


You could revoke update/insert/delete privilege on the account that is using that database. If the application is logged in as root then you have bigger problems on your hands.

like image 42
rook Avatar answered Sep 25 '22 17:09

rook