mysql8.0.25版本设置主从数据库,并且从库只读
具体操作步骤
说明:主从数据库版本一致
1.主库创建同步使用的用户
create user 'repl'@'%' identified with 'mysql_native_password' by 'repl_User_123';
GRANT ALL privileges ON *.* TO 'repl'@'%' with grant option;
flush privileges;
# 必要时主库需要开启远程连接,供其他ip的主机连接
该用户权限仅设置replication slave,replication client权限,从库开启同步会报如下错误:
2022-05-19T07:33:32.846062Z 13 [System] [MY-010562] [Repl] Slave I/O thread for channel '': connected to master 'repl@192.168.0.218:3306',replication started in log 'mysql-bin.000007' at position 165418
2022-05-19T07:33:32.846996Z 13 [Warning] [MY-010551] [Repl] "SELECT UNIX_TIMESTAMP()" failed on master, do not trust column Seconds_Behind_Master of SHOW SLAVE STATUS. Error: Aborted connection 1549 to db: 'unconnected' user: 'repl' host: '192.168.0.36' (init_connect command failed) (1184)
2022-05-19T07:33:32.847995Z 13 [ERROR] [MY-010584] [Repl] Slave I/O for channel '': The slave I/O thread stops because a fatal error is encountered when it try to get the value of SERVER_ID variable from master. Error: , Error_code: MY-000000
用户权限中没有with grant option,,从库开启同步会报如下错误:
2022-05-19T08:12:29.643585Z 16 [Warning] [MY-010584] [Repl] Slave: You are not allowed to create a user with GRANT Error_code: MY-001410
2022-05-19T08:12:29.643600Z 16 [ERROR] [MY-010586] [Repl] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.000007' position 378622
2.主库修改配置文件,开启binlog
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid
lower_case_table_names=1
port=3306
default_authentication_plugin=mysql_native_password
default-storage-engine=INNODB
character-set-server=utf8mb4
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_connections=10000
max_user_connections=5000
max_connect_errors=100
wait_timeout=86400
interactive_timeout=1800
############ 如下这几行是新增的 ####################
server_id=1
log_bin=/data/mysql/mysql-bin
log_slave_updates=on
binlog_format=row
expire_logs_days=7
skip_slave_start=1
sync_binlog=1
binlog-do-db=park_cloud_db # 只同步这个数据库
# 如下四个默认数据库不同步
binlog-ignore-db=information_schema
binlog-ignore-db=performation_schema
binlog-ignore-db=sys
binlog-ignore-db=mysql
skip-name-resolve
############ 如上这几行是新增的 ####################
[mysql]
default-character-set=utf8mb4
[client]
port=3306
default-character-set=utf8mb4
3.获取主库binlog信息
[15:24:55]mysql> show variables like 'log_bin';
[15:24:55]+---------------+-------+
[15:24:55]| Variable_name | Value |
[15:24:55]+---------------+-------+
[15:24:55]| log_bin | ON |
[15:24:55]+---------------+-------+
[15:28:45]mysql> show variables like 'server_id';
[15:28:45]+---------------+-------+
[15:28:45]| Variable_name | Value |
[15:28:45]+---------------+-------+
[15:28:45]| server_id | 1 |
[15:28:45]+---------------+-------+
[15:28:45]1 row in set (0.00 sec)
[15:38:12]mysql> show master status;
[15:38:12]+------------------+----------+---------------+--------------------------------------------------+-------------------+
[15:38:12]| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
[15:38:12]+------------------+----------+---------------+--------------------------------------------------+-------------------+
[15:38:12]| mysql-bin.000007 | 315692 | park_cloud_db | information_schema,performation_schema,sys,mysql | |
[15:38:12]+------------------+----------+---------------+--------------------------------------------------+-------------------+
[15:38:12]1 row in set (0.00 sec)
记录下 mysql-bin.000007 和 315692
4.从库修改配置文件
[mysqld]
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid
lower_case_table_names=1
port=3306
default_authentication_plugin=mysql_native_password
default-storage-engine=INNODB
character-set-server=utf8mb4
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_connections=10000
max_user_connections=5000
max_connect_errors=100
wait_timeout=86400
interactive_timeout=1800
############ 如下这几行是新增的 ####################
server_id=2
log_bin=/data/mysql/mysql-bin
log_slave_updates=on
relay-log-index=/data/mysql/slave-relay-bin.index
relay-log=slave-relay-bin
replicate-do-db=park_cloud_db #要同步的数据库
slave-net-timeout=60
skip-name-resolve
read_only=1 #限定普通用户只读
super_read_only=on #限定root只读
############ 如上这几行是新增的 ####################
[mysql]
default-character-set=utf8mb4
[client]
port=3306
default-character-set=utf8mb4
5.从库导入主库里的要同步的数据库数据,也就是导入park_cloud_db里的数据
6.从库开启同步
stop salve;
CHANGE MASTER TO MASTER_HOST='192.168.0.218',
MASTER_PORT=3306,
MASTER_USER='repl',
MASTER_PASSWORD='repl_User_123',
MASTER_LOG_FILE='mysql-bin.000007',
MASTER_LOG_POS=315692;
start slave;
show slave status\G
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.218
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 742802
Relay_Log_File: slave-relay-bin.000005
Relay_Log_Pos: 75230
Relay_Master_Log_File: mysql-bin.000007
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: park_cloud_db
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 742802
Relay_Log_Space: 75607
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_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: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 4b4e33f1-cfeb-11eb-b6fc-fa163e56a76b
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.00 sec)
ERROR:
No query specified
mysql8.0.25版本设置主从数据库,并且从库只读的更多相关文章
- Mysql8.0.17版本不能自动创建activiti表的坑
maven项目如下: 配置好数据库,和activiti的配置之后,开始执行流程部署 package com.yuanqiao.first_activiti.deployment; import jav ...
- MYSQL8.0以上版本ROOT密码报错及修改
在登录数据库过程中,如果遇到忘记root密码时,该如何解决? 1.使用管理员权限打开命令提示符,在命令行中输入: net stop mysql 2.待mysql服务停止后,输入: mysqld -- ...
- SpringMVC+MyBatis+Druid使用MySQL8.0.11版本
1.使用MySQL8.0.11版本,要使用5.1.45或其他高版本驱动jar包,我本地使用的是最新的8.0.11 2.更换了MySQL驱动后,报Cannot find class [com.aliba ...
- mysql8.0以上版本修改密码问题记录
参考链接: https://blog.csdn.net/qq_27820551/article/details/101488430 https://blog.csdn.net/mukouping82/ ...
- 设置SQLServer数据库中某些表为只读的多种方法
原文:设置SQLServer数据库中某些表为只读的多种方法 翻译自:http://www.mssqltips.com/sqlservertip/2711/different-ways-to-make- ...
- Java连接MySQL8.0以上版本数据库方式
MySQL 8.0 开始数据库相比常用的 5.X 版本发生了比较大的变化,我们在连接数据库的过程中许多地方也要发生一些变化. 总结一下,想要利用 mysql-connector-java 与 MySQ ...
- 登录注册页面(连接MySQL8.0.15版本)
原文链接:https://mp.weixin.qq.com/s?__biz=MzI4Njg5MDA5NA==&mid=2247483779&idx=1&sn=e23e68e96 ...
- MySQL8.0本地访问设置为远程访问权限
1.登录MySQL mysql -u root -p 输入您的密码 2.选择 mysql 数据库 use mysql; 因为 mysql 数据库中存储了用户信息的 user 表. 3.在 mysql ...
- MySql5.5以上版本设置主从结构的例子
为了实现读写分离,一般都需要先设置好mysql的主从结构,网上现有的mysql配置大都基于低版本,在5.5以上版本无法配置成功,所以参考了官方文档,写了这篇笔记. *主要参考Mysql 5.6的官方文 ...
随机推荐
- JAVA中简单的for循环竟有这么多坑,你踩过吗
JAVA中简单的for循环竟有这么多坑,你踩过吗 实际的业务项目开发中,大家应该对从给定的list中剔除不满足条件的元素这个操作不陌生吧? 很多同学可以立刻想出很多种实现的方式,但你想到的这些实现方式 ...
- 如何在.Net Framework应用中请求HTTP2站点
背景介绍 本文的需求背景是对接苹果公司的推送服务(APNS),苹果在安全方面比较积极,已经严格限制API只支持HTTP2.但是我这里的应用目前仍然是.NET Framework平台,所以必须寻找一种解 ...
- SpringBoot接口 - 如何优雅的写Controller并统一异常处理?
SpringBoot接口如何对异常进行统一封装,并统一返回呢?以上文的参数校验为例,如何优雅的将参数校验的错误信息统一处理并封装返回呢?@pdai 为什么要优雅的处理异常 如果我们不统一的处理异常,经 ...
- jdbc 07: 解决sql注入
jdbc连接mysql,解决sql注入问题 package com.examples.jdbc.o7_解决sql注入; import java.sql.*; import java.util.Hash ...
- 【亲测有效】Tecnomatix PDPS 软件安装及常见问题!附授权文件
据说,每个学习 Siemens PLM 仿真的同学,都要先被 TecnoMatix PDPS 软件的安装给折磨过! 经过几天的安装过程,果然,此话不虚~~~ 把自己的安装步骤贴出来,免得大家再走弯路. ...
- 以十字链表为存储结构实现矩阵相加(严5.27)--------西工大noj
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> typedef int ElemT ...
- BufferedWriter字符缓冲输出流和BufferedReader字符缓冲输入流
package com.yang.Test.BufferedStudy; import java.io.BufferedWriter; import java.io.FileWriter; impor ...
- Dubbo源码(五) - 服务目录
前言 本文基于Dubbo2.6.x版本,中文注释版源码已上传github:xiaoguyu/dubbo 今天,来聊聊Dubbo的服务目录(Directory).下面是官方文档对服务目录的定义: 服务目 ...
- Windows环境中Hadoop配置
我们之前已经在Windows中安装好了Hadoop,并且配置了环境变量.如果要在本地上运行的,还需要这两个文件,可以去找一下,放到Hadoop的bin目录下面.这样我们写好的mr程序就可以直接在Win ...
- Radmin自动登录器 v3.0
Radmin自动登录器 v3.0 - By: ybmj@vip.163.com 20150615 用户手册 下载地址:https://download.csdn.net/download/shuren ...