linux 查看数据库主备,Linux下的数据库主从

主库  ip:192.168.1.51

从库  ip:192.168.1.252

主机:

1)创建一个slave用户,并且赋予权限grant replication slave,reload,super on *.* to 'slave'@'%' identified by '123456';

flush privileges;

2)更改配置文件(/etc/my.cnf 放在[mysqld]下面)server-id               = 1    #主机标示,整数

log-bin                 = mysql-binlog   #确保此文件可写

read-only              =0  #主机,读写都可以

binlog-do-db         =test   #需要备份数据,多个写多行

binlog-ignore-db    =mysql #不需要备份的数据库,多个写多行

3)重启mysqlservice  mysqld  restart

4)查看主库的状态

在mysql中:show  master  status\G

mysql> show  master  status\G;

*************************** 1. row ***************************

File: mysql-binlog.000003

Position: 271

Binlog_Do_DB: 1309phpb

Binlog_Ignore_DB: mysql

1 row in set (0.00 sec)

ERROR:

No query specified

出现这样的提示,说明主库配置没有什么问题了

5)查看主库日志开始

mysql> show  master  status;

+---------------------+----------+--------------+------------------+

| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+---------------------+----------+--------------+------------------+

| mysql-binlog.000003 |      271 | 1309phpb     | mysql            |

+---------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

二)从库的配置

1)修改从库配置文件(vi  /etc/my.cnf)server-id               = 2

log-bin                 = mysql-binlog

2)重启mysql服务

3)进入mysql 更改主库参数

change master to master_host='192.168.1.51',master_user='slave',

master_password='123456',master_log_file='File字段的值',master_log_pos=Position 字段值;

change master to master_host='192.168.1.177',master_user='slave',master_password='root',master_log_file='mysql-binlog.000001',master_log_pos=203;

change master to master_host='192.168.1.177',master_user='slave',master_password='123456',master_log_file='binlog.000001',master_log_pos=203;

查看主库日志开始

mysql> show  master  status;

+---------------------+----------+--------------+------------------+

| File                | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+---------------------+----------+--------------+------------------+

| mysql-binlog.000003 |      271 | 1309phpb     | mysql            |

+---------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

4)重启进程

start  slave

5)查看从库的的状态

show   slave  status\G

show  slave  status\G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.1.51

Master_User: slave

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-binlog.000003

Read_Master_Log_Pos: 271

Relay_Log_File: localhost-relay-bin.000004

Relay_Log_Pos: 419

Relay_Master_Log_File: mysql-binlog.000003

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB: 1309phpb

Replicate_Ignore_DB: mysql

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: 271

Relay_Log_Space: 578

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:

1 row in set (0.00 sec)

6)此时可以从主库添加数据,从库查询数据了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值