vlambda博客
学习文章列表

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-insecure2..mysqld install xxx(服务名字) --defaults-file="F:/CodeTools/sql/mysql/mysql-5.7.30-master/my.ini"3.net start xxx4.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 PRIVILEGES; #刷新权限
net stop xxx 关闭服务 net start xxx 开启服务 #重启mysql服务mysql -u root -p #登陆mysqlmysql> 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=20explicit_defaults_for_timestamp=true
#开启二进制日志log-bin=mysql-binserver-id=101
#binlog-ignore-db=information_schema#binlog-ignore-db=performance_schema#binlog-ignore-db=mysql#与主库配置保持一致replicate-do-db=ming#replicate-ignore-db=mysqllog-slave-updatesslave-skip-errors=allslave-net-timeout=60

5 .配置从库Mysql服务

数据库配置同主库 具体操作看主库配置
#开启Slavemysql> stop slave; #设置连接主库信息mysql> change master to master_host='127.0.01',master_user='ming_masrer',master_password='ming_masrer',master_log_file='mysql-bin.000002', master_log_pos=1321;#开启Slavemysql> start slave;
master_log_file 是主库 File 值 master_log_pos 是主库 Position 值 在主库执行 show master status; 可获取


6. 查看从库状态


mysql> show slave status;

看到 slave_io_running  yes 就OK了.