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的官方文 ...
随机推荐
- CentOS7系统DNS主从配置
CentOS7系统DNS主从配置:一.DNS服务器正向解析:1.1 基础环境:主机IP 主机名 操作系统 用途192.168.0.110 master ...
- SELECT 的6大子句
SELECT 6大子句的顺序: SELECT selection_list /*要查询的列名称*/, 结果的字段列表 FROM table_list /*要查询的表名称*/, 后面跟表,视图,多行多列 ...
- 各种Git Bash乱码解决
乱码情景一: 当使用git log 出现乱码时,修改 %GIT_HOME%\etc\gitconfig 文件,加入如下内容: [gui] encoding = utf-8[i18n] commiten ...
- Python网页解析库:用requests-html爬取网页
Python网页解析库:用requests-html爬取网页 1. 开始 Python 中可以进行网页解析的库有很多,常见的有 BeautifulSoup 和 lxml 等.在网上玩爬虫的文章通常都是 ...
- 中高级Java程序员,挑战20k+,知识点汇总(一),Java修饰符
1 前言 工作久了就会发现,基础知识忘得差不多了.为了复习下基础的知识,同时为以后找工作做准备,这里简单总结一些常见的可能会被问到的问题. 2 自我介绍 自己根据实际情况发挥就行 3 Java SE ...
- 青山不遮,毕竟东流,集成Web3.0身份钱包MetaMask以太坊一键登录(Tornado6+Vue.js3)
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_213 上世纪九十年代,海湾战争的时候,一位美军军官担心他们的五角大楼会被敌人的一枚导弹干掉,从而导致在全球的美军基地处于瘫痪状态. ...
- 万答#2,一样的Python代码,为什么可以删表,却不能更新数据
欢迎来到 GreatSQL社区分享的MySQL技术文章,如有疑问或想学习的内容,可以在下方评论区留言,看到后会进行解答 问题 运行下面的这段Python代码,却总是无法更新数据: import pym ...
- MySQL为什么"错误"选择代价更大的索引
欢迎来到 GreatSQL社区分享的MySQL技术文章,如有疑问或想学习的内容,可以在下方评论区留言,看到后会进行解答 MySQL优化器索引选择迷思. 高鹏(八怪)对本文亦有贡献. 1. 问题描述 群 ...
- GoogleTest环境配置以及应用
1 GoogleTest源码编译: GoogleTest代码仓库URL: https://github.com/google/googletest.git 下载源代码: git clone --bra ...
- Python自学教程5-字符串有哪些常用操作
任何编程语言,不管是Python.Java 还是 Golang, 字符串都是最重要的一种数据类型. 但是字符串的操作又很多,初学者经常毫无头绪,不知道从哪儿学起,也不知道哪些操作用得多,今天九柄就和你 ...