實現MySQL的a-b

來源:互聯網
上載者:User

一、需要環境
 
    兩台虛理機都安裝 MYSQL服務  IP分別為192.168.1.1    192.168.1.2
 
二、以下是個操作步驟;
 
    虛理機一
 
[root@localhost ~]# yum install mysql mysql-server -y
 
[root@localhost ~]# vim /etc/my.cnf
 
[mysqld]
 
datadir=/var/lib/mysql
 
socket=/var/lib/mysql/mysql.sock
 
user=mysql
 
server_id = 1
 
log-bin=binlog
 
log-bin-index=binlog.index
 
# Default to using old password format for compatibility with mysql 3.x
 
# clients (those using the mysqlclient10 compatibility package).
 
old_passwords=1
 
# Disabling symbolic-links is recommended to prevent assorted security risks;
 
# to do so, uncomment this line:
 
# symbolic-links=0
 
[mysqld_safe]
 
log-error=/var/log/mysqld.log
 
pid-file=/var/run/mysqld/mysqld.pid
 
[root@localhost ~]# servicr mysqld start
 
bash: servicr: command not found
 
[root@localhost ~]# service  mysqld start
 
[root@localhost ~]# mysql
 
mysql> quit
 
Bye
 
[root@localhost ~]# mysqldump -A -x >/tmp/full.sql
 
[root@localhost ~]# scp /tmp/full.sql  root@192.168.1.2:/tmp/
 
root@192.168.1.2's password:
 
full.sql                                      100%  412KB 412.4KB/s  00:00   
 
[root@localhost ~]# mysql
 
Welcome to the MySQL monitor.  Commands end with ; or \g.
 
Your MySQL connection id is 4
 
Server version: 5.0.77-log Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> show master status;
 
+---------------+----------+--------------+------------------+
 
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB |
 
+---------------+----------+--------------+------------------+
 
| binlog.000003 |      376 |              |                  |
 
+---------------+----------+--------------+------------------+
 
1 row in set (0.00 sec)
 
mysql>                                                                           
 
    虛理機二
 
[root@localhost ~]# yum install mysql  mysql-server -y
 
[root@localhost ~]# vim /etc/my.cnf
 
[mysqld]
 
datadir=/var/lib/mysql
 
socket=/var/lib/mysql/mysql.sock
 
user=mysql
 
server_id = 2
 
relay_log = /var/lib/mysql/mysql-relay-bin
 
relay_log_index=/var/lib/mysql/mysql-relay-bin.index
 
# Default to using old password format for compatibility with mysql 3.x
 
# clients (those using the mysqlclient10 compatibility package).
 
old_passwords=1
 
# Disabling symbolic-links is recommended to prevent assorted security risks;
 
# to do so, uncomment this line:
 
# symbolic-links=0
 
[mysqld_safe]
 
log-error=/var/log/mysqld.log
 
pid-file=/var/run/mysqld/mysqld.pid
 
[root@localhost ~]# service mysqld restar
 
[root@localhost ~]# cd /var/lib/mysql/
 
[root@localhost mysql]# ls
 
ibdata1  ib_logfile0  ib_logfile1  mysql  mysql.sock  test
 
[root@localhost mysql]# rm -fr *
 
[root@localhost mysql]# ls
 
[root@localhost mysql]# service mysqld restart
 
[root@localhost mysql]# mysql < /tmp/full.sql
 
[root@localhost mysql]# mysql> change master to master_host='192.168.1.1', master_port=3306, master_user='hfj', master_password='123', master_log_file='binlog.000003',master_log_pos=376;
 
[root@localhost mysql]# mysql
 
mysql> change master to master_host='192.168.1.1', master_port=3306, master_user='hfj', master_password='123', master_log_file='binlog.000003',master_log_pos=376;
 
Query OK, 0 rows affected (0.04 sec)
 
mysql> start slave;
 
Query OK, 0 rows affected (0.00 sec)
 
mysql> show slavw status;
 
mysql> show slave status \G;
 
*************************** 1. row ***************************
 
            Slave_IO_State: Waiting for master to send event
 
                Master_Host: 192.168.1.1
 
                Master_User: hfj
 
                Master_Port: 3306
 
              Connect_Retry: 60
 
            Master_Log_File: binlog.000003
 
        Read_Master_Log_Pos: 376
 
            Relay_Log_File: mysql-relay-bin.000002
 
              Relay_Log_Pos: 232
 
      Relay_Master_Log_File: binlog.000003
 
          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: 376
 
            Relay_Log_Space: 232
 
            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
 
1 row in set (0.00 sec)
 
ERROR:
 
No query specified
 
mysql>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.