Mysql-從庫只讀設置


主從設置中,如果從庫在my.cnf中使用init_connect來限制只讀權限的話,從庫使用非超級用戶(super權限)登陸數據時,無法進行任何操作,僅可維持主從復制。

init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
init_connect='SET autocommit=0'
init_connect='SET global read_only=1

如果需要從庫可進行查詢類的只讀操作,需要在配置文件中通過配置read_only=on來實現

從庫my.cnf示例

[mysql]
default-character-set=utf8
[mysqld]
autocommit=OFF
skip_name_resolve
skip-external-locking
datadir=/usr/mysql/5.6/data
socket=/var/lib/mysql/mysql.sock
log-bin=mysql-bin
server-id=215
innodb_flush_log_at_trx_commit=1
sync_binlog=1
binlog_format=mixed
lower_case_table_names=1
#主從配置


pid_file=/var/lib/mysql/mysql.pid
#init_connect='SET collation_connection = utf8_general_ci'
#init_connect='SET NAMES utf8'
#init_connect='SET autocommit=0'
#init_connect='SET global read_only=1'
read_only=on
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake
log_bin_trust_function_creators=1
#user=
port=3306
#innodb
default_storage_engine=InnoDB
innodb_buffer_pool_size=512M
innodb_log_buffer_size=16M
innodb_log_file_size=64M
innodb_file_per_table=1
innodb_autoextend_increment=128M
#innodb_flush_method=0_DIRECT
#other
key_buffer_size=512M
log_error=/usr/mysql/5.6/mysql-error.log
slow_query_log_file=/usr/mysql/5.6/mysql-slow.log
tmp_table_size=200M
max_heap_table_size=200M
table_open_cache = 1024
sort_buffer_size = 1024K
max_allowed_packet = 100M
query_cache_type=0
query_cache_size=0
open_files_limit=65535
[client]
socket=/var/lib/mysql/mysql.sock
port=3306
default-character-set=utf8
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM