您的位置:首页 > 数据库 > MySQL

mysql5.6+版本主从设置(mysql5.5之后的主从设置跟5.5之前的差别)

2016-03-15 14:08 423 查看
今天做mysql主从复制test的时候遇到的问题, 我的mysql version 是5.6.29:

在slave server 上配置my.cnf, 添加

master-host=192.168.124.51
master-user= AffairLog
master-password= password
master-port=3306

重启mysqld服务后,报一下错误
# /etc/init.d/mysqld restart

ERROR! MySQL server PID file could not be found!
Starting MySQL.. ERROR! The server quit without updating PID file (/var/mysql/data/csw.pid).

在mysql官方文档search replication slave options
找到
http://dev.mysql.com/doc/refman/5.6/en/replication-options-slave.html
最后发现在这篇文档里有说

Obsolete Replication Slave Options

The following options are removed in MySQL 5.5. If you attempt to start mysqld with any of these options in MySQL 5.6, the server aborts with an unknown variable error. To set the replication parameters formerly associated with these options, you must use the CHANGE MASTER TO ... statement (see Section 13.4.2.1, “CHANGE MASTER TO Syntax”).

The options affected are shown in this list:

--master-host

--master-user

--master-password

--master-port

--master-connect-retry

--master-ssl

--master-ssl-ca

--master-ssl-capath

--master-ssl-cert

--master-ssl-cipher

--master-ssl-key

打开上面链接http://dev.mysql.com/doc/refman/5.6/en/change-master-to.html

MySQL 5.6 Reference Manual / ... / CHANGE MASTER TO Syntax
13.4.2.1 CHANGE MASTER TO Syntax

CHANGE MASTER TO option [, option] ...

option:
MASTER_BIND = 'interface_name'
| MASTER_HOST = 'host_name'
| MASTER_USER = 'user_name'
| MASTER_PASSWORD = 'password'
| MASTER_PORT = port_num
| MASTER_CONNECT_RETRY = interval
| MASTER_RETRY_COUNT = count
| MASTER_DELAY = interval
| MASTER_HEARTBEAT_PERIOD = interval
| MASTER_LOG_FILE = 'master_log_name'
| MASTER_LOG_POS = master_log_pos
| MASTER_AUTO_POSITION = {0|1}
| RELAY_LOG_FILE = 'relay_log_name'
| RELAY_LOG_POS = relay_log_pos
| MASTER_SSL = {0|1}
| MASTER_SSL_CA = 'ca_file_name'
| MASTER_SSL_CAPATH = 'ca_directory_name'
| MASTER_SSL_CERT = 'cert_file_name'
| MASTER_SSL_CRL = 'crl_file_name'
| MASTER_SSL_CRLPATH = 'crl_directory_name'
| MASTER_SSL_KEY = 'key_file_name'
| MASTER_SSL_CIPHER = 'cipher_list'
| MASTER_SSL_VERIFY_SERVER_CERT = {0|1}
| IGNORE_SERVER_IDS = (server_id_list)

server_id_list:
[server_id [, server_id] ... ]

CHANGE MASTER TO changes the parameters that the slave server uses for connecting to the master server, for reading the master binary log, and reading the slave relay log. It also updates the contents of the master info and relay log info repositories (see Section 17.2.2, “Replication Relay and Status Logs”). To use CHANGE MASTER TO, the slave replication threads must be stopped (use STOP SLAVE if necessary). In MySQL 5.6.11 and later, gtid_next must also be set to AUTOMATIC (Bug #16062608).

Options not specified retain their value, except as indicated in the following discussion. Thus, in most cases, there is no need to specify options that do not change. For example, if the password to connect to your MySQL master has changed, issue these statements to tell the slave about the new password:

STOP SLAVE; -- if replication was running
CHANGE MASTER TO MASTER_PASSWORD='new3cret';
START SLAVE; -- if you want to restart replication

原来在mysql要这样设置

mysql> change master to
> master_host='master_ip',
> master_user='user',
> master_password='pwd',
> master_port=3307;

mysql> slave start;

最后查看状态:

mysql> show slave status \G

如出现

Slave_IO_Running: Connecting
Slave_SQL_Running: Yes

Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.

则关闭slave数据库

#/etc/init.d/mysqld stop

删除 DATA_DIR/auto.cnf

# rm -rf /var/mysql/data/auto.cnf

重启mysql

# /etc/init.d/mysqld start

进入数据库

mysql> start slave;
msyql> show slave status \G

如出现

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

则配置成功!

一点心得分享给跟我遇到同样bug的同学
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: