欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MySql主從部署的實(shí)現(xiàn)步驟

 更新時(shí)間:2025年09月29日 10:50:39   作者:Neng_Miao  
本文主要介紹了MySql主從部署的實(shí)現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

1、操作環(huán)境

硬件環(huán)境:香橙派5 aarch64架構(gòu)
軟件環(huán)境:Ubuntu 22.04.3 LTS
軟件版本:mysql-8.0.42
操作方式:mysql_1,mysql_2容器
主節(jié)點(diǎn):mysql_1
啟動(dòng)命令:docker run --name mysql_master \
  -p 3308:3306 \
  -v /data/Test/mysql_master/data:/var/lib/mysql \
  -v /data/Test/mysql_master/conf:/etc/mysql/conf.d \
  -v /data/Test/mysql_master/logs:/var/log/mysql \
  -v /etc/localtime:/etc/localtime:ro \
  -e MYSQL_ROOT_PASSWORD=test0123 \
  -e MYSQL_DATABASE=myappdb \
  -e MYSQL_USER=myuser \
  -e MYSQL_PASSWORD=test0123 \
  --restart=always \
  -d mysql:8.0.42 \
  --default-authentication-plugin=mysql_native_password \
  --character-set-server=utf8mb4 \
  --collation-server=utf8mb4_unicode_ci

從節(jié)點(diǎn):mysql_2
啟動(dòng)命令:docker run --name mysql_slave \
  -p 3309:3306 \
  -v /data/Test/mysql_slave/data:/var/lib/mysql \
  -v /data/Test/mysql_slave/conf:/etc/mysql/conf.d \
  -v /data/Test/mysql_slave/logs:/var/log/mysql \
  -v /etc/localtime:/etc/localtime:ro \
  -e MYSQL_ROOT_PASSWORD=test0123 \
  -e MYSQL_DATABASE=myappdb \
  -e MYSQL_USER=myuser \
  -e MYSQL_PASSWORD=test0123 \
  --restart=always \
  -d mysql:8.0.42 \
  --default-authentication-plugin=mysql_native_password \
  --character-set-server=utf8mb4 \
  --collation-server=utf8mb4_unicode_ci

2、配置操作

2.1、主節(jié)點(diǎn)配置

(1)、my.cnf配置(容器/etc/mysql/conf.d/my.cnf,宿主機(jī)/data/Test/mysql_master/conf/master.cnf)
[client]
default-character-set=utf8mb4
 
[mysql]
default-character-set=utf8mb4
 
[mysqld]
# 設(shè)置時(shí)區(qū)
default-time_zone = '+8:00'
#設(shè)置密碼驗(yàn)證規(guī)則
authentication_policy=mysql_native_password
# 限制導(dǎo)入和導(dǎo)出的數(shù)據(jù)目錄
# 為空,不限制導(dǎo)入到處的數(shù)據(jù)目錄;
secure_file_priv=
init_connect='SET collation_connection = utf8mb4_general_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
skip-character-set-client-handshake
skip-name-resolve
 
# 開啟logbin
log_bin=binlog
# binlog日志格式
binlog_format=ROW
# mysql主從備份serverId
server_id=1
 
#參數(shù)優(yōu)化,避免mysql占用太多內(nèi)存
# 減少緩沖池大小
innodb_buffer_pool_size = 64M
# 降低臨時(shí)表大小
tmp_table_size = 16M
# 設(shè)置最大連接數(shù)
max_connections = 10

可選參數(shù)

# 0表示讀寫 (主機(jī)),1表示只讀(從機(jī))
read-only=0

#設(shè)置日志文件保留的時(shí)長,單位是秒
binlog_expire_logs_seconds=6000

#控制單個(gè)二進(jìn)制日志大小。此參數(shù)的最大和默認(rèn)值是1GB
max_binlog_size=20

#設(shè)置不要復(fù)制的數(shù)據(jù)庫
binlog-ignore-db=test

#設(shè)置需要復(fù)制的數(shù)據(jù)庫,不寫參數(shù)則默認(rèn)全部記錄,可以填寫多個(gè)
binlog-do-db=需要復(fù)制的主數(shù)據(jù)庫名字
例如:
binlog-do-db=dbtest01
binlog-do-db=dbtest02

