在配置好基本步骤后,Slave进行以下操作时报错:
change master to master_host='xx.xx.xx.xx',
master_user='xxxx',
master_password='xxxxxx',
master_port=3306,
master_log_file='mysql-bin.000002',
master_log_pos=120;
报错信息:
# [Slave is not configured or failed to initialize properly. You must at least set --server-id to enable either a master or a slave]
看意思是说我我的server-id没有配置好,然后检查了Master和Slave端的my.cnf配置文件内容,里面都有设置server-id;
然后在msyql命令下执行下面的命令检查server-id是否设置成功(我的Master设置的是id是1,Slave设置的是2)
#这是Master端 输出没有问题
mysql> SHOW GLOBAL VARIABLES like 'server\_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 1 |
+---------------+-------+
1 row in set (0.00 sec)
#这是Slave端 我配置文件设置的是2,但是这里显示的0,显然配置没有生效
mysql> SHOW GLOBAL VARIABLES like 'server\_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 0 |
+---------------+-------+
1 row in set (0.00 sec)
对比着Master检查Slave的my.cnf配置文件,发现my.cnf里面有两段内容,上面是[mysqld]开头的,下面是[mysqld_safe]开头的(仔细检查my.cnf文件内容)
server-id这些内容应该配置在[mysqld]下面
正确配置为:
[root@li1004-237 ~]# cat /etc/my.cnf
#注意看这里……(^_^)a
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#主从配置应该设置在[mysqld]下面……(^_^)a
server_id=2
binlog-ignore-db=mysql
log_slave_updates=1
# 注意看这里……(^_^)a
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
修改好记得重启数据库
#service mysqld restart
配置好了之后在Slave端验证一下
mysql> SHOW GLOBAL VARIABLES like 'server\_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 2 |
+---------------+-------+
1 row in set (0.00 sec)
#这时Value为2 表示配置生效了
OK……
然后在重新执行以下命令进行主从绑定
change master to master_host='xx.xx.xx.xx',
master_user='xxxx',
master_password='xxxxxx',
master_port=3306,
master_log_file='mysql-bin.000002',
master_log_pos=120;
输出
Query OK, 0 rows affected, 2 warnings (0.05 sec)
表示成功
然后还没完,绑定成功后在Slave端要开启服务
在Slave端查看主从同步状态
mysql> show slave status\G;
结果中Slave_IO_Running、Slave_SQL_Running应该是No
然后执行以下命令就可以同步了
mysql> start slave;
重新执行命令,如果Slave_IO_Running、Slave_SQL_Running为YES说明主从复制配置成功!!!
mysql> show slave status\G;
网友评论