1. 程式人生 > >MySQL 5.7 主從資料庫搭建

MySQL 5.7 主從資料庫搭建

1.資料庫安裝

安裝MySQL5.7,主資料庫為192.168.2.221,從資料庫為192.168.2.222,伺服器記憶體8G

sudo apt-get install mysql-server

2.主資料庫配置

  • 修改/etc/mysql/my.cnf

    #master

    [mysqld]

    #common
    port = 3306
    bind-address = 0.0.0.0
    skip-name-resolve
    max_connections = 512

    #replicate
    server_id = 1
    #replicate database
    binlog-do-db = test
    log_bin = mysql-bin

    #innodb
    innodb_buffer_pool_size = 6G
    innodb_flush_method = O_DIRECT
    innodb_log_buffer_size = 16M
    innodb_log_file_size = 2G
    innodb_log_files_in_group = 2

    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

  • 進入資料庫,新增同步使用者

    shell>mysql -uroot -p

    mysql>create user ‘repl’@’%’ identified by ‘password’;
    mysql>grant replication slave on * . * to ‘repl’@’%’;

  • 記錄master資訊,File和Position

    mysql>show master status\G
    ***************** 1. row *****************
    File: mysql-bin.000001
    Position: 154
    Binlog_Do_DB: test
    Binlog_Ignore_DB:
    Executed_Gtid_Set:

  • 重啟資料庫

    sudo /etc/init.d/mysql restart

3.從資料庫配置

  • 修改/etc/mysql/my.cnf

    #slave

    [mysqld]

    #common
    port = 3306
    bind-address = 0.0.0.0
    skip-name-resolve
    max_connections = 512

    #replicate
    server_id = 2
    #replicate database
    replicate-do-db = test

    #innodb
    innodb_buffer_pool_size = 6G
    innodb_flush_method = O_DIRECT
    innodb_log_buffer_size = 16M
    innodb_log_file_size = 2G
    innodb_log_files_in_group = 2
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

  • 配置slave

    shell>mysql -uroot -p
    mysql>change master to master_host =’192.168.2.221’,master_port=3306,master_user=’repl’,master_password=’password’,master_log_file=’mysql-bin.000001’,master_log_pos=154;
    mysql>start slave;

  • 重啟資料庫

    shell>sudo /etc/init.d/mysql restart
    shell>mysql -uroot -p
    mysql>show slave status\G;
    ***************** 1. row *****************
    Slave_IO_State: Waiting for master to send event
    Master_Host: 192.168.2.221
    Master_User: repl
    Master_Port: 3306
    Connect_Retry: 60
    Master_Log_File: mysql-bin.000006
    Read_Master_Log_Pos: 84848971
    Relay_Log_File: database-2-relay-bin.000018
    Relay_Log_Pos: 84849184
    Relay_Master_Log_File: mysql-bin.000006
    Slave_IO_Running: Yes
    Slave_SQL_Running: Yes
    Replicate_Do_DB: test
    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: 84848971
    Relay_Log_Space: 84849443
    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: afa582dc-2628-11e6-9226-408d5ce1124f
    Master_Info_File: /var/lib/mysql/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:

  • 連線成功

4.批量插入效能

批量插入語句

insert into mt_data(mac,time,device_id,intensity,ap_mac,channel,virtual_type)values(……)*n

n為300時,每秒插入達到35000條資料

相關推薦

MySQL 5.7 主從資料庫搭建

1.資料庫安裝 安裝MySQL5.7,主資料庫為192.168.2.221,從資料庫為192.168.2.222,伺服器記憶體8G sudo apt-get install mysql-server 2.主資料庫配置 修改/etc/m

MySQL-5.7主從搭建

主機名 sha linu bnu ins type 進制 err ice 一. 系統信息 Linux版本:6.8MySQL版本信息: /mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz兩臺機器IP:192.168.196.220192.

Centos7.5 生產環境搭建MySQL 5.7主從

maria tps 隔離 地址 mys mov code eve get 環境:服務器兩臺:192.168.19.77 4核心,16G內存 內網隔離,不通外網192.168.19.78 4核心,16G內存 內網

通過 mysqldump 搭建基於 gtid MySQL 5.7 主從復制

glibc binlog lex tar.gz size read enc nlog trigge 安裝主從 MySQL 5.7 # 主 MySQL5.7 useradd mysql /sbin/nologin cd /usr/local tar -xvf mysql-5.

Mysql 5.7主從

mysql5.7安裝忽略,參考我前面的博客。從庫克隆主庫,克隆主數據庫後,需要修改 server-id 和 /data/mysql/auto.cnf 中的UUID, 修改pid文件名字修改my.cnfmaster: 只發送 binlog-do-db=autoops slave: 只接受 replicat