#設(shè)置binlog格式
binlog_format=STATEMENT
(2)、主節(jié)點(diǎn)數(shù)據(jù)庫創(chuàng)建用戶
#進(jìn)入容器內(nèi)部
docker exec -it mysql_master /bin/bash
#登錄mysql
mysql -u root -p
#查看數(shù)據(jù)庫
show databases;
#切換到mysql庫
use mysql;
#創(chuàng)建master用戶
create USER 'master'@'%' IDENTIFIED BY 'root';
grant all on *.* to 'master'@'%';
FLUSH PRIVILEGES;

2.2、從節(jié)點(diǎn)配置

(1)、server.cnf配置(容器/etc/mysql/conf.d/server.cnf,宿主機(jī)的/data/Test/mysql_2/conf/server.cnf)

[client]
default-character-set=utf8mb4
 
[mysql]
default-character-set=utf8mb4
 
[mysqld]
# 設(shè)置時(shí)區(qū)
default-time_zone = '+8:00'
#設(shè)置密碼驗(yàn)證規(guī)則
authentication_policy=mysql_native_password
# 限制導(dǎo)入和導(dǎo)出的數(shù)據(jù)目錄
# 為空,不限制導(dǎo)入到處的數(shù)據(jù)目錄;
secure_file_priv=
init_connect='SET collation_connection = utf8mb4_general_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
skip-character-set-client-handshake
skip-name-resolve
 
#server_id不要和主庫的server_id相同就行
server_id=2
#一般從數(shù)據(jù)庫作為讀數(shù)據(jù)庫
default-storage-engine=MyISAM

(2)、從節(jié)點(diǎn)數(shù)據(jù)庫創(chuàng)建用戶

#進(jìn)入容器內(nèi)部
docker exec -it mysql_slave /bin/bash
#登錄mysql
mysql -u root -p
#查看數(shù)據(jù)庫
show databases;
#切換到mysql庫
use mysql;
#創(chuàng)建slave用戶
create USER 'slave'@'%' IDENTIFIED BY 'root';
grant all on *.* to 'slave'@'%';
FLUSH PRIVILEGES;

2.3、配置數(shù)據(jù)同步

(1)、登錄master節(jié)點(diǎn)數(shù)據(jù)庫

#查看master節(jié)點(diǎn)binlog日志狀態(tài)
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000003 |      841 |              |                  |                   |
+---------------+----------+--------------+------------------+-------------------+

(1)、登錄slave節(jié)點(diǎn)數(shù)據(jù)庫

#停止slave
stop slave;

#查看master節(jié)點(diǎn)binlog日志狀態(tài),MASTER_LOG_FILE、MASTER_LOG_POS根據(jù)master數(shù)據(jù)庫查詢信息配置
 CHANGE MASTER TO MASTER_HOST = '172.17.0.5', #host
 MASTER_PORT = 3306,#
 MASTER_USER = 'master',#binlog
 MASTER_PASSWORD = 'passwd',#binlog
 MASTER_LOG_FILE = 'binlog.000003',#binlog1
 MASTER_LOG_POS = 841;
 
#啟動(dòng)slave
start slave;

#查看slave庫狀態(tài)
mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for source to send event
                  Master_Host: 172.17.0.5
                  Master_User: slave
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog.000003
          Read_Master_Log_Pos: 841
               Relay_Log_File: 4b87ab620b91-relay-bin.000002
                Relay_Log_Pos: 323
        Relay_Master_Log_File: binlog.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_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: 841
              Relay_Log_Space: 540
              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: 61357c39-2e76-11f0-9f6f-0242ac110005
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Replica 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.01 sec)

2.4、測試

(1)、master節(jié)點(diǎn)創(chuàng)建測試表及插入數(shù)據(jù)

mysql -u root -h 127.0.0.1 -p -P3308

