当前位置: 首页 > news >正文

湘西土家族苗族自治州网站建设_网站建设公司_阿里云_seo优化

彩票网站开发制作平台软件,郑州做网站软件,长尾关键词挖掘词工具,dedecms 百度网站地图文章目录 MySQL完成主从复制教程准备#xff1a;原理#xff1a;步骤#xff1a; 推荐文章 MySQL完成主从复制教程 主从复制#xff08;也称 AB 复制#xff09;就是将一个服务器#xff08;主服务器#xff09;的数据复制到一个或多个MySQL数据库服务器#xff08;从… 文章目录 MySQL完成主从复制教程准备原理步骤 推荐文章 MySQL完成主从复制教程 主从复制也称 AB 复制就是将一个服务器主服务器的数据复制到一个或多个MySQL数据库服务器从服务器中。 可以根据配置指定复制哪个库哪个表数据。 可以想到复制是通过异步的。 准备 2台版本一致的服务器数据库一台作为主库、一台作为从库 我的两个数据库版本5.7 一台服务器搭建2个数据库实例教程http://t.csdnimg.cn/aaErM 原理 主库一旦变更数据就会写入二进制日志文件Binary log从库IO线程 I/O thread连接到主库读取二进制日志文件内容并写入自己的中继日志文件Realy log然后从库 SQL thread 定时检查中继日志 Realy log发现有更新的内容就自己的库执行一遍。 从服务器都会copy主服务器二进制日志的全部内容到副本然后从服务器设备负责决定应该执行副本中的哪些语句。 步骤 主库配置my.cnf文件指定唯一server-id [mysqld] ## 同一局域网内注意要唯一 server-id100 ## 开启二进制日志功能可以随便取关键 log-binmysql-bin ## 复制过滤不需要备份的数据库不输出mysql库一般不同步 binlog-ignore-dbmysql ## 为每个session 分配的内存在事务过程中用来存储二进制日志的缓存 binlog_cache_size1M ## 主从复制的格式mixed,statement,row默认格式是statement binlog_formatmixed从库配置my.cnf文件指定唯一server-id [mysqld] ## 设置server_id,注意要唯一 server-id102 ## 开启二进制日志功能以备Slave作为其它Slave的Master时使用 log-binmysql-slave-bin ## relay_log配置中继日志 relay_logedu-mysql-relay-bin ##复制过滤不需要备份的数据库不输出mysql库一般不同步 binlog-ignore-dbmysql ## 如果需要同步函数或者存储过程 log_bin_trust_function_creatorstrue ## 为每个session 分配的内存在事务过程中用来存储二进制日志的缓存 binlog_cache_size1M ## 主从复制的格式mixed,statement,row默认格式是statement binlog_formatmixed ## 跳过主从复制中遇到的所有错误或指定类型的错误避免slave端复制中断。 ## 如1062错误是指一些主键重复1032错误是因为主从数据库数据不一致 slave_skip_errors1062重启3306、3307服务使配置生效 # 查看mysql 3306、3307进程 rootsongdanminserver:[/usr/local/mysql/3306/run]ps -ef | grep mysqld root 8568 25795 0 13:40 pts/0 00:00:00 grep --colorauto mysqld mysql 30201 1 0 Nov10 ? 00:07:13 /usr/local/mysql/bin/mysqld --defaults-file/usr/local/mysql/3306/my.cnf --usermysql mysql 30473 1 0 Nov10 ? 00:07:46 /usr/local/mysql/bin/mysqld --defaults-file/usr/local/mysql/3307/my.cnf --usermysql # 停止3306、3307进程服务 rootsongdanminserver:[/usr/local/mysql/3306/run]kill 30201 rootsongdanminserver:[/usr/local/mysql/3306/run]kill 30473 # 查看mysql进程 rootsongdanminserver:[/usr/local/mysql/3306/run]ps -ef | grep mysqld root 8614 25795 0 13:41 pts/0 00:00:00 grep --colorauto mysqld # 查看端口占用情况是否没有3306、3307 rootsongdanminserver:[/usr/local/mysql/3306/run]netstat -ntl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp6 0 0 :::111 :::* LISTEN tcp6 0 0 :::8080 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN tcp6 0 0 127.0.0.1:8005 :::* LISTEN # 重新启动3306、3307 rootsongdanminserver:[/usr/local/mysql/3306]nohup /usr/local/mysql/bin/mysqld --defaults-file/usr/local/mysql/3306/my.cnf --usermysql [1] 9413 rootsongdanminserver:[/usr/local/mysql/3306]nohup: ignoring input and appending output to ‘nohup.out’ ^C rootsongdanminserver:[/usr/local/mysql/3307]nohup /usr/local/mysql/bin/mysqld --defaults-file/usr/local/mysql/3307/my.cnf --usermysql [2] 9457 rootsongdanminserver:[/usr/local/mysql/3307]nohup: ignoring input and appending output to ‘nohup.out’ ^C rootsongdanminserver:[/usr/local/mysql/3306]# 查看mysql 3306、3307进程 rootsongdanminserver:[/usr/local/mysql/3307]ps -ef | grep mysqld mysql 9413 25795 0 13:52 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file/usr/local/mysql/3306/my.cnf --usermysql mysql 9559 25795 1 13:54 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file/usr/local/mysql/3307/my.cnf --usermysql root 9608 25795 0 13:54 pts/0 00:00:00 grep --colorauto mysqld登录主库授予从库连接主库并复制主库数据的权限刷新权限生效 # 登录主库3306 rootsongdanminserver:[/usr/local/mysql/3306]mysql -uroot -h127.0.0.1 -p -P3306 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.36-log MySQL Community Server (GPL)Copyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type help; or \h for help. Type \c to clear the current input statement.# 授予从库3307的root用户在指定从库ip上从主库复制所有库、所有表数据的权限 mysql grant replication slave, replication client on *.* to root你的从库服务器ip identified by 你的从库root用户密码; Query OK, 0 rows affected, 1 warning (0.00 sec)# 刷新权限 mysql flush privileges; Query OK, 0 rows affected (0.00 sec)# 查看MySQL现在有哪些用户及对应的IP权限可以看到你刚授权的从库user,host mysql select user,host from mysql.user; ----------------------------- | user | host | ----------------------------- | root | % | | root | 121.41.59.91 | | mysql.session | localhost | | mysql.sys | localhost | ----------------------------- 4 rows in set (0.00 sec)# 查看主库3306的binlog文件名和位置 mysql show master status; ------------------------------------------------------------------------------- | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | ------------------------------------------------------------------------------- | mysql-bin.000003 | 612 | | mysql | | ------------------------------------------------------------------------------- 1 row in set (0.00 sec)登录从库连接主库指定主库ip、主库为从库连接所创建的用户、密码、从库从主库哪个二进制文件的哪里开始读取数据等 # 登录从库3307 rootsongdanminserver:[/usr/local/mysql/3306]mysql -uroot -h127.0.0.1 -p -P3307 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.36-log MySQL Community Server (GPL)Copyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type help; or \h for help. Type \c to clear the current input statement.# 配置连接主库3306 # change master to master_host主库服务器ip, master_userroot(上一步主库授权从库能进行复制的用户), master_password123456(上一步主库授权从库能进行复制的密码), master_port3306(主库端口), master_log_filemysql-bin.000002(上一步查看到的主库日志文件名称),master_log_pos2079(上一步查看到的主库日志文件位置); mysql change master to master_host121.41.53.91, master_userroot, master_password123456, master_port3306, master_log_filemysql-bin.000003,master_log_pos612; Query OK, 0 rows affected, 1 warning (0.02 sec)从库启动主从复制查看是否连接主库成功 # 启动从库复制主库 mysql start slave; Query OK, 0 rows affected (0.00 sec)# 查看主从复制状态查看Slave_IO_Running、Slave_SQL_Running 是否为yes mysql show slave status\G; *************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 121.41.53.91 # 绑定的主库ipMaster_User: root # 主库用户Master_Port: 3306 # 主库端口Connect_Retry: 60 Master_Log_File: mysql-bin.000003 # 主库同步日志从这读取主库数据Read_Master_Log_Pos: 612Relay_Log_File: edu-mysql-relay-bin.000002 # 从库中继日志Relay_Log_Pos: 320Relay_Master_Log_File: mysql-bin.000003Slave_IO_Running: Yes # 这里是yes 说明复制成功Slave_SQL_Running: Yes # 这里是yes 说明复制成功Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 612Relay_Log_Space: 531Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 100Master_UUID: cfb53930-7fa2-11ee-8ea9-00163e2859d2Master_Info_File: /usr/local/mysql/3307/data/master.infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec)# 停止从库复制主库 mysql stop slave; Query OK, 0 rows affected (0.01 sec) 测试主从复制是否成功在主库建表插入数据查看从库是否也有 在主库执行操作 新增库新增表新增数据修改数据删除数据 查看从库3307是否发生变化 # 进入主库3306 rootsongdanminserver:[/usr/local/mysql/3306]mysql -uroot -h127.0.0.1 -p -P3306 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 16 Server version: 5.7.36-log MySQL Community Server (GPL)Copyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type help; or \h for help. Type \c to clear the current input statement. # 新建数据库 my_test mysql create database my_test; Query OK, 1 row affected (0.00 sec)mysql use my_test; Database changed mysql CREATE TABLE test (- id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,- name VARCHAR(30) NOT NULL,- email VARCHAR(50) NOT NULL,- reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP- ); Query OK, 0 rows affected (0.01 sec) # 插入初识数据 mysql INSERT INTO test (name, email)- VALUES (John Doe, johnexample.com); Query OK, 1 row affected (0.00 sec)# 查看从库变化​ 注意如果出现从库复制失败没有效果时候从库重新绑定主库执行6 造成这类问题的原因一般是在主从复制的时候基于创建表然后又去删除和操作了数据表或者表。 推荐文章 【史上最细教程】一台服务器上搭建2个MySQL实例
http://www.ihoyoo.com/news/81844.html

