mysql 添加丛库
资源:mysql主库服务器A,需要添加的丛库服务器B
过程:
1,首先将登录A库,添加丛库需要同步的用户
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO '用户名'@'*.*.*.%' IDENTIFIED BY '密码';
#grant all privileges on *.* to 用户名@"*.*.*.%" identified by "密码"; 这是添加普通用户,此步不操作
flush privileges
然后需要记录结点
show master status;
+---------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| binlog.000002 | 106 | | |
+---------------+----------+--------------+------------------+
然后进入到mysql目录,./mysql stop
2,将A库实例3306拷贝到服务器B的相应目录下:scp -r 3306/ (服务器B的IP)@:/data0/mysql/
3,拷贝完毕,登录服务器B,更改3306的my.cnf相关配置
[client]
default-character-set = utf8
port = 3306
socket = /tmp/mysql3306.sock
[mysqld]
default-character-set = utf8
user = mysql
port = 3306
socket = /tmp/mysql3306.sock
basedir = /usr/local/webserver/mysql
datadir = /data0/mysql/3306/data
log-error = /data0/mysql/3306/mysql_error.log
pid-file = /data0/mysql/3306/mysql.pid
open_files_limit = 10240
back_log = 600
max_connections = 1000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 300
thread_concurrency = 8
query_cache_size = 512M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
default_table_type = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 3
log_long_format
#log-slave-updates
log-bin = /data0/mysql/3306/binlog/binlog #bin-log可以开启也可以不开启
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 1024M
max_binlog_size = 1G
relay-log-index = /data0/mysql/3306/relaylog/relaylog #丛库需要开启relay-log
relay-log-info-file = /data0/mysql/3306/relaylog/relaylog
relay-log = /data0/mysql/3306/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
connect_timeout = 20
read-only = 1
skip-name-resolve
master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396,1194
replicate-ignore-db = mysql #此地设置的哪些库不在进行主丛同步
replicate-ignore-db = test
replicate-ignore-db = information_schema
server-id = (B的IP)3306 #此值一定是唯一的,不能和其它地方丛库的server-id重复
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_file_path = ibdata1:256M: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 = 128M
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 = /data0/mysql/3306/slow.log
long_query_time = 5
[mysqldump]
quick
max_allowed_packet = 32M
更改完配置文件后别忘更改3306实例的权限
cd ..
chown mysql.mysql 3306/ -R
开启丛库
cd /data0/msql/3306
./mysql start
change master to master_host = '主库B的IP',master_port = 3306,master_user = '用户名',master_password = '密码',master_log_file = 'binlog.000002',master_log_pos = 106;
show slave status\G;
slave start
查看是否启动成功
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
4,登录主库A,启动3306数据库,在查看数据库B是否报错,如果无,则成功
资源:mysql主库服务器A,需要添加的丛库服务器B
过程:
1,首先将登录A库,添加丛库需要同步的用户
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO '用户名'@'*.*.*.%' IDENTIFIED BY '密码';
#grant all privileges on *.* to 用户名@"*.*.*.%" identified by "密码"; 这是添加普通用户,此步不操作
flush privileges
然后需要记录结点
show master status;
+---------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| binlog.000002 | 106 | | |
+---------------+----------+--------------+------------------+
然后进入到mysql目录,./mysql stop
2,将A库实例3306拷贝到服务器B的相应目录下:scp -r 3306/ (服务器B的IP)@:/data0/mysql/
3,拷贝完毕,登录服务器B,更改3306的my.cnf相关配置
[client]
default-character-set = utf8
port = 3306
socket = /tmp/mysql3306.sock
[mysqld]
default-character-set = utf8
user = mysql
port = 3306
socket = /tmp/mysql3306.sock
basedir = /usr/local/webserver/mysql
datadir = /data0/mysql/3306/data
log-error = /data0/mysql/3306/mysql_error.log
pid-file = /data0/mysql/3306/mysql.pid
open_files_limit = 10240
back_log = 600
max_connections = 1000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 300
thread_concurrency = 8
query_cache_size = 512M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
default_table_type = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 3
log_long_format
#log-slave-updates
log-bin = /data0/mysql/3306/binlog/binlog #bin-log可以开启也可以不开启
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 1024M
max_binlog_size = 1G
relay-log-index = /data0/mysql/3306/relaylog/relaylog #丛库需要开启relay-log
relay-log-info-file = /data0/mysql/3306/relaylog/relaylog
relay-log = /data0/mysql/3306/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
connect_timeout = 20
read-only = 1
skip-name-resolve
master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396,1194
replicate-ignore-db = mysql #此地设置的哪些库不在进行主丛同步
replicate-ignore-db = test
replicate-ignore-db = information_schema
server-id = (B的IP)3306 #此值一定是唯一的,不能和其它地方丛库的server-id重复
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_file_path = ibdata1:256M: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 = 128M
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 = /data0/mysql/3306/slow.log
long_query_time = 5
[mysqldump]
quick
max_allowed_packet = 32M
更改完配置文件后别忘更改3306实例的权限
cd ..
chown mysql.mysql 3306/ -R
开启丛库
cd /data0/msql/3306
./mysql start
change master to master_host = '主库B的IP',master_port = 3306,master_user = '用户名',master_password = '密码',master_log_file = 'binlog.000002',master_log_pos = 106;
show slave status\G;
slave start
查看是否启动成功
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
4,登录主库A,启动3306数据库,在查看数据库B是否报错,如果无,则成功