mysql5.6+版本主從設置(mysql5.5以後的主從設置跟5.5以前的差異)

今天作mysql主從複製test的時候遇到的問題, 個人mysql version 是5.6.29:html

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

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

重啓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).ui

在mysql官方文檔search replication slave options
找到this

http://dev.mysql.com/doc/refman/5.6/en/replication-options-slave.htmlrest

最後發如今這篇文檔裏有說orm

Obsolete Replication Slave Optionsserver

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」).htm

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的同窗

相關文章
相關標籤/搜索