mysql 从设置只读

read-only
该选项限制普通用户只有select权限

--read_only         Make all non-temporary tables read-only, with the 
                               exception for replication (slave) threads and users with 
                               the SUPER privileg

使所有的非temporary表为只读,除了复制的threads和超级用户

超级用户:
SUPER privilege :

The SUPER privilege enables an account to use CHANGE MASTER TO , KILL or mysqladmin kill to kill threads belonging to other accounts (you can always kill your own threads), PURGE BINARY LOGS , 

configuration changes using SET GLOBAL to modify global system variables, the mysqladmin debug command, enabling or disabling logging, performing updates even if the read_only system variable is 

enabled, starting and stopping replication on slave servers, specification of any account in the DEFINER attribute of stored programs and views, and enables you to connect (once) even if the 

connection limit controlled by the max_connections system variable is reached.

To create or alter stored routines if binary logging is enabled, you may also need the SUPER privilege, as described in Section 18.6, “Binary Logging of Stored Programs” 


超级权限可以让一个账户使用CHANGE MASTER TO ,KILL或者mysqladmin kill 来kill 进程属于另外的账户(你也可以kill 你自己的threads),PURGE BINARY LOGS,

配置改变使用SET GLOBAL 来修改全局系统变量,mysqladmin debug 命令,启用或者关闭logging,执行更新 甚至read_only 系统变量是启用的,启动和关闭复制在slave servers上,


指定任何账户在存储程序和视图的定义属性。







测试:
slave:/etc# mysql -uzjzc_app -p1234567

1.对应用用户无法写入和修改
mysql> use zjzc;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from test;
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
+------+
3 rows in set (0.00 sec)

mysql> insert into test values(4);
ERROR 1290 (HY000): The MySQL server is running with the --read-only option so it cannot execute this statement

此时zjzc_app用户 不能对表test进行插入

2.对复制用户不影响
mysql> select * from test;
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
+------+
3 rows in set (0.00 sec)

mysql>  select * from test;
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
|  100 |
+------+
4 rows in set (0.00 sec)



3.对root用户不影响

你可能感兴趣的:(mysql 从设置只读)