mysql a-b_实现mysql的a-b

一、需要环境

两台虚理机都安装 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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值