Windows下安装MySQL8.0并设置双机热备

初始化:
mysqld --initialize-insecure --user=mysql

安装服务:
mysqld -install MySQL-8.0.25

启动:
net start MySQL-8.0.25

登录:
mysql -uroot -p

修改root密码:
alter user 'root'@'localhost' identified by 'PWD';

创建数据库:
create database DBNAME;

创建普通数据库用户:
create user 'USER'@'localhost' identified by 'PWD';

授予权限:
grant all privileges on DBNAME.* to 'USER'@'localhost';

创建双机同步用户:
create user 'replicate'@'REMOTE_HOST' identified BY 'PWD';

授予同步权限:
grant replication slave on *.* to 'replicate'@'REMOTE_HOST';

使生效:
flush privileges;

显示主库信息:
show master status\G

停止从库:
stop slave;

设置主库信息:
change master to master_host='REMOTE_HOST',master_port=3306,master_user='replicate',master_password='PWD',master_auto_position=1,GET_MASTER_PUBLIC_KEY=1;

启动从库:
start slave;

显示从库信息:
show slave status\G

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注