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的官方文 ...
随机推荐
- 爬虫(14) - Scrapy-Redis分布式爬虫(1) | 详解
1.什么是Scrapy-Redis Scrapy-Redis是scrapy框架基于redis的分布式组件,是scrapy的扩展:分布式爬虫将多台主机组合起来,共同完成一个爬取任务,快速高效地提高爬取效 ...
- Node.js精进(9)——性能监控(上)
市面上成熟的 Node.js 性能监控系统,监控的指标有很多. 以开源的 Easy-Monitor 为例,在系统监控一栏中,指标包括内存.CPU.GC.进程.磁盘等. 这些系统能全方位的监控着应用的一 ...
- springboot java -jar指定启动的jar外部配置文件
Limited Setting Effect 中文描述 Java 8 -Xbootclasspath:<path> Sets the search path for bootstrap c ...
- NOI / 2.5基本算法之搜索-6044:鸣人和佐助详解
总时间限制: 1000ms 内存限制: 65536kB 题目 佐助被大蛇丸诱骗走了,鸣人在多少时间内能追上他呢? 已知一张地图(以二维矩阵的形式表示)以及佐助和鸣人的位置.地图上的每个位置都可以走到, ...
- 类型转换_str()函数与int()函数
数据类型转换 需要将不同数据类型拼接在一起的时候就需要先进行数据类型转换 str+str//这里的+叫做连接字符,有点类似C++中的操作符重载,老对象里面的内容了 在python中整型和字符串类型不能 ...
- DQL分组查询和DQL分页查询
分组查询: 1.语法:group by 分组字段: 2.注意: 分组之后查询的字符按:分组字段.聚合函数 where 和having 的区别 where再分组前进行限定,如果不满足条件则不参与分组.h ...
- 43%非常看好TypeScript…解读“2022前端开发者现状报告”
摘要:近日,The Software House 发布了"2022前端开发者现状报告",笔者在此对报告内容进行解读,供大家参考. 本文分享自华为云社区<"2022前 ...
- DolphinScheduler 荣获 2021 中国开源云联盟优秀开源项目奖!
点击上方 蓝字关注我们 好消息,中国开源云联盟(China Open Source Cloud League,简称"COSCL")于近日公布 2021 杰出开源贡献者.优秀开源项目 ...
- Ceph创建一个新集群 报错: File "/usr/bin/ceph-deploy", line 18, in..........
[root@ceph-node1 ceph]# ceph-deploy new node1 Traceback (most recent call last): File "/usr/bin ...
- 在 Linux 安装 Java 的流程
前言 安装流程一共为 4 个步骤,分为下载.解压.配置.检查. 下载 Oracle 官网下载 JDK. 解压 上传至 Linux 中(可使用宝塔面板上传),解压安装包: ubuntu@VM-0-6-u ...