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

Docker mysql 主從配置詳解及實例

 更新時間:2016年11月23日 10:09:15   作者:來自地球的外星人  
這篇文章主要介紹了Docker mysql 主從配置詳解及實例的相關資料,需要的朋友可以參考下

Docker mysql 主從配置

1、首先創(chuàng)建兩個文件my-m.cnf(主庫配置) 、my-s.cnf(從庫配置)

my-m.cnf 內容如下

# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#
# The MySQL Community Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[client]
port    = 3306
socket   = /var/run/mysqld/mysqld.sock

[mysqld_safe]
pid-file  = /var/run/mysqld/mysqld.pid
socket   = /var/run/mysqld/mysqld.sock
nice    = 0

[mysqld]
user    = mysql
pid-file  = /var/run/mysqld/mysqld.pid
socket   = /var/run/mysqld/mysqld.sock
port    = 3306
basedir   = /usr
datadir   = /var/lib/mysql
tmpdir   = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp

log-bin = mysql-bin 
server-id = 1 

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address  = 127.0.0.1

#log-error = /var/log/mysql/error.log

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# * IMPORTANT: Additional settings that can override those from this file!
#  The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

主要是這兩行,只需要在原來的配置里面加上就行

log-bin = mysql-bin
server-id = 1

my-s.cnf 內容如下

# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#
# The MySQL Community Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[client]
port    = 3306
socket   = /var/run/mysqld/mysqld.sock

[mysqld_safe]
pid-file  = /var/run/mysqld/mysqld.pid
socket   = /var/run/mysqld/mysqld.sock
nice    = 0

[mysqld]
user    = mysql
pid-file  = /var/run/mysqld/mysqld.pid
socket   = /var/run/mysqld/mysqld.sock
port    = 3306
basedir   = /usr
datadir   = /var/lib/mysql
tmpdir   = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp

log-bin = mysql-bin 
server-id = 2

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address  = 127.0.0.1

#log-error = /var/log/mysql/error.log

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# * IMPORTANT: Additional settings that can override those from this file!
#  The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

同樣,主要的是這兩行

log-bin = mysql-bin
server-id = 2

2、OK,有了配置文件,就可以啟動MySQL了,先啟動主庫

$ docker run -d -e MYSQL_ROOT_PASSWORD=admin --name mysql-master -v /soft/my-m.cnf:/etc/mysql/my.cnf -p 3307:3306 mysql

3、啟動從庫

$ docker run -d -e MYSQL_ROOT_PASSWORD=admin --name mysql-slave -v /soft/my-s.cnf:/etc/mysql/my.cnf -p 3308:3306 mysql

4、連接主庫,并運行以下命令,創(chuàng)建一個用戶用來同步數(shù)據(jù)

$ GRANT REPLICATION SLAVE ON *.* to 'backup'@'%' identified by '123456';

5、查看主庫狀態(tài)

$ show master status;

記住File、Position的值,如果沒查到數(shù)據(jù),請檢查第一、第二步,配置問題。
我查出來的是mysql-bin.000004、312

6、連接到從庫,運行以下命令,設置主庫鏈接

$ change master to master_host='121.32.32.54',master_user='backup',master_password='123456',
master_log_file='mysql-bin.000004',master_log_pos=312,master_port=3307;

7、啟動同步

$ start slave;

8、查看同步狀態(tài)

$ show slave status

如果看到Waiting for master send event.. 什么的就成功了,你現(xiàn)在在主庫上的修改,都會同步到從庫上

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關文章

  • SQL查詢至少連續(xù)七天下單的用戶

    SQL查詢至少連續(xù)七天下單的用戶

    這篇文章介紹了SQL查詢至少連續(xù)七天下單用戶的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-01-01
  • 干掉一堆mysql數(shù)據(jù)庫,僅需這樣一個shell腳本(推薦)

    干掉一堆mysql數(shù)據(jù)庫,僅需這樣一個shell腳本(推薦)

    這篇文章主要介紹了干掉一堆mysql數(shù)據(jù)庫,僅需這樣一個shell腳本,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-04-04
  • mysql 的load data infile

    mysql 的load data infile

    前些日子在開發(fā)一個輿情監(jiān)測系統(tǒng),需要在一個操作過程中往數(shù)據(jù)表里插入大量的數(shù)據(jù),為了改變以往生硬地逐條數(shù)據(jù)插入的笨辦法,也為了提高執(zhí)行效率,決定用load data infile來執(zhí)行數(shù)據(jù)插入。
    2009-05-05
  • MySQL中時間函數(shù)操作大全

    MySQL中時間函數(shù)操作大全

    在使用SQL語言進行數(shù)據(jù)查詢和數(shù)據(jù)分析中,常常需要借助日期時間函數(shù)來計算相關的指標或生成日期輔助列,下面這篇文章主要給大家介紹了關于MySQL中時間函數(shù)操作的相關資料,文中通過圖文介紹的非常詳細,需要的朋友可以參考下
    2022-08-08
  • MySQL數(shù)據(jù)讀寫分離MaxScale相關配置

    MySQL數(shù)據(jù)讀寫分離MaxScale相關配置

    這篇文章主要為大家介紹了MySQL數(shù)據(jù)讀寫分離MaxScale相關配置詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-07-07
  • Mysql優(yōu)化之Zabbix分區(qū)優(yōu)化

    Mysql優(yōu)化之Zabbix分區(qū)優(yōu)化

    這篇文章主要介紹了Mysql優(yōu)化中Zabbix分區(qū)優(yōu)化的詳細方法和優(yōu)缺點分析,一起學習下。
    2017-11-11
  • MySQL刪除和插入數(shù)據(jù)很慢的問題解決

    MySQL刪除和插入數(shù)據(jù)很慢的問題解決

    公司開發(fā)人員在測試環(huán)境中執(zhí)行一條 insert 語句時,需要花費 10 幾秒才可以執(zhí)行成功。所以本文就來解決一下這個問題,感興趣的小伙伴們可以參考一下
    2021-06-06
  • MySQL修改時間添加時間自動更新的兩種方法

    MySQL修改時間添加時間自動更新的兩種方法

    這篇文章主要介紹了MySQL修改時間添加時間自動更新的兩種方法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-09-09
  • mysql5.6.19下子查詢?yōu)槭裁礋o法使用索引

    mysql5.6.19下子查詢?yōu)槭裁礋o法使用索引

    這篇文章主要介紹了mysql5.6.19下子查詢?yōu)槭裁礋o法使用索引,需要的朋友可以參考下
    2014-08-08
  • MySQL 不等于的三種使用及區(qū)別

    MySQL 不等于的三種使用及區(qū)別

    MySQL中常用到判斷符號,而不等于是比較常用的符號,不等于主要是三種,本文主要介紹了三種的使用及區(qū)別,感興趣的同學可以了解一下
    2021-06-06

最新評論