mysql 5.7主從安裝和配置

crash master rpm 情況下 並發 本地 隔離級別 cover mirror 本文主要介紹mysql 5.7主從復制,轉載請註明出處 下載地址 模塊 版本 下載地址 mysql 5.7 https://dev.mysql.com/downlo

MySQL 5.7 主從復制(主從同步)

MySQL主從設置1、說明:IP 計算機名 角色 192.168.1.222 MySQL-001 master 192.168.1.233 MySQL-002 slave 系統:CentOS 6.* 或 7.* MySQL版本:5.72、master配置文件設置如

完全解決 MySQL 5.7 主從復制的延遲問題

cond master sla sql 進行 b- proc mas 恢復 1、問題發現sysbench使用以下配置對MySQL進行測試 sysbench /usr/share/sysbench/tests/include/oltp_legacy/oltp.lua --my

centos6.5 mysql 5.7 主從配置

環境 主伺服器ip:192.168.136.131 從伺服器ip:192.168.136.132 先將兩臺伺服器的my.cnf配置下 vi /usr/local/mysql/my.cnf #編輯my.cnf 1 主伺服器配置 log-bin=mysql-bin #[必須] ser

Linux下以二進位制原始碼方式安裝mysql-5.7.24 資料庫

Linux下安裝mysql資料庫 今天正好有時間自己在環境下安裝資料庫,操作了一下,以供大家學習下,但是也有一寫坑的地方 下載安裝包 mysql官網下載地址 1、如果需要下載到本地的話,點選下載mysql-5.7.24至本地 2、如果是在linux伺服器上操作

mysql 5.7主從同步踩坑實踐

基本環境配置 首先,要保證防火牆對3306埠的開啟,(開啟方式,請參考:[http://blog.csdn.net/xlgen157387/article/details/49964557]),如果只是為了學習資料庫的主從配置,可以使用service iptables

python3.6 + Django2.0.1 +MySQL 5.7 環境下搭建環境的流程

最近在學習Django,看的教程中使用的是老版本的python2+Django1.10,已經略顯落後。遂自己查資料改用py3+Django2.0,期間遇到很多問題,寫成這篇流程記錄。 1.建立你的專案 django-admin startproject 專案名

mysql 5.7 主從複製

mysql主從複製  首先這個密碼就搞得我很頭大  yum安裝的rpm包 系統自動完成初始化 預設密碼強度是strong 這個設定是真的坑 規則很嚴格 反正我試了各種辦法都不能滿足密碼要求  只能先用服務啟動時日誌裡給的初始密碼先登進去 然後修改規則 再執行mysql_s

lnmp中centos7配置mysql.5.7主從讀寫分離配

筆者參考的是這篇博文:http://blog.csdn.net/jiaoshenmo/article/details/51181773 在配置的過程成發現有些地方沒說清楚,繞過了幾個坑才配置完成的。 首先你玩的話肯定是在本地玩,流程沒問題你才到伺服器上配置。 我使用的映象

MySQL 5.7.25資料庫死鎖

1、檢視innodb狀態 show engine innodb status\G 2、開啟lock_monitor監控 use databases sys; create table innodb_lock_monitor(x int) engine=innodb; 3、查詢程序 m

mysql 5.7設定資料庫大小寫敏感

# CLIENT SECTION# ----------------------------------------------------------------------## The following options will be read by MySQL client applications.

mysql 5.7 主從配置

原理: MySQL使用3個執行緒來執行復制功能(其中1個在【主伺服器】上,另兩個在【從伺服器】上。 當【從伺服器】發出START SLAVE時,【從伺服器】建立一個I/O執行緒,以連線【主伺服器】並讓它傳送記錄在其二進位制日誌中的語句。 【主伺服器】建立一

mysql 5.7 主從同步配置(windows)

今天在做mysql的主從同步的時候碰到了一些問題,在這裡整理一下。 首先趁著五一假期,主庫停機,複製data至從庫(時間比較長)。 1、配置主庫,主要是my.ini增加如下選項: # Binary Logging. # log-bin log-bi

Windows下配置MySQL(5.7.21)資料庫

大好的週末,本該是打機、出遊、睡覺的好時機。擼主,卻在這裡寫部落格… … 吊絲,注孤老。不管怎麼樣,希望,這篇文章,能幫到你。 一、下載MySQL。 我下的是mysql-5.7.21-winx64。

mysql 5.7 主從同步 gtid

back trying waiting maria nlog 創建 single lib t_sql 環境:1、(主) linux centOS 7 64位2、(從) linux centOS 7 64位3、(mysql)最好要求版本一致,從庫不能比主庫版本高 建議5.7