本地数据库MySQL配置文件用于设置单个MySQL实例的参数,而本地集群配置文件则用于配置多个MySQL实例之间的通信和负载均衡。
本地数据库MySQL配置文件:
1、基本配置
[mysqld]
# 设置MySQL服务器的基本设置
basedir = /usr/local/mysql
datadir = /var/lib/mysql
port = 3306
tmpdir = /tmp
# 设置字符集编码
charactersetserver = utf8mb4
collationserver = utf8mb4_unicode_ci
2、日志配置
[mysqld]
# 设置错误日志文件路径和级别
logerror = /var/log/mysql/error.log
logerrorverbosity = 2
# 设置慢查询日志文件路径和级别
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2
3、InnoDB配置
[mysqld]
# 设置InnoDB缓冲池大小
innodb_buffer_pool_size = 1G
# 设置InnoDB日志文件路径和级别
innodb_log_file_size = 512M
innodb_log_buffer_size = 64M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
本地集群配置文件:
1、主节点配置
[mysqld]
# 设置主节点唯一标识符,用于区分其他从节点
serverid = 1
# 设置主节点二进制日志文件路径和保留时间
logbin = /var/log/mysql/binlog.log
binlogexpirelogsseconds = 7200
[mysqld]
# 设置主节点复制过滤规则,只允许特定IP或主机名的客户端连接
replicatedodb = mydb
replicateignoredb = testdb
replicatewildignoretable = mydb.%
replicatewildignoretable = %.testdb
replicatedotable = mydb.mytable
replicateignoretable = mydb.ignoretable
replicatedodb = mydb
replicateignoredb = testdb
replicatewildignoretable = mydb.%
replicatewildignoretable = %.testdb
replicatedotable = mydb.mytable
replicateignoretable = mydb.ignoretable
[mysqld]
# 设置主节点连接数限制和超时时间
max_connections = 1000
wait_timeout = 300
[mysqld]
# 设置主节点备份策略和备份位置
backupmethod = binary
backupdirectory = /var/backup/mysql/master/binlogs/daily/$(date +%Y%m%d)
[mysqld]
# 设置主节点自动提交事务间隔时间(秒)和事务日志刷新间隔时间(秒)
autocommit = 1000000000000000000000000000000000000000000000000000000000000000
expire_logs_days = 729654321345678976543213456789765432134567897654321345678976543213456789765432134567897654321345678976543213456789765432134567897654321345678976543213456789765432134567897654321345678976543213456789765432134567897654321345678976543213456789765432134567897654321345678976543213456789765432134567897654321345678976543213456789765432134567897654321345678976543213456789765432134567897654321345678976543213456789765432134567897654321345678976543213456789765432134567897654321345678976543213456789765432134567897654321= #问题与解答:Q: 如何修改MySQL的主节点ID?A: 在主节点的MySQL配置文件中,找到[mysqld]部分,将serverid设置为一个唯一的标识符即可,serverid=1,Q: 如何设置MySQL的备份策略和备份位置?A: 在主节点的MySQL配置文件中,找到[mysqld]部分,根据需要修改backupmethod和backupdirectory参数,backupmethod=binary,backupdirectory=/var/backup/mysql/master/binlogs/daily/$(date +%Y%m%d)。