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 with mysql_native_password by 'PWD';

创建数据库:
create database DBNAME;

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

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

创建双机同步用户:
create user 'replicate'@'REMOTE_HOST' identified with mysql_native_password 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=63306,master_user='replicate',master_password='PWD',master_log_file='backup-log.000002',master_log_pos=0;

启动从库:
start slave;

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

发表评论

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