Innodb has come up (in mysql-5.6.7 release candidates onwards) with changes for running server instance in read only mode. It makes entire server instance as read only. You cannot selectively make certain table as read only (Not at table level). Feature is introduced by considering
(1) Innodb can be run from read only media like DVD/CD etc
(2) User can explicitly set instance in read only mode though its on read-write media
Start server in Read Only Mode:"--innodb-read-only" boolean configuration parameter is introduced
for starting server in read only mode. Server will not start in
read only mode if it was not shutdown cleanly/safely earlier.
User must pass/set parameter which try to create file/log on read/write media. Else server will not start. Like , user will need to pass "--pid-file=<path on non RO media>" and/or "--event-scheduler=disabled" if datadir is on read only media etc
There exits a "--read-only" variable which differs from newly added --innodb-read-only.[If datadir is without write permission then server will give error even when --read-only option is provided ]--read-only
1) When datadir is RW and server started with --read-only : root/super user have permission for operations. Other users will not have permission to change.
2) When datadir is on read only media and server started with --read-only : all operations blocked for users (including root).
--innodb-read-only
1) When datadir is RW and server started with --innodb-read-only :
a) No user will be able to modify. DCL(like create user/grant/revoke etc) commands will work for root user. (It's non innodb issue)
b) When both --read-only and --innodb-read-only are given, then --innodb-read-only takes effect.(As I checked that root user can not do DML/DDL but can perform DCL )
2) When datadir is on read only media and server started with --read-only : all operations blocked for users (including root).
How it works is listed here in short.
Feature Testing Approach
Important area to test was
a) Data can not be changed in read only mode
b) user able to run instance on read only media
MTR framework was useful for (a) , where test itself creates initial data and restart sever by passing "--innodb-read-only". Example ,
# Create/Preapare Data
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--shutdown_server 10
--source include/wait_until_disconnected.inc
# Do something while server is down
--enable_reconnect
# Write file to make mysql-test-run.pl start up the server again
--exec echo "restart: --innodb-read-only " > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--source include/wait_until_connected_again.inc
# Check for error on modfying data
Checkout stopping server during test for other details
(b) was carried out by making USB device write protected. (instead of using DVD/CD). Performed following manual steps/checks
- Create binaries and data on USB device
- Make it write protected (so as it behave as RO )
- Start server with --innodb-read-only and check data can not modified.
Steps to make USB write protected (make work as read only)
Unix :
Plugin USB , unmout it. (e.g unmount /dev/sdb1)
sudo blockdev --setro /dev/sdb1 (for removing write permissions)
Mount USB. Now ,USB will be write protected.
Windows:
Click Start ---> Select Run , Type regedit.exe
Navigate to the registry key (HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\StorageDevicePolicies).Create if it does not exists.
Add/create a new DWORD called WriteProtect with value as 1 (On pluging in USB , user will not be able to write>)
SET WriteProtect DWORD to 0 , to enable writing
Author: Vinay Fisrekar