redhat linux5.0下虚拟机搭建mysql5.5.40主从复制配置步骤

来源:互联网 发布:mac os x 10.11.6镜像 编辑:程序博客网 时间:2024/06/14 22:53
1、主库配置 在rpm下安装配置文件默认安装位置/usr/share/mysql/my-medium.cnf ,拷贝到/etc目录下 cp my-medium.cnf 到my.cnf;
   同样从库也一样配置。


2、主库修改配置文件vi my.cnf 下server-id=1 log-bin=mysql-bin;


3、在主服务器上建立帐户并授权slave
    grant replication slave on *.* to 'root'@'192.168.56.129' identified by '123456'


4、重启主库  /etc/init.d/mysql start


5、主服务器的mysql,查询master的状态


mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      262 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)






从库配置




1、从库修改配置文件 vi my.cnf下server-id=2 ,log-bin=mysql-bin


2、配置从服务器Slave:




  mysql> change master to master_host='192.168.56.128',master_user='root',master_password='123456',
    -> master_log_file='mysql-bin.000001',master_log_pos=0;   




3、检查从服务器复制功能状态:


mysql> show slave status \G;
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 192.168.56.128
                  Master_User: root
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 4
               Relay_Log_File: localhost-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: No
            Slave_SQL_Running: No
              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: 4
              Relay_Log_Space: 107
              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: NULL
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: 0
1 row in set (0.01 sec)


ERROR: 
No query specified


        SLAVE_IO_RUNING:NO
        SLAVE_SQL_RUNING:NO 判断mysql服务没有启动。




4、启动从服务器


 start slave


5、检查从服务器复制功能状态 Slave_IO_Running: Yes
                            Slave_SQL_Running: Yes  正常


mysql> show slave status \G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.56.128
                  Master_User: root
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 262
               Relay_Log_File: localhost-relay-bin.000002
                Relay_Log_Pos: 408
        Relay_Master_Log_File: mysql-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: 262
              Relay_Log_Space: 568
              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
1 row in set (0.00 sec)


ERROR: 
No query specified




在主服务器上建立测试数据:




mysql> create database ceshi;
Query OK, 1 row affected (0.01 sec)


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| ceshi              |
| mysql              |
| performance_schema |
| student            |
| test               |
+--------------------+
6 rows in set (0.01 sec)


mysql> use ceshi;
Database changed
mysql> use ceshi;
Database changed
mysql> create table ceshi(id int(3),name char(10));
Query OK, 0 rows affected (0.27 sec)


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


mysql> insert into ceshi values(001,'bobu');
Query OK, 1 row affected (0.05 sec)


mysql> select * from ceshi;
+------+------+
| id   | name |
+------+------+
|    1 | bobu |
+------+------+
1 row in set (0.00 sec)




在从服务器上检查服务是否正确






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


mysql> use ceshi;
Database changed




mysql> select * from ceshi;
+------+------+
| id   | name |
+------+------+
|    1 | bobu |
+------+------+
1 row in set (0.01 sec)




    

0 0
原创粉丝点击