相关文章:

  • 江门网站制作wordpress无插件美化
  • 昆明公司网站建设免费生成短链接
  • 一个专业做设计的网站红杉树装饰有限公司装修的怎样
  • 商城网站建设资讯百度竞价广告收费标准
  • 合肥做网站做推广学什么技术比较有发展
  • 凡天网网站建设微信网页
  • 备案号 不放在网站首页网站建设英文合同
  • 网站 托管房产建设网站
  • 备案网站名称怎么写江苏建工
  • 做网站一般需要多少钱现在什么网站做推广比较好
  • 公司网站制作网络公司济宁专业网站建设
  • 江西省建设招标网站网上找装修设计师
  • 鄂尔多斯建设招投标网站网站建设电话销售录音
  • 手机wap网站多少钱一学一做征文网站
  • 怎么看网站被降权中国科技成果
  • 校园网站的作用山西大学物理电子工程学院研招网
  • 网站开发需要后台吗自己建的网站打开的特别慢
  • 网站建设营销策略网络营销方案设计范文
  • 广州海外建站网站安全建设模板下载
  • 杭州市富阳区建设局网站重庆活动轨迹公布
  • 山西公司响应式网站建设平台网站关键词库怎么做有什么效果
  • 国外设计师灵感网站用wordpress做视频网站
  • 深圳电商网站设计专业网站优化关键词
  • 老渔哥网站建设公司北京海淀财政局网站
  • 网站优化 检测响应速度wordpress小夜
  • wap 网站的盗链问题做艺术品的网站有哪些
  • 网站关键词全国各地的排名情况大型网站系统解决方案
  • 利用织梦搭网站如何用phpstudy做网站
  • python做项目的网站seo门户网站建设方案
  • 网站建设技术app下载网站个人备案需要什么资料