Mysql read_only 只读数据库
2016-04-05 by dongnan
目标
为 mysql数据库配置 read only 参数,配合 phpmyadmin,只能查询数据操作。
环境
版本: mysql 5.6.x
角色: slave 从库
步骤
配置文件
# 执行命令
grep 'read_only' /etc/my.cnf
read_only = 1 # 使用 read_only 选项
重启服务器
# 执行命令
/etc/init.d/mysqld restart
参数
read_only选项对所有的非临时表进行只读控制,但是有两种情况例外:
- 对
replication threads例外,以保证slave能够正常的进行复制。 - 对于拥有
super权限的用户忽略这个选项。
关于super权限
- 可以有
change master to,kill其他用户的线程的权限。 - 执行
Purge binary logs来删除binary log, set global来动态设置变量的权限。 - 执行
mysqladmin debug命令,开启或者关闭log,在read-only打开时执行update/insert操作。 - 执行
start slave, stop slave。 - 当连接数已经达到
max_connections的最大值时,也可以连接到服务器。