中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

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

發布時間:2020-05-27 10:51:25 來源:網絡 閱讀:2597 作者:文爾 欄目:MySQL數據庫

環境:
服務器兩臺:
192.168.19.77 4核心,16G內存 內網隔離,不通外網
192.168.19.78 4核心,16G內存 內網隔離,不通外網

一. 先有外網的機器,下載MySQL 5.7官網軟件包

官網下載鏈接:
為了方便,我這里將安裝MySQL5.7需要的官方軟件包下載鏈接地址就直接貼上來
使用官方RPM包安裝,需要安裝5個包,分別是下面的5個鏈接,都是官方鏈接

https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-common-5.7.23-1.el7.x86_64.rpm
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-5.7.23-1.el7.x86_64.rpm
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.23-1.el7.x86_64.rpm
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.23-1.el7.x86_64.rpm
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-devel-5.7.23-1.el7.x86_64.rpm

二. 安裝MySQL

使用FTP軟件,將軟件包上傳至內網2臺數據庫服務器77/78的/tmp目錄下
安裝rpm前,先要將MariaDB數據庫和libs卸載掉

    # yum remove mariadb mariadb-server mariadb-devel mariadb-libs

安裝MySQL

   #  rpm -ivh mysql-community-libs-5.7.23-1.el7.x86_64.rpm 
   #  rpm -ivh mysql-community-common-5.7.23-1.el7.x86_64.rpm 
   #  rpm -ivh mysql-community-libs-5.7.23-1.el7.x86_64.rpm 
   #  rpm -ivh mysql-community-client-5.7.23-1.el7.x86_64.rpm 
   #  rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm 
   #  rpm -ivh mysql-community-devel-5.7.23-1.el7.x86_64.rpm

三. 定制配置數據庫
將數據庫的數據、日志指向到data存放目錄下,再加入主從的參數

192.168.19.77主服務器的my.cnf

[root@mysql-m ~]# cat /etc/my.cnf

[mysqld]
datadir=/u1/mysql/data
socket=/u1/mysql/data/mysql.sock

log-error=/u1/mysql/log/mysqld.log
pid-file=/u1/mysql/pid/mysqld.pid

user=mysql
server-id=1
port=3306

##要給從機同步的庫
#binlog-do-db=

##不給從機同步的庫(多個寫多行)
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=sys

##開啟二進制日志
log-bin=/u1/mysql/binary/mysql1-bin

##自動清理 7 天前的log文件,可根據需要修改
expire_logs_days=7

[client]
socket=/u1/mysql/data/mysql.sock

192.168.19.77從服務器的my.cnf

[root@mysql-m ~]# cat /etc/my.cnf

[mysqld]
datadir=/u1/mysql/data
socket=/u1/mysql/data/mysql.sock

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

log-error=/u1/mysql/log/mysqld.log
pid-file=/u1/mysql/pid/mysqld.pid

user=mysql
server-id=2
port=3306

##從庫上的參數
read_only = 1
master_info_repository=TABLE
relay_log_info_repository=TABLE
#relay_log_recovery=1   #從機禁止寫
#super_read_only=1      #從機禁止寫

[client]
socket=/u1/mysql/data/mysql.sock

建立配置文件指定的目錄

# mkdir -p /u1/mysql/{data,logs,pid}
# chown -R mysql.mysql  /u1

啟動數據庫并找出root密碼

# systemctl start mysqld

--找出root隨機密碼
# egrep "root@localhost"  /u1/mysql/log/mysqld.log |awk -F":" '{print $4}'
 zn9><g_ZCz9N

登陸數據庫并修改root密碼

# mysql -uroot -p
Enter password:         --健入上面egrep過濾出來的隨機密碼

mysql > ALTER USER root@localhost identified by 'TestMySQL5.7';

四. 配置主從

在主服務器上授權從服務器復制帳號

# mysql -uroot -p
Enter password:         

mysql > grant replication slave on *.* to mysql_ab@'192.168.19.%' identified by 'mysql_AB5.7';
mysql > show master status\G
*************************** 1. row ***************************
             File: mysql1-bin.000001
         Position: 1082
     Binlog_Do_DB: 
 Binlog_Ignore_DB: mysql,information_schema,performance_schema,sys
Executed_Gtid_Set: 
1 row in set (0.00 sec)

來到從服務器上配置連接主服務器

# mysql -uroot -p
Enter password:     

mysql > stop slave;
mysql > chagne master to
   -> master_host='192.168.19.77',
     -> master_port=3306,
     -> master_user='mysql_ab',
     -> master_password='mysql_AB5.7',
     -> master_log_file='mysql1-bin.000001',
     -> master_log_pos=1082;

mysql > start slave;

mysql > show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.19.77
                  Master_User: mysql_ab
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql1-bin.000001
          Read_Master_Log_Pos: 1082
               Relay_Log_File: dosercn10235b-relay-bin.000004
                Relay_Log_Pos: 951
        Relay_Master_Log_File: mysql1-bin.000001
            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: 1082
              Relay_Log_Space: 1166
              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: 45d68d37-b6f9-11e8-a947-0050569afd93
             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: 
1 row in set (0.00 sec)

配置完成,從服務器已經連接上了主服務器

五. 驗證

主服務器上創建數據庫、表、并插入數據

mysql > CREATE DATABASE test_ab default charset utf8;
mysql > CREATE TABLE test_ab.a1(id int(2),name varchar(20));
mysql > INSERT INTO test_ab.a1(id,name) VALUES(1,"測試1");
mysql> select * from test_ab.a1;
+------+---------+
| id   | name    |
+------+---------+
|    1 | 測試1   |
+------+---------+
1 row in set (0.00 sec)

從服務器上查詢該數據,驗證是否復制過來

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

至此完成。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

桦南县| 府谷县| 南通市| 福泉市| 大埔县| 青冈县| 黄陵县| 桃园市| 古田县| 离岛区| 尉氏县| 宁安市| 巩义市| 民权县| 贡觉县| 凉山| 麦盖提县| 库伦旗| 龙井市| 孟津县| 巴东县| 巴青县| 开平市| 渑池县| 富裕县| 平度市| 县级市| 澄江县| 广汉市| 麟游县| 周宁县| 黄龙县| 沂水县| 台湾省| 钟祥市| 松溪县| 诸暨市| 大同县| 黄冈市| 石柱| 正镶白旗|