单机部署
mkdir -p /opt/soft/archive
cd /opt/soft/archive
wget -i -c https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
yum install -y mysql80-community-release-el7-7.noarch.rpm
yum-config-manager --enable mysql80-community
yum install -y mysql-community-server
systemctl start mysqld
export pw=$(grep 'temporary password' /var/log/mysqld.log | awk '{print $13}')
mysql -u root -p$pw
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
CREATE USER demo IDENTIFIED BY 'Demo@1234';
grant all on *.* to 'demo'@'%';
flush privileges;
quit;
systemctl restart mysqld
主从
主库:
set global server_id = 2;
CREATE USER 'repl'@'%' IDENTIFIED BY 'Repl@1234';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
ALTER USER 'repl'@'%' IDENTIFIED WITH mysql_native_password BY 'Repl@1234';
flush privileges;
FLUSH TABLES WITH READ LOCK;
# 查看binlog file 和 position
SHOW MASTER STATUS;
UNLOCK TABLES;
从库:
set global server_id = 33;
CHANGE MASTER TO
MASTER_HOST='123.56.192.242',
MASTER_USER='repl',
MASTER_PASSWORD='Repl@1234',
MASTER_LOG_FILE='binlog.000003',
MASTER_LOG_POS=578964;
start slave;
# 停止同步
stop slave;
reset slave all;