实现MySQL的a-b

来源:这里教程网 时间:2026-02-27 15:36:10 作者:

一、需要环境 两台虚理机都安装 MYSQL服务 IP分别为192.168.1.1 192.168.1.2 二、以下是个操作步骤; 虚理机一 [

一、需要环境
 
    两台虚理机都安装 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  
[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>

相关推荐