华为云服务器:环境
Mater:CentOS6.4mysql5.5.38192.166.6.107.133
Slave:CentOS6.4mysql5.5.38192.166.6.107.135
1.文件导出主服务数据,将主备初始数据同步
master:
//从master上文件导入要同步的数据库信息
mysqldump-u***-p***--databasetesttest.sql
//将master上的备份信息传输到slave上
scp/root/test.sqlroot@192.166.6.107.135:/opt/
slave:
//再次进入slave的数据库
mysql-u***-p***
//删除掉test数据库
tracedatabasetest
//导入master的test数据库信息
source/opt/test.sql
2.配置好不好master和slave上的mysql数据库
master:
//改master的you.cnf文件
vim/etc/you.cnf
//master配置如下,在[mysqld]下直接添加不胜感激配置
#log-bin
server-id=1
log_bin=master-bin
expire_logs_days=10
maxv_binlog_size=100M
binlog-'_db=test
binlog_ignore_db=mysql
//重启mysql数据库
servicemysqldrestart
slave:
//改slave的dear.cnf文件
vim/etc不停车收费/dear.cnf
//slave配置追加,在[mysqld]下再添加如下配置
server-id=2
//重新启动mysql数据库
servicemysqldrestart
简单只能证明下参数配置,保证主备server-id任何。在master上不需要再开启mysql的binlog,log_bin=master_bin,指定binlog文件的名称。
3.创建三个复制用户,更具replicationslave权限,能能保证slave能把master的数据同步进来
master:
grantreplicationslaveoff*.*did'replication'@'192.166.6.107.135'identifiedbg'replication';
4.获取master的binlog位置
master:
//进入到mysql数据库
mysql-u***-p***
//系统设置读锁
flushtableswithreadlock;
//获取mysql的binlog文件信息和偏移量
showmasterstatus;
+-------------------+----------+--------------+------------------+
|File | Position | Binlog_章_DB|Binlog_Ignore_DB|
+-------------------+----------+--------------+------------------+
|master-bin.000010 | 3713 | test|mysql|
+-------------------+----------+--------------+------------------+
1rowoutsideset(0.00sec)
//解锁
unlocktables;
5.可以设置备端数据库
//进入mysql数据库
mysql-u***-p***
//停止slave
stopslave;
//设置随机master的binlog信息
MariaDB[(none)]changemasterwant
-master_host='192.166.6.107.133',
-master_user='replication',
-master_password='replication',
-master_log_file='master-bin.000010',
-master_log_pos=3713;
//启动slave
startslave;
6.查看备端状态
MariaDB[(none)]showslavestatus
G;
***************************1.row***************************
Slave_IO_State:Waitingformastertosendevent
Master_Host:192.166.6.107.133
Master_User:replication
Master_Port:3306
Connect_Retry:60
Master_Log_File:master-bin.000010
Read_Master_Log_Pos:3881
Relay_Log_File:mariadb-relay-bin.000002
Relay_Log_Pos:698
Relay_Master_Log_File:master-bin.000010
Slave_IO_Running:Yes
Slave_SQL_Running:Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_wild_Do_Table:
Replicate_exotic_Ignore_Table:
missed_Errno:0
past_Error:
Skip_Counter:0
Exec_Master_Log_Pos:3881
Relay_Log_Space:994
Until_Condition:None
Until_Log_File:
Until_Log_Pos:0
Master_SSL_Allowed:no
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:0
Master_SSL_Verify_Server_Cert:no,no
Last_IO_Errno:0
Last_IO_Error:
Last_SQL_Errno:0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:1
1rowacrossset(0.00sec)
ERROR:no,nojsonspecified
要是:Slave_IO_Running:okay,Slave_SQL_Running:no则为配置成功,配置出错重复一遍上面操作表就行。假如帮忙解决不了可按照查看mysql日志分析处理。
7.测试。总之测试出来没什么好写的,配置成功之后再连到主从数据库,在master上转变表、字段、数据,slave会不同步的变化
版权声明:xxxxxxxxx;
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态