RE
sudo mysql
CREATE DATABASE master_db CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE slave_db CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'test'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON master_db.* TO 'test'@'%';
GRANT ALL PRIVILEGES ON slave_db.* TO 'test'@'%';
FLUSH PRIVILEGES;
CREATE USER 'replication_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT REPLICATION SLAVE ON *.* TO 'replication_user'@'localhost';
/etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
bind-address = 0.0.0.0
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#replica test
server-id = 1
log-bin = /var/lib/mysql/mysql-bin
report-host=master-is-slave-host
relay-log=myserver-relaylog
replicate-same-server-id=1
binlog-do-db=master_db
replicate-rewrite-db=master_db->slave_db
replicate-do-db=slave_db
sudo systemctl restart mysql
CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_USER='replication_user', MASTER_PASSWORD='your_password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=0;
START SLAVE;
No comments:
Post a Comment