您好,欢迎访问一九零五行业门户网

Linux CentOS 5.5 下 MySQL 5.5.3-m3 同步与主从备份

也就是说,slave传输的master binlog 不与当前master正使用的binlog以及binlog的行数对应。3.[error] slave i/o: error connecti
**************************前言**************************
一.主从的作用:
1.可以当做一种备份方式
2.用来实现读写分离,缓解一个数据库的压力
二.环境:
os    centos5.5
db    mysql5.5.3-m3
安装 centos5.5 请看
安装 mysql5.5.3-m3 请看
三.mysql主从备份原理
master  上提供binlog ,
slave    通过 i/o线程从 master拿取 binlog,并复制到slave的中继日志中
slave    通过 sql线程从 slave的中继日志中读取binlog ,然后解析到slave中
四.主从复制大前提
需要master与slave同步,因为笔者的数据库数据量不大,所以无需考虑太多,直接把
master上的data复制到了slave上,但是如果是大的数据量,比如像taobao这个的系统
那么数据同步也是很难得,需要有一个完善的方案,有兴趣的可以看看这篇文章
%e5%a2%9e%e9%87%8f%e6%97%a5%e5%bf%97%e8%bf%ad%e4%bb%a3%e5%90%8c%e6%ad%a5%e5%92%8c%e9%98%bf%e5%9f%ba%e9%87%8c%e6%96%af%e6%82%96%e8%ae%ba.html
**************************开始***************************************************
一.将master设置为只读。
mysql> flush tables with read lock;
二.用master中的data文件夹替换slave中的data文件夹
比如 用 tar zcvf  mysql_data.gz   /media/raid10/mysql/3306/data
然后 mv  mysql_data.gz /media/raid10/htdocs/blog/wordpress/
因为我的 /media/raid10/htdocs/blog/wordpress/  是 nginx 的主目录
所以可以在 slave上,用wget下载这个文件,然后 解压,并覆盖slave上的data文件
注意:覆盖之前最好备份源文件
三.配置master的my.cnf,添加以下内容
在[mysqld]配置段添加如下字段
server-id=1
log-bin=/media/raid10/mysql/3306/binlog/binlog //这里写你的binlog绝对路径名
binlog-do-db=blog //需要同步的数据库,如果没有本行,,即表示同步所有的数据库
binlog-ignore-db=mysql //被忽略的数据库
这里给出我的my.cnf配置文件
[client]
character-set-server = utf8
port    = 3306
socket  = /tmp/mysql.sock
[mysqld]
character-set-server = utf8
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user    = mysql
port    = 3306
socket  = /tmp/mysql.sock
basedir = /usr/local/webserver/mysql
datadir = /media/raid10/mysql/3306/data
log-error = /media/raid10/mysql/3306/mysql_error.log
pid-file = /media/raid10/mysql/3306/mysql.pid
open_files_limit    = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_cache = 614
external-locking = false
max_allowed_packet = 16m
sort_buffer_size = 1m
join_buffer_size = 1m
thread_cache_size = 300
#thread_concurrency = 8
query_cache_size = 20m
query_cache_limit = 2m
query_cache_min_res_unit = 2k
default-storage-engine = myisam
thread_stack = 192k
transaction_isolation = read-committed
tmp_table_size = 20m
max_heap_table_size = 20m
long_query_time = 3
log-slave-updates
log-bin = /media/raid10/mysql/3306/binlog/binlog
binlog-do-db=blog
binlog-ignore-db=mysql
binlog_cache_size = 4m
binlog_format = mixed
max_binlog_cache_size = 8m
max_binlog_size = 20m
relay-log-index = /media/raid10/mysql/3306/relaylog/relaylog
relay-log-info-file = /media/raid10/mysql/3306/relaylog/relaylog
relay-log = /media/raid10/mysql/3306/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 10m
read_buffer_size = 1m
read_rnd_buffer_size = 6m
bulk_insert_buffer_size = 4m
myisam_sort_buffer_size = 8m
myisam_max_sort_file_size = 20m
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
#master-host     =   192.168.1.2
#master-user     =   username
#master-password =   password
#master-port     =  3306
server-id = 1
innodb_additional_mem_pool_size = 16m
innodb_buffer_pool_size = 20m
innodb_data_file_path = ibdata1:56m:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16m
innodb_log_file_size = 20m
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
#log-slow-queries = /media/raid10/mysql/3306/slow.log
#long_query_time = 10
[mysqldump]
quick
max_allowed_packet = 32m
四.在master机上为slave机添加一同步帐号
mysql> grant replication slave on *.* to 'admin'@'172.29.141.115' identified by '12345678';
mysql> flush privileges ;
其它类似信息

推荐信息