一.Mysql主從複製配置

在我以前的文章四·安裝mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz(基於Centos7源碼安裝 和 九.mysql數據庫多實例安裝mysqld_multi [start,stop,report] 兩篇文章寫到了單太服務器多實例的安裝,本篇文章是關於主從複製的配置。本次把mysql3306做爲主Master,mysql3307和mysql3308做爲Slavehtml

一.啓動3臺mysql服務器mysql

[mysql@iZ25ufmpy4sZ ~]$ mysqld_multi start
[mysql@iZ25ufmpy4sZ ~]$ mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3306 is running
MySQL server from group: mysqld3307 is running
MySQL server from group: mysqld3308 is running

二.登陸Master主服務器mysql3306linux

[mysql@iZ25ufmpy4sZ ~]$ mysql -u root -S /tmp/mysql3306.sock -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.15-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

三.在Master主服務器mysql3306上創建帳戶並受權Slavesql

mysql> grant replication slave on *.* to 'mysqlsync'@'%' identified by 'mysqlsync';
Query OK, 0 rows affected, 1 warning (0.00 sec)


  mysql> show master status;
  +----------------------+----------+--------------+------------------+-------------------+
  | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
  +----------------------+----------+--------------+------------------+-------------------+
  | mysql3306_bin.000006 | 442 | | | |
  +----------------------+----------+--------------+------------------+-------------------+
  1 row in set (0.00 sec)數據庫

 

四.登陸Slave從服務器mysql3307或mysql3308服務器

[mysql@iZ25ufmpy4sZ ~]$ mysql -u root -S /tmp/mysql3307.sock -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.15-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

五.配置Slave從服務器mysql3307或mysql3308ide

mysql> change master to master_host='127.0.0.1',master_user='mysqlsync',master_password='mysqlsync',master_log_file='mysql3306_bin.000006',master_log_pos=442;
Query OK, 0 rows affected, 2 warnings (0.05 sec)

mysql> start slave;
Query OK, 0 rows affected (0.03 sec)

mysql> 

六.在Slave從服務器上查看slave狀態測試

mysql> mysql> show slave status;
+----------------------------------+-------------+-------------+-------------+---------------+----------------------+---------------------+-------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+----------------------------------------+-----------+---------------------+--------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+
| Slave_IO_State                   | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File      | Read_Master_Log_Pos | Relay_Log_File                | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master | Master_SSL_Verify_Server_Cert | Last_IO_Errno | Last_IO_Error | Last_SQL_Errno | Last_SQL_Error | Replicate_Ignore_Server_Ids | Master_Server_Id | Master_UUID                          | Master_Info_File                       | SQL_Delay | SQL_Remaining_Delay | Slave_SQL_Running_State                                | Master_Retry_Count | Master_Bind | Last_IO_Error_Timestamp | Last_SQL_Error_Timestamp | Master_SSL_Crl | Master_SSL_Crlpath | Retrieved_Gtid_Set | Executed_Gtid_Set | Auto_Position | Replicate_Rewrite_DB | Channel_Name | Master_TLS_Version |
+----------------------------------+-------------+-------------+-------------+---------------+----------------------+---------------------+-------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+----------------------------------------+-----------+---------------------+--------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+
| Waiting for master to send event | 127.0.0.1   | mysqlsync   |        3306 |            60 | mysql3306_bin.000006 |                 442 | iZ25ufmpy4sZ-relay-bin.000002 |           324 | mysql3306_bin.000006  | Yes              | Yes               |                 |                     |                    |                        |                         |                             |          0 |            |            0 |                 442 |             538 | None            |                |             0 | No                 |                    |                    |                 |                   |                |                     0 | No                            |             0 |               |              0 |                |                             |             3306 | 526196c9-dbe6-11e6-aa52-00163e0066e2 | /home/mysql/mysql3307/data/master.info |         0 |                NULL | Slave has read all relay log; waiting for more updates |              86400 |             |                         |                          |                |                    |                    |                   |             0 |                      |              |                    |
+----------------------------------+-------------+-------------+-------------+---------------+----------------------+---------------------+-------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+----------------------------------------+-----------+---------------------+--------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+
1 row in set (0.00 sec)

 

七.主從服務器配置測試spa

    在Master主服務器上新建一個database,則Slave從服務器上應該也可以查詢到,以下code

   

---------------一下爲主服務器

[mysql@iZ25ufmpy4sZ ~]$ mysql -u root -S /tmp/mysql3306.sock -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.15-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database test;
Query OK, 1 row affected (0.00 sec)

mysql> 

--------------從服務器


  [mysql@iZ25ufmpy4sZ ~]$ mysql -u root -S /tmp/mysql3307.sock -p
  Enter password:
  Welcome to the MySQL monitor. Commands end with ; or \g.
  Your MySQL connection id is 13
  Server version: 5.7.15-log MySQL Community Server (GPL)

  Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

  Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective
  owners.

  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  mysql> show databases;
  +--------------------+
  | Database |
  +--------------------+
  | information_schema |
  | mysql |
  | performance_schema |
  | sys |
  | test |
  +--------------------+
  5 rows in set (0.00 sec)

  mysql>

問題:1.This operation cannot be performed with a running slave io thread; run STOP SLAV

           這是因爲我在尚未中止slave進程的時候,又執行start slave。故要先運行stop slave,

相關文章
相關標籤/搜索