实现MySQL的a-b

php中文网
发布: 2016-06-07 17:23:30
原创
1374人浏览过

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

linux

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号