1、主库大概配置如下:
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
log-error = /var/log/mysql_error.log
skip-locking
key_buffer = 256M
max_allowed_packet = 32M
table_cache = 512
sort_buffer_size = 6M
thread_stack = 256K
net_buffer_length = 8K
read_buffer_size = 4M
join_buffer_size = 8M
tmp_table_size = 256M
max_connections = 1000
wait_timeout = 10
query_cache_size = 256M
query_cache_type = 1
thread_cache_size = 64
log_slow_queries
log-queries-not-using-indexes
log_long_format
long_query_time = 2
read_rnd_buffer_size = 16M
myisam_sort_buffer_size = 8M
log-bin=mysql-bin
server-id = 1
innodb_buffer_pool_size = 2G
innodb_log_file_size = 512M
innodb_lock_wait_timeout = 60
innodb_thread_concurrency= 30
innodb_commit_concurrency = 30
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
2、从库大概配置如下:
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
log-error = /var/log/mysql_error.log
skip-locking
key_buffer = 256M
max_allowed_packet = 32M
table_cache = 512
sort_buffer_size = 6M
thread_stack = 256K
net_buffer_length = 8K
read_buffer_size = 4M
join_buffer_size = 8M
tmp_table_size = 256M
max_connections = 1000
wait_timeout = 10
query_cache_size = 256M
query_cache_type = 1
thread_cache_size = 64
log_slow_queries
log-queries-not-using-indexes
log_long_format
long_query_time = 2
read_rnd_buffer_size = 16M
myisam_sort_buffer_size = 8M
log-bin=mysql-bin
server-id = 20
master-connect-retry = 60 (需要同步的2个库如下)
replicate-do-db = xxoo
replicate-do-db = xxoo2
innodb_additional_mem_pool_size = 4M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
3、错误:
我们知道,要想mysql主从复制成功的先决条件是Slave_IO_Running和Slave_SQL_Running均为Yes,而上图所示的结果显然是有一个不满足条件。
再根据Last_IO_Error的错误代码2013及下面的错误提示我们可以知道,从数据库无法正常连接到主数据库。
这里原因有三:
1、主数据库没有给从数据库登录授权
2、网络不通
3、有防火墙
明白这三点之后我们就可以针对原因依次来解决它们:
登录主数据库,给从数据库授权
[root@localhost ~]# mysql -uroot –p123456 登录主数据库
mysql> grant replication slave on *.* to 'backup'@'192.168.48.130' identified by 'backup'; 创建backup用户,并授权给从数据库连接使用。
检查网络是否通畅
[root@localhost ~]# ping -c 4 192.168.48.128 再从服务器上ping主服务器。
分别在主从服务器上检查防火墙状态
我们可以直接关闭防火墙
运行命令:[root@localhost ~]# service iptables stop
注意:一次性导入主库数据量过大,同步时会导致超时,从而同步失败。
本文出自 “仰望青春-李寒斌” 博客,请务必保留此出处http://youboy.blog.51cto.com/6090216/1009412