#登錄master節(jié)點(diǎn)創(chuàng)建簡單數(shù)據(jù)表
CREATE TABLE `test` (
  `id` int NOT NULL AUTO_INCREMENT,
  `Test_str` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

mysql> show tables;
+-------------------+
| Tables_in_myappdb |
+-------------------+
| test              |
+-------------------+
1 row in set (0.00 sec)

mysql> select * from test;
Empty set (0.00 sec)

mysql> INSERT INTO test (Test_str) VALUES( '1');
Query OK, 1 row affected (0.02 sec)

mysql> select * from test;
+----+----------+
| id | Test_str |
+----+----------+
|  1 | 1        |
+----+----------+
1 row in set (0.00 sec)

(2)、slave節(jié)點(diǎn)查看數(shù)據(jù)同步

mysql -u root -h 127.0.0.1 -p -P3309

mysql> use myappdb
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+-------------------+
| Tables_in_myappdb |
+-------------------+
| test              |
+-------------------+
1 row in set (0.01 sec)

mysql> select * from test;
+----+----------+
| id | Test_str |
+----+----------+
|  1 | 1        |
+----+----------+
1 row in set (0.01 sec)

到此這篇關(guān)于MySql主從部署的實(shí)現(xiàn)步驟的文章就介紹到這了,更多相關(guān)MySql主從部署內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 在MySQL中使用JOIN語句進(jìn)行連接操作的詳細(xì)教程

    在MySQL中使用JOIN語句進(jìn)行連接操作的詳細(xì)教程

    這篇文章主要介紹了在MySQL中使用JOIN語句進(jìn)行連接操作的詳細(xì)教程,是MySQL入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下
    2015-05-05
  • 基于mysql replication的問題總結(jié)

    基于mysql replication的問題總結(jié)

    本篇文章是對(duì)mysql中replication的問題進(jìn)行了詳細(xì)分析介紹,需要的朋友參考下
    2013-06-06
  • MySQL進(jìn)階查詢、聚合查詢和聯(lián)合查詢

    MySQL進(jìn)階查詢、聚合查詢和聯(lián)合查詢

    這篇文章主要介紹了MySQL數(shù)據(jù)庫的進(jìn)階查詢,聚合查詢及聯(lián)合查詢,文中有詳細(xì)的代碼示例,需要的朋友可以參考閱讀
    2023-04-04
  • MySQL刪除binlog日志文件的三種實(shí)現(xiàn)方式

    MySQL刪除binlog日志文件的三種實(shí)現(xiàn)方式

    本文介紹了三種刪除MySQL binlog日志文件的方法,包含手動(dòng)刪除、使用SQL命令刪除和設(shè)置自動(dòng)清理,具有一定的參考價(jià)值,感興趣的可以了解一下
    2025-02-02
  • MySQL使用命令創(chuàng)建、刪除、查詢索引的介紹

    MySQL使用命令創(chuàng)建、刪除、查詢索引的介紹

    今天小編就為大家分享一篇關(guān)于MySQL使用命令創(chuàng)建、刪除、查詢索引的介紹,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • mysql 5.7.17 winx64安裝配置方法圖文教程

    mysql 5.7.17 winx64安裝配置方法圖文教程

    這篇文章主要為大家分享了mysql 5.7.17winx64安裝配置方法圖文教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • MySQL聯(lián)合索引與最左匹配原則的實(shí)現(xiàn)

    MySQL聯(lián)合索引與最左匹配原則的實(shí)現(xiàn)

    最左匹配原則在我們MySQL開發(fā)過程中和面試過程中經(jīng)常遇到,為了加深印象和理解,我在這里把MySQL的最左匹配原則詳細(xì)的講解一下,感興趣的可以了解一下
    2023-12-12
  • MySQL常見問題解決辦法以及自動(dòng)化安裝腳本

    MySQL常見問題解決辦法以及自動(dòng)化安裝腳本

    自動(dòng)化運(yùn)維是一個(gè)DBA應(yīng)該掌握的技術(shù),其中,自動(dòng)化安裝數(shù)據(jù)庫是一項(xiàng)基本的技能,下面這篇文章主要給大家介紹了關(guān)于MySQL常見問題解決辦法以及自動(dòng)化安裝腳本的相關(guān)資料,需要的朋友可以參考下
    2024-05-05
  • MySQL表約束的實(shí)現(xiàn)

    MySQL表約束的實(shí)現(xiàn)

    本文主要介紹了MySQL表約束的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07
  • MySQL慢查詢相關(guān)參數(shù)原理解析

    MySQL慢查詢相關(guān)參數(shù)原理解析

    這篇文章主要介紹了MySQL慢查詢相關(guān)參數(shù)原理解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-11-11

最新評(píng)論