mysql主从配置的参数配置与步骤
在主库建立要同步的数据库,建立主库的帐号和修改主备库配置
create database web default character set utf8
grant replication slave on *.* to ‘repdcssub‘@‘192.168.191.112‘ identified by ‘123456‘;
grant all privileges on *.* to ‘repdcssub‘@‘192.168.191.112‘ identified by ‘123456‘
mysql -h192.168.191.113 -urep -p123456
mysqldump --master-data 这样可以在从上还原,
建立同步用户(主从)
grant replication slave on *.* to ‘repdcs‘@‘192.168.191.110‘ identified by ‘123456‘;
grant all privileges on *.* to ‘repdcs‘@‘192.168.191.110‘ identified by ‘123456‘;
FLUSH PRIVILEGES;
mysql> show master status;
FLUSH PRIVILEGES;
从库配置my.cnf
[root@ligangtest u02]# more /etc/my.cnf
[mysqld]
datadir=/u02/ligangdata
socket=/var/lib/mysql/mysql.sock
user=mysql
old_passwords=1
character-set-server=utf8
symbolic-links=0
lower_case_table_names=1
default-storage-engine=innoDB
#innodb_log_buffer_pool_size=2G
max_connections=300
server-id=2
init_connect=‘SET NAMES utf8‘
log-bin=mysqlbin
master-host=192.168.191.111
master-user=repdcs
master-pass=123456
master-connect-retry=60
replicate-do-db=dcs
[mysqld_safe]
log-error=/u03/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql]
default-character-set=utf8
#character-set-server=utf8
主库配置my.ini
[root@ligang log]# more /etc/my.cnf
[mysqld]
datadir=/u02/ligangdata
socket=/var/lib/mysql/mysql.sock
user=mysql
old_passwords=1
character-set-server=utf8
# Disabling symbolic-links is recommended to prevent assorted security risks;
symbolic-links=0
lower_case_table_names=1
default-storage-engine=innoDB
server-id=1
log-bin=mysqlbin
innodb_flush_log_at_trx_commit=1
sync_binlog=1
init_connect=‘SET NAMES utf8‘
#innodb_log_buffer_pool_size=2G
max_connections=300
[mysqld_safe]
log-error=/u03/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql]
default-character-set=utf8
#character-set-server=utf8
参数配置说明
server-id=n //设置数据库id默认主服务器是1可以随便设置但是如果有多台从服务器则不能重复。
master-host=192.168.191.111 //主服务器的IP地址或者域名
master-port=3306 //主数据库的端口号
master-user=repdcs //同步数据库的用户
master-password=123456 //同步数据库的密码
master-connect-retry=60 //如果从服务器发现主服务器断掉,重新连接的时间差
replicate-do-db=dcs //进行同步的数据库
设置从服务器为readonly
mysql -e "set global read_only=1;"
查看主备库正常与否的命令:
SHOW SLAVE STATUS;
SHOW MASTER STATUS;
主从切换请看下一篇文章
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。