Mysql从库read-only配置详解
2019/10/10/17:32:27 阅读:1881 来源:谷歌SEO算法 标签:
自媒体
在做mysql主从同步时我们会碰到一个从库read-only了,下面小编来为各位介绍Mysql从库read-only配置详解,希望文章对各位有用.
为了防止用户对从库进行插入,采用read-only参数.
配置:
[root@Slave-Mysql data]# grep read-only /etc/my.cnf
read-only
试验过程:
主库授权ALL:mysql> grant all on *.* to 'imbyrd'@'localhost' identified by 'admin';
从库测试:
- [root@Slave-Mysqldata]#/usr/local/mysql/bin/mysql-uimbyrd-p'admin'
- mysql>usehitest;
- mysql>insertintotest(id,name)values(14,'fo');
- QueryOK,1rowaffected(0.14sec)
主库授权select,insert,update,delete
- mysql>REVOKEallON*.*FROM'imbyrd'@'localhost';
- mysql>grantselect,insert,update,deleteon*.*to'imbyrd'@'localhost'identifiedby'admin';
- mysql>showgrantsforimbyrd@'localhost';
- +----------------------------------------------------------------------------------------------------------------------------------------+
- |Grantsforimbyrd@localhost|
- +----------------------------------------------------------------------------------------------------------------------------------------+
- |GRANTSELECT,INSERT,UPDATE,DELETEON*.*TO'imbyrd'@'localhost'IDENTIFIEDBYPASSWORD'*4ACFE3202A5FF5CF467898FC58AAB1D615029441'|--phpfensi.com
- +----------------------------------------------------------------------------------------------------------------------------------------+
- 1rowinset(0.00sec)
从库测试:
- mysql>usehitest;
- mysql>insertintotest(id,name)values(16,'dddd');
- ERROR1290(HY000):TheMySQLserverisrunningwiththe--read-onlyoptionsoitcannotexecutethisstatement
主库配置:
- mysql>grantallon*.*to'imbyrd'@'localhost'identifiedby'admin';
- mysql>showgrantsforimbyrd@'localhost'\G
- ***************************1.row***************************
- Grantsforimbyrd@localhost:GRANTALLPRIVILEGESON*.*TO'imbyrd'@'localhost'IDENTIFIEDBYPASSWORD'*4ACFE3202A5FF5CF467898FC58AAB1D615029441'
- 1rowinset(0.00sec)
- mysql>REVOKESUPERON*.*FROM'imbyrd'@'localhost';
- mysql>showgrantsforimbyrd@'localhost'\G
- ***************************1.row***************************
- Grantsforimbyrd@localhost:GRANTSELECT,INSERT,UPDATE,DELETE,CREATE,DROP,RELOAD,SHUTDOWN,PROCESS,FILE,REFERENCES,INDEX,ALTER,SHOWDATABASES,CREATETEMPORARYTABLES,LOCKTABLES,EXECUTE,REPLICATIONSLAVE,REPLICATIONCLIENT,CREATEVIEW,SHOWVIEW,CREATEROUTINE,ALTERROUTINE,CREATEUSER,EVENT,TRIGGER,CREATETABLESPACEON*.*TO'imbyrd'@'localhost'IDENTIFIEDBYPASSWORD'*4ACFE3202A5FF5CF467898FC58AAB1D615029441'
- 1rowinset(0.00sec)
从库测试:
- [root@Slave-Mysqldata]#/usr/local/mysql/bin/mysql-uimbyrd-p'admin'
- mysql>usehitest;
- mysql>insertintotest(id,name)values(23,'fddf');
- ERROR1290(HY000):TheMySQLserverisrunningwiththe--read-onlyoptionsoitcannotexecutethisstatement
结论:当用户权限中没有SUPER权限(ALL权限是包括SUPER的)时,从库的read-only生效.
热门评论