[mysqld] log-bin=mysql-bin #添加這一行就ok binlog-format=ROW #選擇row模式 server_id=1 #配置mysql replaction須要定義,不能和canal的slaveId重複
b. canal的原理是模擬本身爲mysql slave,因此這裏必定須要作爲mysql slave的相關權限.mysql
CREATE USER canal IDENTIFIED BY 'canal'; GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%'; -- GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%' ; FLUSH PRIVILEGES;
Download and add the repository, then update.sql
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm yum update
Install MySQL as usual and start the service. During installation, you will be asked if you want to accept the results from the .rpm file’s GPG verification. If no error or mismatch occurs, enter y
.shell
sudo yum install mysql-server sudo systemctl start mysqld
sudo nano /etc/mysql/my.cnf
We have to make sure that we have a few things set up in this configuration. The first is the server-id. This number, as mentioned before needs to be unique. Since it is set on the default (still 1), be sure to change it’s something different.app
server-id = 2
Following that, make sure that your have the following three criteria appropriately filled out:ide
relay-log = /var/log/mysql/mysql-relay-bin.log
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = newdatabase
You will need to add in the relay-log line: it is not there by default. Once you have made all of the necessary changes, save and exit out of the slave configuration file.this
Restart MySQL once again:rest
sudo service mysql restart
The next step is to enable the replication from within the MySQL shell.code
Open up the the MySQL shell once again and type in the following details, replacing the values to match your information:orm
CHANGE MASTER TO MASTER_HOST='12.34.56.789',MASTER_USER='slave_user', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS= 107;
This command accomplishes several things at the same time:server
With that—you have configured a master and slave server.
Activate the slave server:
START SLAVE;
You be able to see the details of the slave replication by typing in this command. The \G rearranges the text to make it more readable.
SHOW SLAVE STATUS\G
If there is an issue in connecting, you can try starting slave with a command to skip over it:
SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; SLAVE START;
在master那邊,執行:
flush logs;
show master status;
記下File, Position。
在slave端,執行:
CHANGE MASTER TO MASTER_LOG_FILE='testdbbinlog.000xxxx',MASTER_LOG_POS=xxxxx;slave start;show slave status \G