mysql 六步从安装到主从同步(双机热备)
windows系统 mysql 六部从安装到主从同步
1.下载MySQL
2.配置主库 my.ini
[mysqld]
# 设置mysql的安装目录,即你解压缩安装包的位置
basedir = F:/CodeTools/sql/mysql/mysql-5.7.30-master
# 设置mysql数据库的数据的存放目录
datadir = F:/CodeTools/sql/mysql/mysql-5.7.30-master/data
# 设置端口号
port = 3306
# 允许最大连接数
max_connections = 200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=20
log-bin=mysql-bin
#标识唯一id(必须),一般使用ip最后位
#不同步的数据库,可设置多个
server-id=100
#不同步的数据库
binlog-ignore-db=information_schema
#指定需要同步的数据库(和slave是相互匹配的),可以设置多个
binlog-do-db=ming
data 文件需要手动创建
3.配置主库Mysql服务
进入mysql 的安装bin目录
1.mysqld --initialize-insecure
2..mysqld install xxx(服务名字) --defaults-file="F:/CodeTools/sql/mysql/mysql-5.7.30-master/my.ini"
3.net start xxx
4.mysql -u root -p (免密登录)
5.修改数据库账号密码
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;
exit
mysql>GRANT FILE ON *.* TO 'ming_masrer'@'127.0.01' IDENTIFIED BY 'ming_masrer';
mysql>GRANT REPLICATION SLAVE ON *.* TO 'ming_masrer'@'127.0.0.1' IDENTIFIED BY 'ming_masrer';
mysql>select host,user from mysql.user;
mysql>FLUSH PRIVILEGE
S;
net stop xxx 关闭服务 net start xxx 开启服务 #重启mysql服务
mysql -u root -p #登陆mysql
mysql> show master status; #查看master状态
mysql> show master status;
+------------------+----------+--------------+--------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+--------------------+-------------------+
| mysql-bin.000002 | 1321 | ming | information_schema | |
+------------------+----------+--------------+--------------------+-------------------+
1 row in set
4.配置从库 myini
[mysqld]
# 设置mysql的安装目录,即你解压缩安装包的位置
basedir = F:/CodeTools/sql/mysql/mysql-5.7.30-slave
# 设置mysql数据库的数据的存放目录
datadir = F:/CodeTools/sql/mysql/mysql-5.7.30-slave/data
# 设置端口号
port = 3307
# 允许最大连接数
max_connections = 200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=20
explicit_defaults_for_timestamp=true
#开启二进制日志
log-bin=mysql-bin
server-id=101
#binlog-ignore-db=information_schema
#binlog-ignore-db=performance_schema
#binlog-ignore-db=mysql
#与主库配置保持一致
replicate-do-db=ming
#replicate-ignore-db=mysql
log-slave-updates
slave-skip-errors=all
slave-net-timeout=60
5 .配置从库Mysql服务
数据库配置同主库 具体操作看主库配置
#开启Slave
#设置连接主库信息 stop slave;
'127.0.01',master_user='ming_masrer',master_password='ming_masrer',master_log_file='mysql-bin.000002', master_log_pos=1321;#开启Slave change master to master_host=
start slave;
master_log_file 是主库 File 值
master_log_pos 是主库 Position 值
在主库执行 show master status; 可获取
6. 查看从库状态
show slave status;
看到 slave_io_running yes 就OK了.